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

Side by Side Diff: net/socket/tcp_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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/tcp_socket.h" 5 #include "net/socket/tcp_socket.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <netinet/tcp.h> 8 #include <netinet/tcp.h>
9 #include <sys/socket.h> 9 #include <sys/socket.h>
10 10
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 168
169 int TCPSocketPosix::Open(AddressFamily family) { 169 int TCPSocketPosix::Open(AddressFamily family) {
170 DCHECK(!socket_); 170 DCHECK(!socket_);
171 socket_.reset(new SocketPosix); 171 socket_.reset(new SocketPosix);
172 int rv = socket_->Open(ConvertAddressFamily(family)); 172 int rv = socket_->Open(ConvertAddressFamily(family));
173 if (rv != OK) 173 if (rv != OK)
174 socket_.reset(); 174 socket_.reset();
175 return rv; 175 return rv;
176 } 176 }
177 177
178 int TCPSocketPosix::AdoptConnectedSocket(int socket_fd, 178 int TCPSocketPosix::AdoptConnectedSocket(SocketDescriptor socket,
179 const IPEndPoint& peer_address) { 179 const IPEndPoint& peer_address) {
180 DCHECK(!socket_); 180 DCHECK(!socket_);
181 181
182 SockaddrStorage storage; 182 SockaddrStorage storage;
183 if (!peer_address.ToSockAddr(storage.addr, &storage.addr_len) && 183 if (!peer_address.ToSockAddr(storage.addr, &storage.addr_len) &&
184 // For backward compatibility, allows the empty address. 184 // For backward compatibility, allows the empty address.
185 !(peer_address == IPEndPoint())) { 185 !(peer_address == IPEndPoint())) {
186 return ERR_ADDRESS_INVALID; 186 return ERR_ADDRESS_INVALID;
187 } 187 }
188 188
189 socket_.reset(new SocketPosix); 189 socket_.reset(new SocketPosix);
190 int rv = socket_->AdoptConnectedSocket(socket_fd, storage); 190 int rv = socket_->AdoptConnectedSocket(socket, storage);
191 if (rv != OK) 191 if (rv != OK)
192 socket_.reset(); 192 socket_.reset();
193 return rv; 193 return rv;
194 }
195
196 int TCPSocketPosix::AdoptUnconnectedSocket(SocketDescriptor socket) {
197 DCHECK(!socket_);
198
199 socket_.reset(new SocketPosix);
200 int rv = socket_->AdoptUnconnectedSocket(socket);
201 if (rv != OK)
202 socket_.reset();
203 return rv;
194 } 204 }
195 205
196 int TCPSocketPosix::Bind(const IPEndPoint& address) { 206 int TCPSocketPosix::Bind(const IPEndPoint& address) {
197 DCHECK(socket_); 207 DCHECK(socket_);
198 208
199 SockaddrStorage storage; 209 SockaddrStorage storage;
200 if (!address.ToSockAddr(storage.addr, &storage.addr_len)) 210 if (!address.ToSockAddr(storage.addr, &storage.addr_len))
201 return ERR_ADDRESS_INVALID; 211 return ERR_ADDRESS_INVALID;
202 212
203 return socket_->Bind(storage); 213 return socket_->Bind(storage);
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 if (info.tcpi_rtt > 0) { 824 if (info.tcpi_rtt > 0) {
815 *out_rtt = base::TimeDelta::FromMicroseconds(info.tcpi_rtt); 825 *out_rtt = base::TimeDelta::FromMicroseconds(info.tcpi_rtt);
816 return true; 826 return true;
817 } 827 }
818 } 828 }
819 #endif // defined(TCP_INFO) 829 #endif // defined(TCP_INFO)
820 return false; 830 return false;
821 } 831 }
822 832
823 } // namespace net 833 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698