| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_server_socket_win.h" | 5 #include "net/socket/tcp_server_socket_win.h" |
| 6 | 6 |
| 7 #include <mstcpip.h> | 7 #include <mstcpip.h> |
| 8 | 8 |
| 9 #include "net/base/ip_endpoint.h" | 9 #include "net/base/ip_endpoint.h" |
| 10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
| 11 #include "net/base/net_util.h" | 11 #include "net/base/net_util.h" |
| 12 #include "net/base/winsock_init.h" | 12 #include "net/base/winsock_init.h" |
| 13 #include "net/base/winsock_util.h" | 13 #include "net/base/winsock_util.h" |
| 14 #include "net/socket/tcp_client_socket.h" | 14 #include "net/socket/tcp_client_socket.h" |
| 15 | 15 |
| 16 namespace net { | 16 namespace net { |
| 17 | 17 |
| 18 TCPServerSocketWin::TCPServerSocketWin(net::NetLog* net_log, | 18 TCPServerSocketWin::TCPServerSocketWin(net::NetLog* net_log, |
| 19 const net::NetLog::Source& source) | 19 const net::NetLog::Source& source) |
| 20 : socket_(INVALID_SOCKET), | 20 : socket_(INVALID_SOCKET), |
| 21 socket_event_(WSA_INVALID_EVENT), | 21 socket_event_(WSA_INVALID_EVENT), |
| 22 accept_socket_(NULL), | 22 accept_socket_(NULL), |
| 23 accept_callback_(NULL), | |
| 24 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SOCKET)) { | 23 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SOCKET)) { |
| 25 scoped_refptr<NetLog::EventParameters> params; | 24 scoped_refptr<NetLog::EventParameters> params; |
| 26 if (source.is_valid()) | 25 if (source.is_valid()) |
| 27 params = new NetLogSourceParameter("source_dependency", source); | 26 params = new NetLogSourceParameter("source_dependency", source); |
| 28 net_log_.BeginEvent(NetLog::TYPE_SOCKET_ALIVE, params); | 27 net_log_.BeginEvent(NetLog::TYPE_SOCKET_ALIVE, params); |
| 29 EnsureWinsockInit(); | 28 EnsureWinsockInit(); |
| 30 } | 29 } |
| 31 | 30 |
| 32 TCPServerSocketWin::~TCPServerSocketWin() { | 31 TCPServerSocketWin::~TCPServerSocketWin() { |
| 33 Close(); | 32 Close(); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 struct sockaddr* addr = reinterpret_cast<struct sockaddr*>(&addr_storage); | 91 struct sockaddr* addr = reinterpret_cast<struct sockaddr*>(&addr_storage); |
| 93 if (getsockname(socket_, addr, &addr_len)) | 92 if (getsockname(socket_, addr, &addr_len)) |
| 94 return MapSystemError(WSAGetLastError()); | 93 return MapSystemError(WSAGetLastError()); |
| 95 if (!address->FromSockAddr(addr, addr_len)) | 94 if (!address->FromSockAddr(addr, addr_len)) |
| 96 return ERR_FAILED; | 95 return ERR_FAILED; |
| 97 | 96 |
| 98 return OK; | 97 return OK; |
| 99 } | 98 } |
| 100 | 99 |
| 101 int TCPServerSocketWin::Accept( | 100 int TCPServerSocketWin::Accept( |
| 102 scoped_ptr<StreamSocket>* socket, OldCompletionCallback* callback) { | 101 scoped_ptr<StreamSocket>* socket, const CompletionCallback& callback) { |
| 103 DCHECK(CalledOnValidThread()); | 102 DCHECK(CalledOnValidThread()); |
| 104 DCHECK(socket); | 103 DCHECK(socket); |
| 105 DCHECK(callback); | 104 DCHECK(!callback.is_null()); |
| 106 DCHECK(!accept_callback_); | 105 DCHECK(accept_callback_.is_null()); |
| 107 | 106 |
| 108 net_log_.BeginEvent(NetLog::TYPE_TCP_ACCEPT, NULL); | 107 net_log_.BeginEvent(NetLog::TYPE_TCP_ACCEPT, NULL); |
| 109 | 108 |
| 110 int result = AcceptInternal(socket); | 109 int result = AcceptInternal(socket); |
| 111 | 110 |
| 112 if (result == ERR_IO_PENDING) { | 111 if (result == ERR_IO_PENDING) { |
| 113 // Start watching | 112 // Start watching |
| 114 WSAEventSelect(socket_, socket_event_, FD_ACCEPT); | 113 WSAEventSelect(socket_, socket_event_, FD_ACCEPT); |
| 115 accept_watcher_.StartWatching(socket_event_, this); | 114 accept_watcher_.StartWatching(socket_event_, this); |
| 116 | 115 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 void TCPServerSocketWin::OnObjectSignaled(HANDLE object) { | 174 void TCPServerSocketWin::OnObjectSignaled(HANDLE object) { |
| 176 WSANETWORKEVENTS ev; | 175 WSANETWORKEVENTS ev; |
| 177 if (WSAEnumNetworkEvents(socket_, socket_event_, &ev) == SOCKET_ERROR) { | 176 if (WSAEnumNetworkEvents(socket_, socket_event_, &ev) == SOCKET_ERROR) { |
| 178 PLOG(ERROR) << "WSAEnumNetworkEvents()"; | 177 PLOG(ERROR) << "WSAEnumNetworkEvents()"; |
| 179 return; | 178 return; |
| 180 } | 179 } |
| 181 | 180 |
| 182 if (ev.lNetworkEvents & FD_ACCEPT) { | 181 if (ev.lNetworkEvents & FD_ACCEPT) { |
| 183 int result = AcceptInternal(accept_socket_); | 182 int result = AcceptInternal(accept_socket_); |
| 184 if (result != ERR_IO_PENDING) { | 183 if (result != ERR_IO_PENDING) { |
| 185 OldCompletionCallback* c = accept_callback_; | |
| 186 accept_callback_ = NULL; | |
| 187 accept_socket_ = NULL; | 184 accept_socket_ = NULL; |
| 188 c->Run(result); | 185 accept_callback_.Run(result); |
| 186 accept_callback_.Reset(); |
| 189 } | 187 } |
| 190 } | 188 } |
| 191 } | 189 } |
| 192 | 190 |
| 193 } // namespace net | 191 } // namespace net |
| OLD | NEW |