Chromium Code Reviews| Index: net/base/tcp_listen_socket.cc |
| =================================================================== |
| --- net/base/tcp_listen_socket.cc (revision 170891) |
| +++ net/base/tcp_listen_socket.cc (working copy) |
| @@ -76,6 +76,28 @@ |
| return s; |
| } |
| +SocketDescriptor TCPListenSocket::CreateAndBindAnyPort(const string& ip, |
| + int* port) { |
| + SocketDescriptor s = CreateAndBind(ip, 0); |
|
szym
2012/12/05 18:21:37
Check if (s == kInvalidSocket) and return early he
halyavin
2012/12/06 15:35:01
Done.
|
| + sockaddr_in addr; |
| + socklen_t addr_size = sizeof(addr); |
| + bool failed = getsockname(s, (struct sockaddr *) &addr, &addr_size) != 0; |
|
Mark Seaborn
2012/12/05 18:00:47
Use reinterpret_cast<> here
halyavin
2012/12/06 15:35:01
Done.
|
| + if (addr_size != sizeof(addr)) { |
| + failed = true; |
| + } |
| + if (failed) { |
| + LOG(ERROR) << "Could not determine bound port, getsockname() failed"; |
| +#if defined(OS_WIN) |
| + closesocket(s); |
| +#elif defined(OS_POSIX) |
| + close(s); |
| +#endif |
| + return kInvalidSocket; |
| + } |
| + *port = base::NetToHost16(addr.sin_port); |
| + return s; |
| +} |
| + |
| void TCPListenSocket::Accept() { |
| SocketDescriptor conn = AcceptSocket(); |
| if (conn == kInvalidSocket) |