| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Stream-based listen socket implementation that handles reading and writing | 5 // Stream-based listen socket implementation that handles reading and writing |
| 6 // to the socket, but does not handle creating the socket nor connecting | 6 // to the socket, but does not handle creating the socket nor connecting |
| 7 // sockets, which are handled by subclasses on creation and in Accept, | 7 // sockets, which are handled by subclasses on creation and in Accept, |
| 8 // respectively. | 8 // respectively. |
| 9 | 9 |
| 10 // StreamListenSocket handles IO asynchronously in the specified MessageLoop. | 10 // StreamListenSocket handles IO asynchronously in the specified MessageLoop. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 #include "base/basictypes.h" | 31 #include "base/basictypes.h" |
| 32 #include "base/compiler_specific.h" | 32 #include "base/compiler_specific.h" |
| 33 #include "base/memory/scoped_ptr.h" | 33 #include "base/memory/scoped_ptr.h" |
| 34 #include "net/base/net_export.h" | 34 #include "net/base/net_export.h" |
| 35 #include "net/socket/socket_descriptor.h" | 35 #include "net/socket/socket_descriptor.h" |
| 36 | 36 |
| 37 namespace net { | 37 namespace net { |
| 38 | 38 |
| 39 class IPEndPoint; | 39 class IPEndPoint; |
| 40 | 40 |
| 41 class NET_EXPORT StreamListenSocket | 41 class NET_EXPORT StreamListenSocket : |
| 42 : | |
| 43 #if defined(OS_WIN) | 42 #if defined(OS_WIN) |
| 44 public base::win::ObjectWatcher::Delegate { | 43 public base::win::ObjectWatcher::Delegate { |
| 45 #elif defined(OS_POSIX) | 44 #elif defined(OS_POSIX) |
| 46 public base::MessageLoopForIO::Watcher { | 45 public base::MessageLoopForIO::Watcher { |
| 47 #endif | 46 #endif |
| 48 | 47 |
| 49 public: | 48 public: |
| 50 virtual ~StreamListenSocket(); | 49 virtual ~StreamListenSocket(); |
| 51 | 50 |
| 52 // TODO(erikkay): this delegate should really be split into two parts | 51 // TODO(erikkay): this delegate should really be split into two parts |
| 53 // to split up the listener from the connected socket. Perhaps this class | 52 // to split up the listener from the connected socket. Perhaps this class |
| 54 // should be split up similarly. | 53 // should be split up similarly. |
| 55 class Delegate { | 54 class Delegate { |
| 56 public: | 55 public: |
| (...skipping 15 matching lines...) Expand all Loading... |
| 72 void Send(const std::string& str, bool append_linefeed = false); | 71 void Send(const std::string& str, bool append_linefeed = false); |
| 73 | 72 |
| 74 // Copies the local address to |address|. Returns a network error code. | 73 // Copies the local address to |address|. Returns a network error code. |
| 75 int GetLocalAddress(IPEndPoint* address); | 74 int GetLocalAddress(IPEndPoint* address); |
| 76 // Copies the peer address to |address|. Returns a network error code. | 75 // Copies the peer address to |address|. Returns a network error code. |
| 77 int GetPeerAddress(IPEndPoint* address); | 76 int GetPeerAddress(IPEndPoint* address); |
| 78 | 77 |
| 79 static const int kSocketError; | 78 static const int kSocketError; |
| 80 | 79 |
| 81 protected: | 80 protected: |
| 82 enum WaitState { | 81 enum WaitState { NOT_WAITING = 0, WAITING_ACCEPT = 1, WAITING_READ = 2 }; |
| 83 NOT_WAITING = 0, | |
| 84 WAITING_ACCEPT = 1, | |
| 85 WAITING_READ = 2 | |
| 86 }; | |
| 87 | 82 |
| 88 StreamListenSocket(SocketDescriptor s, Delegate* del); | 83 StreamListenSocket(SocketDescriptor s, Delegate* del); |
| 89 | 84 |
| 90 SocketDescriptor AcceptSocket(); | 85 SocketDescriptor AcceptSocket(); |
| 91 virtual void Accept() = 0; | 86 virtual void Accept() = 0; |
| 92 | 87 |
| 93 void Listen(); | 88 void Listen(); |
| 94 void Read(); | 89 void Read(); |
| 95 void Close(); | 90 void Close(); |
| 96 void CloseSocket(); | 91 void CloseSocket(); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 virtual ~StreamListenSocketFactory() {} | 136 virtual ~StreamListenSocketFactory() {} |
| 142 | 137 |
| 143 // Returns a new instance of StreamListenSocket or NULL if an error occurred. | 138 // Returns a new instance of StreamListenSocket or NULL if an error occurred. |
| 144 virtual scoped_ptr<StreamListenSocket> CreateAndListen( | 139 virtual scoped_ptr<StreamListenSocket> CreateAndListen( |
| 145 StreamListenSocket::Delegate* delegate) const = 0; | 140 StreamListenSocket::Delegate* delegate) const = 0; |
| 146 }; | 141 }; |
| 147 | 142 |
| 148 } // namespace net | 143 } // namespace net |
| 149 | 144 |
| 150 #endif // NET_SOCKET_STREAM_LISTEN_SOCKET_H_ | 145 #endif // NET_SOCKET_STREAM_LISTEN_SOCKET_H_ |
| OLD | NEW |