Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(245)

Side by Side Diff: src/platform-posix.cc

Issue 10412021: Make socket send and receive more robust and return 0 on failure. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution. 11 // with the distribution.
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 int status = shutdown(socket_, SHUT_RDWR); 460 int status = shutdown(socket_, SHUT_RDWR);
461 close(socket_); 461 close(socket_);
462 socket_ = -1; 462 socket_ = -1;
463 return status == 0; 463 return status == 0;
464 } 464 }
465 return true; 465 return true;
466 } 466 }
467 467
468 468
469 int POSIXSocket::Send(const char* data, int len) const { 469 int POSIXSocket::Send(const char* data, int len) const {
470 if (len <= 0) return 0;
470 int status = send(socket_, data, len, 0); 471 int status = send(socket_, data, len, 0);
471 return status; 472 return (status < 0) ? 0 : status;
472 } 473 }
473 474
474 475
475 int POSIXSocket::Receive(char* data, int len) const { 476 int POSIXSocket::Receive(char* data, int len) const {
477 if (len <= 0) return 0;
476 int status = recv(socket_, data, len, 0); 478 int status = recv(socket_, data, len, 0);
477 return status; 479 return (status < 0) ? 0 : status;
478 } 480 }
479 481
480 482
481 bool POSIXSocket::SetReuseAddress(bool reuse_address) { 483 bool POSIXSocket::SetReuseAddress(bool reuse_address) {
482 int on = reuse_address ? 1 : 0; 484 int on = reuse_address ? 1 : 0;
483 int status = setsockopt(socket_, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); 485 int status = setsockopt(socket_, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
484 return status == 0; 486 return status == 0;
485 } 487 }
486 488
487 489
(...skipping 27 matching lines...) Expand all
515 return ntohl(value); 517 return ntohl(value);
516 } 518 }
517 519
518 520
519 Socket* OS::CreateSocket() { 521 Socket* OS::CreateSocket() {
520 return new POSIXSocket(); 522 return new POSIXSocket();
521 } 523 }
522 524
523 525
524 } } // namespace v8::internal 526 } } // namespace v8::internal
OLDNEW
« src/debug-agent.cc ('K') | « src/platform.h ('k') | src/platform-win32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698