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 #ifndef NET_SOCKET_TCP_SERVER_SOCKET_LIBEVENT_H_ | 5 #ifndef NET_SOCKET_TCP_SERVER_SOCKET_LIBEVENT_H_ |
6 #define NET_SOCKET_TCP_SERVER_SOCKET_LIBEVENT_H_ | 6 #define NET_SOCKET_TCP_SERVER_SOCKET_LIBEVENT_H_ |
7 | 7 |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
10 #include "base/threading/non_thread_safe.h" | 10 #include "base/threading/non_thread_safe.h" |
11 #include "net/base/completion_callback.h" | 11 #include "net/base/completion_callback.h" |
12 #include "net/base/net_log.h" | 12 #include "net/base/net_log.h" |
13 #include "net/socket/server_socket.h" | 13 #include "net/socket/server_socket.h" |
14 | 14 |
15 namespace net { | 15 namespace net { |
16 | 16 |
17 class IPEndPoint; | 17 class IPEndPoint; |
18 | 18 |
19 class TCPServerSocketLibevent : public ServerSocket, | 19 class TCPServerSocketLibevent : public ServerSocket, |
20 public base::NonThreadSafe, | 20 public base::NonThreadSafe, |
21 public MessageLoopForIO::Watcher { | 21 public MessageLoopForIO::Watcher { |
22 public: | 22 public: |
23 TCPServerSocketLibevent(net::NetLog* net_log, | 23 TCPServerSocketLibevent(net::NetLog* net_log, |
24 const net::NetLog::Source& source); | 24 const net::NetLog::Source& source); |
25 ~TCPServerSocketLibevent(); | 25 virtual ~TCPServerSocketLibevent(); |
26 | 26 |
27 // net::ServerSocket implementation. | 27 // net::ServerSocket implementation. |
28 virtual int Listen(const net::IPEndPoint& address, int backlog); | 28 virtual int Listen(const net::IPEndPoint& address, int backlog); |
29 virtual int GetLocalAddress(IPEndPoint* address) const; | 29 virtual int GetLocalAddress(IPEndPoint* address) const; |
30 virtual int Accept(scoped_ptr<StreamSocket>* socket, | 30 virtual int Accept(scoped_ptr<StreamSocket>* socket, |
31 CompletionCallback* callback); | 31 CompletionCallback* callback); |
32 | 32 |
33 // MessageLoopForIO::Watcher implementation. | 33 // MessageLoopForIO::Watcher implementation. |
34 virtual void OnFileCanReadWithoutBlocking(int fd); | 34 virtual void OnFileCanReadWithoutBlocking(int fd); |
35 virtual void OnFileCanWriteWithoutBlocking(int fd); | 35 virtual void OnFileCanWriteWithoutBlocking(int fd); |
36 | 36 |
37 private: | 37 private: |
38 int AcceptInternal(scoped_ptr<StreamSocket>* socket); | 38 int AcceptInternal(scoped_ptr<StreamSocket>* socket); |
39 void Close(); | 39 void Close(); |
40 | 40 |
41 int socket_; | 41 int socket_; |
42 | 42 |
43 MessageLoopForIO::FileDescriptorWatcher accept_socket_watcher_; | 43 MessageLoopForIO::FileDescriptorWatcher accept_socket_watcher_; |
44 | 44 |
45 scoped_ptr<StreamSocket>* accept_socket_; | 45 scoped_ptr<StreamSocket>* accept_socket_; |
46 CompletionCallback* accept_callback_; | 46 CompletionCallback* accept_callback_; |
47 | 47 |
48 BoundNetLog net_log_; | 48 BoundNetLog net_log_; |
49 }; | 49 }; |
50 | 50 |
51 } // namespace net | 51 } // namespace net |
52 | 52 |
53 #endif // NET_SOCKET_TCP_SERVER_SOCKET_LIBEVENT_H_ | 53 #endif // NET_SOCKET_TCP_SERVER_SOCKET_LIBEVENT_H_ |
OLD | NEW |