From f87d1530e679ddfa89602eb08e8b9cdbcf9cc884 Mon Sep 17 00:00:00 2001 From: "sgjesse@chromium.org" Date: Wed, 4 Mar 2009 10:33:00 +0000 Subject: [PATCH] The SendAll method on Socket was a helper method that did not really belong in platform. Review URL: http://codereview.chromium.org/40104 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@1414 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/platform-freebsd.cc | 14 -------------- src/platform-linux.cc | 14 -------------- src/platform-macos.cc | 14 -------------- src/platform-win32.cc | 14 -------------- src/platform.h | 1 - test/cctest/test-sockets.cc | 15 ++++++++++++++- 6 files changed, 14 insertions(+), 58 deletions(-) diff --git a/src/platform-freebsd.cc b/src/platform-freebsd.cc index fb2fba6227..b1e0b73fa1 100644 --- a/src/platform-freebsd.cc +++ b/src/platform-freebsd.cc @@ -656,7 +656,6 @@ class FreeBSDSocket : public Socket { // Data Transimission int Send(const char* data, int len) const; - bool SendAll(const char* data, int len) const; int Receive(char* data, int len) const; bool IsValid() const { return socket_ != -1; } @@ -736,19 +735,6 @@ int FreeBSDSocket::Send(const char* data, int len) const { } -bool FreeBSDSocket::SendAll(const char* data, int len) const { - int sent_len = 0; - while (sent_len < len) { - int status = Send(data, len); - if (status <= 0) { - return false; - } - sent_len += status; - } - return true; -} - - int FreeBSDSocket::Receive(char* data, int len) const { int status = recv(socket_, data, len, 0); return status; diff --git a/src/platform-linux.cc b/src/platform-linux.cc index c001f51b69..09eee2ed10 100644 --- a/src/platform-linux.cc +++ b/src/platform-linux.cc @@ -640,7 +640,6 @@ class LinuxSocket : public Socket { // Data Transimission int Send(const char* data, int len) const; - bool SendAll(const char* data, int len) const; int Receive(char* data, int len) const; bool IsValid() const { return socket_ != -1; } @@ -720,19 +719,6 @@ int LinuxSocket::Send(const char* data, int len) const { } -bool LinuxSocket::SendAll(const char* data, int len) const { - int sent_len = 0; - while (sent_len < len) { - int status = Send(data, len); - if (status <= 0) { - return false; - } - sent_len += status; - } - return true; -} - - int LinuxSocket::Receive(char* data, int len) const { int status = recv(socket_, data, len, 0); return status; diff --git a/src/platform-macos.cc b/src/platform-macos.cc index 9bbdcfc5d7..4892e2a96c 100644 --- a/src/platform-macos.cc +++ b/src/platform-macos.cc @@ -607,7 +607,6 @@ class MacOSSocket : public Socket { // Data Transimission int Send(const char* data, int len) const; - bool SendAll(const char* data, int len) const; int Receive(char* data, int len) const; bool IsValid() const { return socket_ != -1; } @@ -693,19 +692,6 @@ int MacOSSocket::Send(const char* data, int len) const { } -bool MacOSSocket::SendAll(const char* data, int len) const { - int sent_len = 0; - while (sent_len < len) { - int status = Send(data, len); - if (status <= 0) { - return false; - } - sent_len += status; - } - return true; -} - - int MacOSSocket::Receive(char* data, int len) const { int status = recv(socket_, data, len, 0); return status; diff --git a/src/platform-win32.cc b/src/platform-win32.cc index cc725cb79f..fd65738601 100644 --- a/src/platform-win32.cc +++ b/src/platform-win32.cc @@ -1583,7 +1583,6 @@ class Win32Socket : public Socket { // Data Transimission int Send(const char* data, int len) const; - bool SendAll(const char* data, int len) const; int Receive(char* data, int len) const; bool IsValid() const { return socket_ != INVALID_SOCKET; } @@ -1663,19 +1662,6 @@ int Win32Socket::Send(const char* data, int len) const { } -bool Win32Socket::SendAll(const char* data, int len) const { - int sent_len = 0; - while (sent_len < len) { - int status = Send(data, len); - if (status <= 0) { - return false; - } - sent_len += status; - } - return true; -} - - int Win32Socket::Receive(char* data, int len) const { int status = recv(socket_, data, len, 0); return status; diff --git a/src/platform.h b/src/platform.h index a297c47d07..b58067f5ba 100644 --- a/src/platform.h +++ b/src/platform.h @@ -437,7 +437,6 @@ class Socket { // Data Transimission virtual int Send(const char* data, int len) const = 0; - virtual bool SendAll(const char* data, int len) const = 0; virtual int Receive(char* data, int len) const = 0; virtual bool IsValid() const = 0; diff --git a/test/cctest/test-sockets.cc b/test/cctest/test-sockets.cc index 187bbe052c..9316a26eae 100644 --- a/test/cctest/test-sockets.cc +++ b/test/cctest/test-sockets.cc @@ -63,6 +63,19 @@ void SocketListenerThread::Run() { } +static bool SendAll(Socket* socket, const char* data, int len) { + int sent_len = 0; + while (sent_len < len) { + int status = socket->Send(data, len); + if (status <= 0) { + return false; + } + sent_len += status; + } + return true; +} + + static void SendAndReceive(char *data, int len) { bool ok; @@ -78,7 +91,7 @@ static void SendAndReceive(char *data, int len) { CHECK(ok); // Send all the data. - ok = client->SendAll(data, len); + ok = SendAll(client, data, len); CHECK(ok); // Wait until data is received.