Author: [email protected]
Date: Thu Mar 19 04:55:09 2009
New Revision: 1545
Modified:
branches/bleeding_edge/src/platform-freebsd.cc
branches/bleeding_edge/src/platform-linux.cc
branches/bleeding_edge/src/platform-macos.cc
branches/bleeding_edge/src/platform-win32.cc
branches/bleeding_edge/src/platform.h
branches/bleeding_edge/test/cctest/test-sockets.cc
Log:
Change the socket close to shutdown.
Removed the close method for socket and added shutdown instead. The
shutdown method is the one to use when terminating socket communication.
The close call is in the destructor.
Review URL: http://codereview.chromium.org/42387
Modified: branches/bleeding_edge/src/platform-freebsd.cc
==============================================================================
--- branches/bleeding_edge/src/platform-freebsd.cc (original)
+++ branches/bleeding_edge/src/platform-freebsd.cc Thu Mar 19 04:55:09 2009
@@ -650,8 +650,7 @@
socket_ = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
}
explicit FreeBSDSocket(int socket): socket_(socket) { }
-
- virtual ~FreeBSDSocket() { Close(); }
+ virtual ~FreeBSDSocket() { Shutdown(); }
// Server initialization.
bool Bind(const int port);
@@ -661,8 +660,8 @@
// Client initialization.
bool Connect(const char* host, const char* port);
- // Close.
- bool Close();
+ // Shutdown socket for both read and write.
+ bool Shutdown();
// Data Transimission
int Send(const char* data, int len) const;
@@ -740,15 +739,17 @@
}
-bool FreeBSDSocket::Close() {
+bool FreeBSDSocket::Shutdown() {
if (IsValid()) {
- // Close socket.
- int status = close(socket_);
+ // Shutdown socket for both read and write.
+ int status = shutdown(socket_, SHUT_RDWR);
+ close(socket_);
socket_ = -1;
return status == 0;
}
return true;
}
+
int FreeBSDSocket::Send(const char* data, int len) const {
int status = send(socket_, data, len, 0);
Modified: branches/bleeding_edge/src/platform-linux.cc
==============================================================================
--- branches/bleeding_edge/src/platform-linux.cc (original)
+++ branches/bleeding_edge/src/platform-linux.cc Thu Mar 19 04:55:09 2009
@@ -651,8 +651,7 @@
socket_ = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
}
explicit LinuxSocket(int socket): socket_(socket) { }
-
- virtual ~LinuxSocket() { Close(); }
+ virtual ~LinuxSocket() { Shutdown(); }
// Server initialization.
bool Bind(const int port);
@@ -662,8 +661,8 @@
// Client initialization.
bool Connect(const char* host, const char* port);
- // Close.
- bool Close();
+ // Shutdown socket for both read and write.
+ bool Shutdown();
// Data Transimission
int Send(const char* data, int len) const;
@@ -741,10 +740,11 @@
}
-bool LinuxSocket::Close() {
+bool LinuxSocket::Shutdown() {
if (IsValid()) {
- // Close socket.
- int status = close(socket_);
+ // Shutdown socket for both read and write.
+ int status = shutdown(socket_, SHUT_RDWR);
+ close(socket_);
socket_ = -1;
return status == 0;
}
Modified: branches/bleeding_edge/src/platform-macos.cc
==============================================================================
--- branches/bleeding_edge/src/platform-macos.cc (original)
+++ branches/bleeding_edge/src/platform-macos.cc Thu Mar 19 04:55:09 2009
@@ -576,8 +576,7 @@
socket_ = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
}
explicit MacOSSocket(int socket): socket_(socket) { }
-
- virtual ~MacOSSocket() { Close(); }
+ virtual ~MacOSSocket() { Shutdown(); }
// Server initialization.
bool Bind(const int port);
@@ -587,8 +586,8 @@
// Client initialization.
bool Connect(const char* host, const char* port);
- // Close.
- bool Close();
+ // Shutdown socket for both read and write.
+ bool Shutdown();
// Data Transimission
int Send(const char* data, int len) const;
@@ -672,10 +671,11 @@
}
-bool MacOSSocket::Close() {
+bool MacOSSocket::Shutdown() {
if (IsValid()) {
- // Close socket.
- int status = close(socket_);
+ // Shutdown socket for both read and write.
+ int status = shutdown(socket_, SHUT_RDWR);
+ close(socket_);
socket_ = -1;
return status == 0;
}
Modified: branches/bleeding_edge/src/platform-win32.cc
==============================================================================
--- branches/bleeding_edge/src/platform-win32.cc (original)
+++ branches/bleeding_edge/src/platform-win32.cc Thu Mar 19 04:55:09 2009
@@ -1548,9 +1548,7 @@
socket_ = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
}
explicit Win32Socket(SOCKET socket): socket_(socket) { }
-
-
- virtual ~Win32Socket() { Close(); }
+ virtual ~Win32Socket() { Shutdown(); }
// Server initialization.
bool Bind(const int port);
@@ -1560,8 +1558,8 @@
// Client initialization.
bool Connect(const char* host, const char* port);
- // Close.
- bool Close();
+ // Shutdown socket for both read and write.
+ bool Shutdown();
// Data Transimission
int Send(const char* data, int len) const;
@@ -1639,12 +1637,13 @@
}
-bool Win32Socket::Close() {
+bool Win32Socket::Shutdown() {
if (IsValid()) {
- // Close socket.
- int rc = closesocket(socket_);
+ // Shutdown socket for both read and write.
+ int status = shutdown(socket_, SD_BOTH);
+ closesocket(socket_);
socket_ = INVALID_SOCKET;
- return rc != SOCKET_ERROR;
+ return status == SOCKET_ERROR;
}
return true;
}
Modified: branches/bleeding_edge/src/platform.h
==============================================================================
--- branches/bleeding_edge/src/platform.h (original)
+++ branches/bleeding_edge/src/platform.h Thu Mar 19 04:55:09 2009
@@ -439,8 +439,10 @@
// Client initialization.
virtual bool Connect(const char* host, const char* port) = 0;
- // Close.
- virtual bool Close() = 0;
+ // Shutdown socket for both read and write. This causes blocking Send and
+ // Receive calls to exit. After Shutdown the Socket object cannot be
used for
+ // any communication.
+ virtual bool Shutdown() = 0;
// Data Transimission
virtual int Send(const char* data, int len) const = 0;
Modified: branches/bleeding_edge/test/cctest/test-sockets.cc
==============================================================================
--- branches/bleeding_edge/test/cctest/test-sockets.cc (original)
+++ branches/bleeding_edge/test/cctest/test-sockets.cc Thu Mar 19 04:55:09
2009
@@ -105,7 +105,7 @@
}
// Close the client before the listener to avoid TIME_WAIT issues.
- client->Close();
+ client->Shutdown();
delete client;
delete listener;
}
--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---