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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 #elif defined(OS_POSIX) | 53 #elif defined(OS_POSIX) |
54 public MessageLoopForIO::Watcher { | 54 public MessageLoopForIO::Watcher { |
55 #endif | 55 #endif |
56 | 56 |
57 public: | 57 public: |
58 // TODO(erikkay): this delegate should really be split into two parts | 58 // TODO(erikkay): this delegate should really be split into two parts |
59 // to split up the listener from the connected socket. Perhaps this class | 59 // to split up the listener from the connected socket. Perhaps this class |
60 // should be split up similarly. | 60 // should be split up similarly. |
61 class Delegate { | 61 class Delegate { |
62 public: | 62 public: |
63 virtual ~Delegate() {} | |
64 | |
65 // |server| is the original listening Socket, connection is the new | 63 // |server| is the original listening Socket, connection is the new |
66 // Socket that was created. Ownership of |connection| is transferred | 64 // Socket that was created. Ownership of |connection| is transferred |
67 // to the delegate with this call. | 65 // to the delegate with this call. |
68 virtual void DidAccept(StreamListenSocket* server, | 66 virtual void DidAccept(StreamListenSocket* server, |
69 StreamListenSocket* connection) = 0; | 67 StreamListenSocket* connection) = 0; |
70 virtual void DidRead(StreamListenSocket* connection, | 68 virtual void DidRead(StreamListenSocket* connection, |
71 const char* data, | 69 const char* data, |
72 int len) = 0; | 70 int len) = 0; |
73 virtual void DidClose(StreamListenSocket* sock) = 0; | 71 virtual void DidClose(StreamListenSocket* sock) = 0; |
| 72 |
| 73 protected: |
| 74 virtual ~Delegate() {} |
74 }; | 75 }; |
75 | 76 |
76 // Send data to the socket. | 77 // Send data to the socket. |
77 void Send(const char* bytes, int len, bool append_linefeed = false); | 78 void Send(const char* bytes, int len, bool append_linefeed = false); |
78 void Send(const std::string& str, bool append_linefeed = false); | 79 void Send(const std::string& str, bool append_linefeed = false); |
79 | 80 |
80 protected: | 81 protected: |
81 enum WaitState { | 82 enum WaitState { |
82 NOT_WAITING = 0, | 83 NOT_WAITING = 0, |
83 WAITING_ACCEPT = 1, | 84 WAITING_ACCEPT = 1, |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 virtual ~StreamListenSocketFactory() {} | 155 virtual ~StreamListenSocketFactory() {} |
155 | 156 |
156 // Returns a new instance of StreamListenSocket or NULL if an error occurred. | 157 // Returns a new instance of StreamListenSocket or NULL if an error occurred. |
157 virtual scoped_refptr<StreamListenSocket> CreateAndListen( | 158 virtual scoped_refptr<StreamListenSocket> CreateAndListen( |
158 StreamListenSocket::Delegate* delegate) const = 0; | 159 StreamListenSocket::Delegate* delegate) const = 0; |
159 }; | 160 }; |
160 | 161 |
161 } // namespace net | 162 } // namespace net |
162 | 163 |
163 #endif // NET_BASE_STREAM_LISTEN_SOCKET_H_ | 164 #endif // NET_BASE_STREAM_LISTEN_SOCKET_H_ |
OLD | NEW |