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 class NET_EXPORT TCPSocketWin : NON_EXPORTED_BASE(public base::NonThreadSafe), |
| 26 public base::win::ObjectWatcher::Delegate { |
| 27 public: |
| 28 TCPSocketWin(NetLog* net_log, const NetLog::Source& source); |
| 29 virtual ~TCPSocketWin(); |
| 30 |
| 31 int Create(AddressFamily family); |
| 32 // Takes ownership of |socket|. |
| 33 int Adopt(SOCKET socket); |
| 34 // Returns a socket descriptor. The ownership is transferred to the caller. |
| 35 SOCKET Release(); |
| 36 int Bind(const IPEndPoint& address); |
| 37 int GetLocalAddress(IPEndPoint* address) const; |
| 38 int Listen(int backlog); |
| 39 int Accept(scoped_ptr<TCPSocketWin>* socket, |
| 40 IPEndPoint* address, |
| 41 const CompletionCallback& callback); |
| 42 int SetExclusiveAddrUse(); |
| 43 void Close(); |
| 44 |
| 45 const BoundNetLog& net_log() const { return net_log_; } |
| 46 |
| 47 // base::ObjectWatcher::Delegate implementation. |
| 48 virtual void OnObjectSignaled(HANDLE object) OVERRIDE; |
| 49 |
| 50 private: |
| 51 int AcceptInternal(scoped_ptr<TCPSocketWin>* socket, |
| 52 IPEndPoint* address); |
| 53 |
| 54 SOCKET socket_; |
| 55 HANDLE socket_event_; |
| 56 |
| 57 base::win::ObjectWatcher accept_watcher_; |
| 58 |
| 59 scoped_ptr<TCPSocketWin>* accept_socket_; |
| 60 IPEndPoint* accept_address_; |
| 61 CompletionCallback accept_callback_; |
| 62 |
| 63 BoundNetLog net_log_; |
| 64 |
| 65 DISALLOW_COPY_AND_ASSIGN(TCPSocketWin); |
| 66 }; |
| 67 |
| 68 } // namespace net |
| 69 |
| 70 #endif // NET_SOCKET_TCP_SOCKET_WIN_H_ |
OLD | NEW |