diff options
author | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-27 20:03:16 +0000 |
---|---|---|
committer | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-27 20:03:16 +0000 |
commit | a1b95f0eaba4d94ceb0711f2fd3245d8ecd444a0 (patch) | |
tree | 3f7208d4742fab73de02b90af827a3f689dae2a5 /net/socket/tcp_server_socket_win.cc | |
parent | 55775cc217406277d7591c22f5d7abec91773edc (diff) | |
download | chromium_src-a1b95f0eaba4d94ceb0711f2fd3245d8ecd444a0.zip chromium_src-a1b95f0eaba4d94ceb0711f2fd3245d8ecd444a0.tar.gz chromium_src-a1b95f0eaba4d94ceb0711f2fd3245d8ecd444a0.tar.bz2 |
Bind() methods for TCP sockets
BUG=80245
TEST=None
Review URL: http://codereview.chromium.org/7004055
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@87077 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/socket/tcp_server_socket_win.cc')
-rw-r--r-- | net/socket/tcp_server_socket_win.cc | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/net/socket/tcp_server_socket_win.cc b/net/socket/tcp_server_socket_win.cc index a850a8a..55c2439 100644 --- a/net/socket/tcp_server_socket_win.cc +++ b/net/socket/tcp_server_socket_win.cc @@ -46,7 +46,7 @@ int TCPServerSocketWin::Listen(const IPEndPoint& address, int backlog) { return ERR_FAILED; } - socket_ = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + socket_ = socket(address.GetFamily(), SOCK_STREAM, IPPROTO_TCP); if (socket_ < 0) { PLOG(ERROR) << "socket() returned an error"; return MapSystemError(WSAGetLastError()); @@ -126,8 +126,8 @@ int TCPServerSocketWin::AcceptInternal(scoped_ptr<StreamSocket>* socket) { socklen_t addr_len = sizeof(addr_storage); struct sockaddr* addr = reinterpret_cast<struct sockaddr*>(&addr_storage); - int result = accept(socket_, addr, &addr_len); - if (result < 0) { + int new_socket = accept(socket_, addr, &addr_len); + if (new_socket < 0) { int net_error = MapSystemError(WSAGetLastError()); if (net_error != ERR_IO_PENDING) net_log_.EndEventWithNetErrorCode(NetLog::TYPE_TCP_ACCEPT, net_error); @@ -137,16 +137,22 @@ int TCPServerSocketWin::AcceptInternal(scoped_ptr<StreamSocket>* socket) { IPEndPoint address; if (!address.FromSockAddr(addr, addr_len)) { NOTREACHED(); - if (closesocket(result) < 0) + if (closesocket(new_socket) < 0) PLOG(ERROR) << "closesocket"; net_log_.EndEventWithNetErrorCode(NetLog::TYPE_TCP_ACCEPT, ERR_FAILED); return ERR_FAILED; } - TCPClientSocket* tcp_socket = new TCPClientSocket( + scoped_ptr<TCPClientSocket> tcp_socket(new TCPClientSocket( AddressList::CreateFromIPAddress(address.address(), address.port()), - net_log_.net_log(), net_log_.source()); - tcp_socket->AdoptSocket(result); - socket->reset(tcp_socket); + net_log_.net_log(), net_log_.source())); + int adopt_result = tcp_socket->AdoptSocket(new_socket); + if (adopt_result != OK) { + if (closesocket(new_socket) < 0) + PLOG(ERROR) << "closesocket"; + net_log_.EndEventWithNetErrorCode(NetLog::TYPE_TCP_ACCEPT, adopt_result); + return adopt_result; + } + socket->reset(tcp_socket.release()); net_log_.EndEvent(NetLog::TYPE_TCP_ACCEPT, make_scoped_refptr(new NetLogStringParameter( "address", address.ToString()))); |