Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2807)

Unified Diff: base/sync_socket_posix.cc

Issue 8965053: Implement support for a cancelable SyncSocket. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Using a single event for file operations on Windows. Some comment improvements. Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/sync_socket.h ('k') | base/sync_socket_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/sync_socket_posix.cc
diff --git a/base/sync_socket_posix.cc b/base/sync_socket_posix.cc
index f50d20b9f9918e3244b5bca826f36a39170f9f96..4e9ce22b696533988f974c76836f6d04cb86dbe2 100644
--- a/base/sync_socket_posix.cc
+++ b/base/sync_socket_posix.cc
@@ -30,25 +30,26 @@ static const SyncSocket::Handle kInvalidHandle = -1;
} // namespace
-bool SyncSocket::CreatePair(SyncSocket* pair[2]) {
- Handle handles[2] = { kInvalidHandle, kInvalidHandle };
- SyncSocket* tmp_sockets[2] = { NULL, NULL };
+SyncSocket::SyncSocket() : handle_(kInvalidHandle) {}
+
+SyncSocket::~SyncSocket() {
+ Close();
+}
+
+// static
+bool SyncSocket::CreatePair(SyncSocket* socket_a, SyncSocket* socket_b) {
+ DCHECK(socket_a != socket_b);
+ DCHECK(socket_a->handle_ == kInvalidHandle);
+ DCHECK(socket_b->handle_ == kInvalidHandle);
+
#if defined(OS_MACOSX)
int nosigpipe = 1;
#endif // defined(OS_MACOSX)
- // Create the two SyncSocket objects first to avoid ugly cleanup issues.
- tmp_sockets[0] = new SyncSocket(kInvalidHandle);
- if (tmp_sockets[0] == NULL) {
- goto cleanup;
- }
- tmp_sockets[1] = new SyncSocket(kInvalidHandle);
- if (tmp_sockets[1] == NULL) {
- goto cleanup;
- }
- if (socketpair(AF_UNIX, SOCK_STREAM, 0, handles) != 0) {
+ Handle handles[2] = { kInvalidHandle, kInvalidHandle };
+ if (socketpair(AF_UNIX, SOCK_STREAM, 0, handles) != 0)
goto cleanup;
- }
+
#if defined(OS_MACOSX)
// On OSX an attempt to read or write to a closed socket may generate a
// SIGPIPE rather than returning -1. setsockopt will shut this off.
@@ -59,11 +60,11 @@ bool SyncSocket::CreatePair(SyncSocket* pair[2]) {
goto cleanup;
}
#endif
+
// Copy the handles out for successful return.
- tmp_sockets[0]->handle_ = handles[0];
- pair[0] = tmp_sockets[0];
- tmp_sockets[1]->handle_ = handles[1];
- pair[1] = tmp_sockets[1];
+ socket_a->handle_ = handles[0];
+ socket_b->handle_ = handles[1];
+
return true;
cleanup:
@@ -75,8 +76,7 @@ bool SyncSocket::CreatePair(SyncSocket* pair[2]) {
if (HANDLE_EINTR(close(handles[1])) < 0)
DPLOG(ERROR) << "close";
}
- delete tmp_sockets[0];
- delete tmp_sockets[1];
+
return false;
}
@@ -117,4 +117,13 @@ size_t SyncSocket::Peek() {
return (size_t) number_chars;
}
+CancelableSyncSocket::CancelableSyncSocket() {}
+CancelableSyncSocket::CancelableSyncSocket(Handle handle)
+ : SyncSocket(handle) {
+}
+
+bool CancelableSyncSocket::Shutdown() {
+ return HANDLE_EINTR(shutdown(handle(), SHUT_RDWR)) >= 0;
Ami GONE FROM CHROMIUM 2011/12/21 17:41:30 What guarantees that shutdown() is thread-safe?
+}
+
} // namespace base
« no previous file with comments | « base/sync_socket.h ('k') | base/sync_socket_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698