OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 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_SOCKET_LIBEVENT_H_ |
| 6 #define NET_SOCKET_TCP_SOCKET_LIBEVENT_H_ |
| 7 |
| 8 #include "base/basictypes.h" |
| 9 #include "base/compiler_specific.h" |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/threading/non_thread_safe.h" |
| 13 #include "net/base/address_family.h" |
| 14 #include "net/base/completion_callback.h" |
| 15 #include "net/base/net_export.h" |
| 16 #include "net/base/net_log.h" |
| 17 |
| 18 namespace net { |
| 19 |
| 20 class IPEndPoint; |
| 21 |
| 22 // TODO(yzshen): This class is incomplete. TCP client operations (Connect/Read/ |
| 23 // Write/etc.) will be added. And TCPClientSocket will be changed to be a |
| 24 // wrapper around TCPSocket. |
| 25 class NET_EXPORT TCPSocketLibevent : public base::NonThreadSafe, |
| 26 public base::MessageLoopForIO::Watcher { |
| 27 public: |
| 28 TCPSocketLibevent(NetLog* net_log, const NetLog::Source& source); |
| 29 virtual ~TCPSocketLibevent(); |
| 30 |
| 31 int Create(AddressFamily family); |
| 32 // Takes ownership of |socket|. |
| 33 int Adopt(int socket); |
| 34 // Returns a socket file descriptor. The ownership is transferred to the |
| 35 // caller. |
| 36 int Release(); |
| 37 int Bind(const IPEndPoint& address); |
| 38 int GetLocalAddress(IPEndPoint* address) const; |
| 39 int Listen(int backlog); |
| 40 int Accept(scoped_ptr<TCPSocketLibevent>* socket, |
| 41 IPEndPoint* address, |
| 42 const CompletionCallback& callback); |
| 43 int SetDefaultOptionsForServer(); |
| 44 int SetAddressReuse(bool allow); |
| 45 void Close(); |
| 46 |
| 47 const BoundNetLog& net_log() const { return net_log_; } |
| 48 |
| 49 // MessageLoopForIO::Watcher implementation. |
| 50 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE; |
| 51 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE; |
| 52 |
| 53 private: |
| 54 int AcceptInternal(scoped_ptr<TCPSocketLibevent>* socket, |
| 55 IPEndPoint* address); |
| 56 |
| 57 int socket_; |
| 58 |
| 59 base::MessageLoopForIO::FileDescriptorWatcher accept_socket_watcher_; |
| 60 |
| 61 scoped_ptr<TCPSocketLibevent>* accept_socket_; |
| 62 IPEndPoint* accept_address_; |
| 63 CompletionCallback accept_callback_; |
| 64 |
| 65 BoundNetLog net_log_; |
| 66 |
| 67 DISALLOW_COPY_AND_ASSIGN(TCPSocketLibevent); |
| 68 }; |
| 69 |
| 70 } // namespace net |
| 71 |
| 72 #endif // NET_SOCKET_TCP_SOCKET_LIBEVENT_H_ |
OLD | NEW |