OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/socket/socket_libevent.h" | 5 #include "net/socket/socket_libevent.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <netinet/in.h> | 8 #include <netinet/in.h> |
9 #include <sys/socket.h> | 9 #include <sys/socket.h> |
10 | 10 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 if (SetNonBlocking(socket_fd_)) { | 99 if (SetNonBlocking(socket_fd_)) { |
100 int rv = MapSystemError(errno); | 100 int rv = MapSystemError(errno); |
101 Close(); | 101 Close(); |
102 return rv; | 102 return rv; |
103 } | 103 } |
104 | 104 |
105 SetPeerAddress(address); | 105 SetPeerAddress(address); |
106 return OK; | 106 return OK; |
107 } | 107 } |
108 | 108 |
| 109 SocketDescriptor SocketLibevent::ReleaseConnectedSocket() { |
| 110 SocketDescriptor tmp_fd = socket_fd_; |
| 111 socket_fd_ = kInvalidSocket; |
| 112 Close(); |
| 113 return tmp_fd; |
| 114 } |
| 115 |
109 int SocketLibevent::Bind(const SockaddrStorage& address) { | 116 int SocketLibevent::Bind(const SockaddrStorage& address) { |
110 DCHECK(thread_checker_.CalledOnValidThread()); | 117 DCHECK(thread_checker_.CalledOnValidThread()); |
111 DCHECK_NE(kInvalidSocket, socket_fd_); | 118 DCHECK_NE(kInvalidSocket, socket_fd_); |
112 | 119 |
113 int rv = bind(socket_fd_, address.addr, address.addr_len); | 120 int rv = bind(socket_fd_, address.addr, address.addr_len); |
114 if (rv < 0) { | 121 if (rv < 0) { |
115 PLOG(ERROR) << "bind() returned an error, errno=" << errno; | 122 PLOG(ERROR) << "bind() returned an error, errno=" << errno; |
116 return MapSystemError(errno); | 123 return MapSystemError(errno); |
117 } | 124 } |
118 | 125 |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 return; | 469 return; |
463 | 470 |
464 bool ok = write_socket_watcher_.StopWatchingFileDescriptor(); | 471 bool ok = write_socket_watcher_.StopWatchingFileDescriptor(); |
465 DCHECK(ok); | 472 DCHECK(ok); |
466 write_buf_ = NULL; | 473 write_buf_ = NULL; |
467 write_buf_len_ = 0; | 474 write_buf_len_ = 0; |
468 base::ResetAndReturn(&write_callback_).Run(rv); | 475 base::ResetAndReturn(&write_callback_).Run(rv); |
469 } | 476 } |
470 | 477 |
471 } // namespace net | 478 } // namespace net |
OLD | NEW |