X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fnet%2Fsocket%2Fsocket_libevent.cc;h=cd40e49afa04efc3071f25e8860b411336d26fe7;hb=3545e9f2671f595d2a2f3ee75ca0393b01e35ef6;hp=c7b08be2476039661c3bc892f147bfda8f425176;hpb=7d210d4c7e9ba36e635eabc5b5780495f8a63292;p=platform%2Fframework%2Fweb%2Fcrosswalk.git diff --git a/src/net/socket/socket_libevent.cc b/src/net/socket/socket_libevent.cc index c7b08be..cd40e49 100644 --- a/src/net/socket/socket_libevent.cc +++ b/src/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) { @@ -440,7 +422,7 @@ int SocketLibevent::DoRead(IOBuffer* buf, int buf_len) { } void SocketLibevent::ReadCompleted() { - int rv = DoRead(read_buf_, read_buf_len_); + int rv = DoRead(read_buf_.get(), read_buf_len_); if (rv == ERR_IO_PENDING) return; @@ -457,7 +439,7 @@ int SocketLibevent::DoWrite(IOBuffer* buf, int buf_len) { } void SocketLibevent::WriteCompleted() { - int rv = DoWrite(write_buf_, write_buf_len_); + int rv = DoWrite(write_buf_.get(), write_buf_len_); if (rv == ERR_IO_PENDING) return; @@ -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