OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef NET_SOCKET_TCP_SERVER_SOCKET_WIN_H_ |
| 6 #define NET_SOCKET_TCP_SERVER_SOCKET_WIN_H_ |
| 7 |
| 8 #include <winsock2.h> |
| 9 |
| 10 #include "base/message_loop.h" |
| 11 #include "base/win/object_watcher.h" |
| 12 #include "base/threading/non_thread_safe.h" |
| 13 #include "net/base/completion_callback.h" |
| 14 #include "net/socket/tcp_client_socket.h" |
| 15 |
| 16 namespace net { |
| 17 |
| 18 class IPEndPoint; |
| 19 |
| 20 class TCPServerSocketWin : public base::NonThreadSafe, |
| 21 private base::win::ObjectWatcher::Delegate { |
| 22 public: |
| 23 TCPServerSocketWin(net::NetLog* net_log, |
| 24 const net::NetLog::Source& source); |
| 25 ~TCPServerSocketWin(); |
| 26 |
| 27 // Bind the socket and start listening. |
| 28 int Bind(const net::IPEndPoint& address, int backlog); |
| 29 |
| 30 // Gets current address the socket is bound to. |
| 31 int GetLocalAddress(IPEndPoint* address) const; |
| 32 |
| 33 // Accept connection. Callback is called when new connection is |
| 34 // accepted. |
| 35 int Accept(TCPClientSocket** socket, IPEndPoint* address, |
| 36 CompletionCallback* callback); |
| 37 private: |
| 38 int AcceptInternal(TCPClientSocket** socket, net::IPEndPoint* address); |
| 39 |
| 40 // base::ObjectWatcher::Delegate implementation. |
| 41 virtual void OnObjectSignaled(HANDLE object); |
| 42 |
| 43 SOCKET socket_; |
| 44 HANDLE socket_event_; |
| 45 |
| 46 base::win::ObjectWatcher accept_watcher_; |
| 47 |
| 48 TCPClientSocket** accept_socket_; |
| 49 IPEndPoint* accept_address_; |
| 50 CompletionCallback* accept_callback_; |
| 51 |
| 52 net::NetLog* net_log_; |
| 53 net::NetLog::Source net_log_source_; |
| 54 }; |
| 55 |
| 56 } // namespace net |
| 57 |
| 58 #endif // NET_SOCKET_TCP_SERVER_SOCKET_WIN_H_ |
OLD | NEW |