Commit 881e01b2 authored by sgjesse@chromium.org's avatar sgjesse@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@1545 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent c918bec9
......@@ -650,8 +650,7 @@ class FreeBSDSocket : public Socket {
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 @@ class FreeBSDSocket : public Socket {
// 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,16 +739,18 @@ bool FreeBSDSocket::Connect(const char* host, const char* port) {
}
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);
return status;
......
......@@ -651,8 +651,7 @@ class LinuxSocket : public Socket {
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 @@ class LinuxSocket : public Socket {
// 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::Connect(const char* host, const char* port) {
}
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;
}
......
......@@ -576,8 +576,7 @@ class MacOSSocket : public Socket {
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 @@ class MacOSSocket : public Socket {
// 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::Connect(const char* host, const char* port) {
}
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;
}
......
......@@ -1548,9 +1548,7 @@ class Win32Socket : public Socket {
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 @@ class Win32Socket : public Socket {
// 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::Connect(const char* host, const char* port) {
}
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;
}
......
......@@ -439,8 +439,10 @@ class Socket {
// 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;
......
......@@ -105,7 +105,7 @@ static void SendAndReceive(char *data, int len) {
}
// Close the client before the listener to avoid TIME_WAIT issues.
client->Close();
client->Shutdown();
delete client;
delete listener;
}
......
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