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

Unified Diff: net/socket/socket_libevent.cc

Issue 509133002: Raw SocketDescriptor variant of UnixDomainServerSocket::Accept (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix usage of Close(), add a read() to unittest Created 6 years, 3 months 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 | « net/socket/socket_libevent.h ('k') | net/socket/unix_domain_client_socket_posix.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/socket/socket_libevent.cc
diff --git a/net/socket/socket_libevent.cc b/net/socket/socket_libevent.cc
index 84bd3a7ea6f048787151d79c91a8ef569ef853c0..cd40e49afa04efc3071f25e8860b411336d26fe7 100644
--- a/net/socket/socket_libevent.cc
+++ b/net/socket/socket_libevent.cc
@@ -106,6 +106,13 @@ int SocketLibevent::AdoptConnectedSocket(SocketDescriptor socket,
return OK;
}
+SocketDescriptor SocketLibevent::ReleaseConnectedSocket() {
+ StopWatchingAndCleanUp();
+ SocketDescriptor socket_fd = socket_fd_;
+ socket_fd_ = kInvalidSocket;
+ return socket_fd;
+}
+
int SocketLibevent::Bind(const SockaddrStorage& address) {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK_NE(kInvalidSocket, socket_fd_);
@@ -326,38 +333,13 @@ bool SocketLibevent::HasPeerAddress() const {
void SocketLibevent::Close() {
DCHECK(thread_checker_.CalledOnValidThread());
- bool ok = accept_socket_watcher_.StopWatchingFileDescriptor();
- DCHECK(ok);
- ok = read_socket_watcher_.StopWatchingFileDescriptor();
- DCHECK(ok);
- ok = write_socket_watcher_.StopWatchingFileDescriptor();
- DCHECK(ok);
+ StopWatchingAndCleanUp();
if (socket_fd_ != kInvalidSocket) {
if (IGNORE_EINTR(close(socket_fd_)) < 0)
PLOG(ERROR) << "close() returned an error, errno=" << errno;
socket_fd_ = kInvalidSocket;
}
-
- if (!accept_callback_.is_null()) {
- accept_socket_ = NULL;
- accept_callback_.Reset();
- }
-
- if (!read_callback_.is_null()) {
- read_buf_ = NULL;
- read_buf_len_ = 0;
- read_callback_.Reset();
- }
-
- if (!write_callback_.is_null()) {
- write_buf_ = NULL;
- write_buf_len_ = 0;
- write_callback_.Reset();
- }
-
- waiting_connect_ = false;
- peer_address_.reset();
}
void SocketLibevent::OnFileCanReadWithoutBlocking(int fd) {
@@ -468,4 +450,33 @@ void SocketLibevent::WriteCompleted() {
base::ResetAndReturn(&write_callback_).Run(rv);
}
+void SocketLibevent::StopWatchingAndCleanUp() {
+ bool ok = accept_socket_watcher_.StopWatchingFileDescriptor();
+ DCHECK(ok);
+ ok = read_socket_watcher_.StopWatchingFileDescriptor();
+ DCHECK(ok);
+ ok = write_socket_watcher_.StopWatchingFileDescriptor();
+ DCHECK(ok);
+
+ if (!accept_callback_.is_null()) {
+ accept_socket_ = NULL;
+ accept_callback_.Reset();
+ }
+
+ if (!read_callback_.is_null()) {
+ read_buf_ = NULL;
+ read_buf_len_ = 0;
+ read_callback_.Reset();
+ }
+
+ if (!write_callback_.is_null()) {
+ write_buf_ = NULL;
+ write_buf_len_ = 0;
+ write_callback_.Reset();
+ }
+
+ waiting_connect_ = false;
+ peer_address_.reset();
+}
+
} // namespace net
« no previous file with comments | « net/socket/socket_libevent.h ('k') | net/socket/unix_domain_client_socket_posix.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698