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 29 matching lines...) Expand all Loading... |
40 #include "net/base/stream_listen_socket.h" | 40 #include "net/base/stream_listen_socket.h" |
41 | 41 |
42 #if defined(OS_POSIX) | 42 #if defined(OS_POSIX) |
43 typedef int SocketDescriptor; | 43 typedef int SocketDescriptor; |
44 #else | 44 #else |
45 typedef SOCKET SocketDescriptor; | 45 typedef SOCKET SocketDescriptor; |
46 #endif | 46 #endif |
47 | 47 |
48 namespace net { | 48 namespace net { |
49 | 49 |
| 50 class IPEndPoint; |
| 51 |
50 class NET_EXPORT StreamListenSocket | 52 class NET_EXPORT StreamListenSocket |
51 : public base::RefCountedThreadSafe<StreamListenSocket>, | 53 : public base::RefCountedThreadSafe<StreamListenSocket>, |
52 #if defined(OS_WIN) | 54 #if defined(OS_WIN) |
53 public base::win::ObjectWatcher::Delegate { | 55 public base::win::ObjectWatcher::Delegate { |
54 #elif defined(OS_POSIX) | 56 #elif defined(OS_POSIX) |
55 public MessageLoopForIO::Watcher { | 57 public MessageLoopForIO::Watcher { |
56 #endif | 58 #endif |
57 | 59 |
58 public: | 60 public: |
59 // TODO(erikkay): this delegate should really be split into two parts | 61 // TODO(erikkay): this delegate should really be split into two parts |
(...skipping 12 matching lines...) Expand all Loading... |
72 virtual void DidClose(StreamListenSocket* sock) = 0; | 74 virtual void DidClose(StreamListenSocket* sock) = 0; |
73 | 75 |
74 protected: | 76 protected: |
75 virtual ~Delegate() {} | 77 virtual ~Delegate() {} |
76 }; | 78 }; |
77 | 79 |
78 // Send data to the socket. | 80 // Send data to the socket. |
79 void Send(const char* bytes, int len, bool append_linefeed = false); | 81 void Send(const char* bytes, int len, bool append_linefeed = false); |
80 void Send(const std::string& str, bool append_linefeed = false); | 82 void Send(const std::string& str, bool append_linefeed = false); |
81 | 83 |
| 84 // Copies the local address to |address|. Returns a network error code. |
| 85 int GetLocalAddress(IPEndPoint* address); |
| 86 |
82 static const SocketDescriptor kInvalidSocket; | 87 static const SocketDescriptor kInvalidSocket; |
83 static const int kSocketError; | 88 static const int kSocketError; |
84 | 89 |
85 protected: | 90 protected: |
86 enum WaitState { | 91 enum WaitState { |
87 NOT_WAITING = 0, | 92 NOT_WAITING = 0, |
88 WAITING_ACCEPT = 1, | 93 WAITING_ACCEPT = 1, |
89 WAITING_READ = 2 | 94 WAITING_READ = 2 |
90 }; | 95 }; |
91 | 96 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 virtual ~StreamListenSocketFactory() {} | 161 virtual ~StreamListenSocketFactory() {} |
157 | 162 |
158 // Returns a new instance of StreamListenSocket or NULL if an error occurred. | 163 // Returns a new instance of StreamListenSocket or NULL if an error occurred. |
159 virtual scoped_refptr<StreamListenSocket> CreateAndListen( | 164 virtual scoped_refptr<StreamListenSocket> CreateAndListen( |
160 StreamListenSocket::Delegate* delegate) const = 0; | 165 StreamListenSocket::Delegate* delegate) const = 0; |
161 }; | 166 }; |
162 | 167 |
163 } // namespace net | 168 } // namespace net |
164 | 169 |
165 #endif // NET_BASE_STREAM_LISTEN_SOCKET_H_ | 170 #endif // NET_BASE_STREAM_LISTEN_SOCKET_H_ |
OLD | NEW |