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