Commit 0bfedfb5 authored by yangguo@chromium.org's avatar yangguo@chromium.org

Make socket send and receive more robust and return 0 on failure.

R=jkummerow@chromium.org
BUG=15719
TEST=

Review URL: https://chromiumcodereview.appspot.com/10412021

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@11601 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent ee17b195
// Copyright 2009 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:
......@@ -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;
......
// 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;
}
......
......@@ -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;
}
......
// 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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment