[email protected] | 3871252 | 2011-04-18 23:03:32 | [diff] [blame] | 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/scoped_ptr.h" |
| 12 | #include "base/win/object_watcher.h" |
| 13 | #include "base/threading/non_thread_safe.h" |
| 14 | #include "net/base/net_log.h" |
| 15 | #include "net/socket/server_socket.h" |
| 16 | |
| 17 | namespace net { |
| 18 | |
| 19 | class IPEndPoint; |
| 20 | |
| 21 | class TCPServerSocketWin : public ServerSocket, |
| 22 | public base::NonThreadSafe, |
| 23 | public base::win::ObjectWatcher::Delegate { |
| 24 | public: |
| 25 | TCPServerSocketWin(net::NetLog* net_log, |
| 26 | const net::NetLog::Source& source); |
| 27 | ~TCPServerSocketWin(); |
| 28 | |
| 29 | // net::ServerSocket implementation. |
| 30 | virtual int Listen(const net::IPEndPoint& address, int backlog); |
| 31 | virtual int GetLocalAddress(IPEndPoint* address) const; |
[email protected] | 3268023f | 2011-05-05 00:08:10 | [diff] [blame^] | 32 | virtual int Accept(scoped_ptr<StreamSocket>* socket, |
[email protected] | 3871252 | 2011-04-18 23:03:32 | [diff] [blame] | 33 | CompletionCallback* callback); |
| 34 | |
| 35 | // base::ObjectWatcher::Delegate implementation. |
| 36 | virtual void OnObjectSignaled(HANDLE object); |
| 37 | |
| 38 | private: |
[email protected] | 3268023f | 2011-05-05 00:08:10 | [diff] [blame^] | 39 | int AcceptInternal(scoped_ptr<StreamSocket>* socket); |
[email protected] | 3871252 | 2011-04-18 23:03:32 | [diff] [blame] | 40 | void Close(); |
| 41 | |
| 42 | SOCKET socket_; |
| 43 | HANDLE socket_event_; |
| 44 | |
| 45 | base::win::ObjectWatcher accept_watcher_; |
| 46 | |
[email protected] | 3268023f | 2011-05-05 00:08:10 | [diff] [blame^] | 47 | scoped_ptr<StreamSocket>* accept_socket_; |
[email protected] | 3871252 | 2011-04-18 23:03:32 | [diff] [blame] | 48 | CompletionCallback* accept_callback_; |
| 49 | |
| 50 | BoundNetLog net_log_; |
| 51 | }; |
| 52 | |
| 53 | } // namespace net |
| 54 | |
| 55 | #endif // NET_SOCKET_TCP_SERVER_SOCKET_WIN_H_ |