Reviewers: Jakob,
Message:
PTAL.
Description:
Make socket send and receive more robust and return 0 on failure.
[email protected]
BUG=15719
TEST=
Please review this at http://codereview.chromium.org/10412021/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files:
M src/debug-agent.cc
M src/platform-posix.cc
M src/platform-win32.cc
M src/platform.h
Index: src/debug-agent.cc
diff --git a/src/debug-agent.cc b/src/debug-agent.cc
index
511663d8eeaab57c45639746e93c9ca1b3b6d049..a7015bfa206bb99f91728541fe98a225c69b6384
100644
--- a/src/debug-agent.cc
+++ b/src/debug-agent.cc
@@ -247,7 +247,7 @@ SmartArrayPointer<char>
DebuggerAgentUtil::ReceiveMessage(const Socket* conn) {
while (!(c == '\n' && prev_c == '\r')) {
prev_c = c;
received = conn->Receive(&c, 1);
- if (received <= 0) {
+ if (received == 0) {
PrintF("Error %d\n", Socket::LastError());
return SmartArrayPointer<char>();
}
@@ -454,7 +454,7 @@ int DebuggerAgentUtil::ReceiveAll(const Socket* conn,
char* data, int len) {
int total_received = 0;
while (total_received < len) {
int received = conn->Receive(data + total_received, len -
total_received);
- if (received <= 0) {
+ if (received == 0) {
return total_received;
}
total_received += received;
Index: src/platform-posix.cc
diff --git a/src/platform-posix.cc b/src/platform-posix.cc
index
66316594c8ce3fdfe90cc4fd296f08325b653eb5..3e143d2f6441f78929c4784384e20fbfca85b47b
100644
--- a/src/platform-posix.cc
+++ b/src/platform-posix.cc
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2012 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
@@ -467,14 +467,16 @@ bool POSIXSocket::Shutdown() {
int POSIXSocket::Send(const char* data, int len) const {
+ if (len <= 0) return 0;
int status = send(socket_, data, len, 0);
- return status;
+ return (status < 0) ? 0 : status;
}
int POSIXSocket::Receive(char* data, int len) const {
+ if (len <= 0) return 0;
int status = recv(socket_, data, len, 0);
- return status;
+ return (status < 0) ? 0 : status;
}
Index: src/platform-win32.cc
diff --git a/src/platform-win32.cc b/src/platform-win32.cc
index
9e377a1977700840306f9f631e51d740091ff79b..aa2a71af54f8a29b97d0084afb19e901a03a0639
100644
--- a/src/platform-win32.cc
+++ b/src/platform-win32.cc
@@ -1848,14 +1848,16 @@ bool Win32Socket::Shutdown() {
int Win32Socket::Send(const char* data, int len) const {
+ if (len <= 0) return 0;
int status = send(socket_, data, len, 0);
- return status;
+ return (status == SOCKET_ERROR) ? 0 : status;
}
int Win32Socket::Receive(char* data, int len) const {
+ if (len <= 0) return 0;
int status = recv(socket_, data, len, 0);
- return status;
+ return (status == SOCKET_ERROR) ? 0 : status;
}
Index: src/platform.h
diff --git a/src/platform.h b/src/platform.h
index
168791a0a4a881df549f1dc20830a2c006c220b3..a2ddf7a625edd783e386cff61adc048a78d26370
100644
--- a/src/platform.h
+++ b/src/platform.h
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2012 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
@@ -653,6 +653,7 @@ class Socket {
virtual bool Shutdown() = 0;
// Data Transimission
+ // Return 0 on failure.
virtual int Send(const char* data, int len) const = 0;
virtual int Receive(char* data, int len) const = 0;
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev