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

Side by Side Diff: net/socket/socket_posix.cc

Issue 2815993002: Adds a method to TCPServerSocket to adopt a socket. (Closed)
Patch Set: Rebased to fix merge conflict Created 3 years, 8 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 unified diff | Download patch
OLDNEW
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
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 }
mmenke 2017/04/21 19:20:38 nit: Don't use braces for one line if bodies.
Raul Vera 2017/05/01 05:35:25 Done. But I'd like to point out that the style gui
mmenke 2017/05/01 18:44:19 Note that you should generally be consistent with
105
106 SetPeerAddress(address);
107 return OK;
108 }
109
110 int SocketPosix::AdoptUnconnectedSocket(SocketDescriptor socket) {
101 DCHECK(thread_checker_.CalledOnValidThread()); 111 DCHECK(thread_checker_.CalledOnValidThread());
102 DCHECK_EQ(kInvalidSocket, socket_fd_); 112 DCHECK_EQ(kInvalidSocket, socket_fd_);
103 113
104 socket_fd_ = socket; 114 socket_fd_ = socket;
105 115
106 if (!base::SetNonBlocking(socket_fd_)) { 116 if (!base::SetNonBlocking(socket_fd_)) {
107 int rv = MapSystemError(errno); 117 int rv = MapSystemError(errno);
108 Close(); 118 Close();
109 return rv; 119 return rv;
110 } 120 }
111 121
112 SetPeerAddress(address);
113 return OK; 122 return OK;
114 } 123 }
115 124
116 SocketDescriptor SocketPosix::ReleaseConnectedSocket() { 125 SocketDescriptor SocketPosix::ReleaseConnectedSocket() {
117 StopWatchingAndCleanUp(); 126 StopWatchingAndCleanUp();
118 SocketDescriptor socket_fd = socket_fd_; 127 SocketDescriptor socket_fd = socket_fd_;
119 socket_fd_ = kInvalidSocket; 128 socket_fd_ = kInvalidSocket;
120 return socket_fd; 129 return socket_fd;
121 } 130 }
122 131
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 write_buf_ = NULL; 550 write_buf_ = NULL;
542 write_buf_len_ = 0; 551 write_buf_len_ = 0;
543 write_callback_.Reset(); 552 write_callback_.Reset();
544 } 553 }
545 554
546 waiting_connect_ = false; 555 waiting_connect_ = false;
547 peer_address_.reset(); 556 peer_address_.reset();
548 } 557 }
549 558
550 } // namespace net 559 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698