| 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_posix.h" | 5 #include "net/socket/socket_posix.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 #include <utility> | 10 #include <utility> |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 int rv = MapSystemError(errno); | 91 int rv = MapSystemError(errno); |
| 92 Close(); | 92 Close(); |
| 93 return rv; | 93 return rv; |
| 94 } | 94 } |
| 95 | 95 |
| 96 return OK; | 96 return OK; |
| 97 } | 97 } |
| 98 | 98 |
| 99 int SocketPosix::AdoptConnectedSocket(SocketDescriptor socket, | 99 int SocketPosix::AdoptConnectedSocket(SocketDescriptor socket, |
| 100 const SockaddrStorage& address) { | 100 const SockaddrStorage& address) { |
| 101 int rv = AdoptUnconnectedSocket(socket); |
| 102 if (rv != OK) |
| 103 return rv; |
| 104 |
| 105 SetPeerAddress(address); |
| 106 return OK; |
| 107 } |
| 108 |
| 109 int SocketPosix::AdoptUnconnectedSocket(SocketDescriptor socket) { |
| 101 DCHECK(thread_checker_.CalledOnValidThread()); | 110 DCHECK(thread_checker_.CalledOnValidThread()); |
| 102 DCHECK_EQ(kInvalidSocket, socket_fd_); | 111 DCHECK_EQ(kInvalidSocket, socket_fd_); |
| 103 | 112 |
| 104 socket_fd_ = socket; | 113 socket_fd_ = socket; |
| 105 | 114 |
| 106 if (!base::SetNonBlocking(socket_fd_)) { | 115 if (!base::SetNonBlocking(socket_fd_)) { |
| 107 int rv = MapSystemError(errno); | 116 int rv = MapSystemError(errno); |
| 108 Close(); | 117 Close(); |
| 109 return rv; | 118 return rv; |
| 110 } | 119 } |
| 111 | 120 |
| 112 SetPeerAddress(address); | |
| 113 return OK; | 121 return OK; |
| 114 } | 122 } |
| 115 | 123 |
| 116 SocketDescriptor SocketPosix::ReleaseConnectedSocket() { | 124 SocketDescriptor SocketPosix::ReleaseConnectedSocket() { |
| 117 StopWatchingAndCleanUp(); | 125 StopWatchingAndCleanUp(); |
| 118 SocketDescriptor socket_fd = socket_fd_; | 126 SocketDescriptor socket_fd = socket_fd_; |
| 119 socket_fd_ = kInvalidSocket; | 127 socket_fd_ = kInvalidSocket; |
| 120 return socket_fd; | 128 return socket_fd; |
| 121 } | 129 } |
| 122 | 130 |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 write_buf_ = NULL; | 549 write_buf_ = NULL; |
| 542 write_buf_len_ = 0; | 550 write_buf_len_ = 0; |
| 543 write_callback_.Reset(); | 551 write_callback_.Reset(); |
| 544 } | 552 } |
| 545 | 553 |
| 546 waiting_connect_ = false; | 554 waiting_connect_ = false; |
| 547 peer_address_.reset(); | 555 peer_address_.reset(); |
| 548 } | 556 } |
| 549 | 557 |
| 550 } // namespace net | 558 } // namespace net |
| OLD | NEW |