OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 // TCP/IP server that handles IO asynchronously in the specified MessageLoop. | 5 // TCP/IP server that handles IO asynchronously in the specified MessageLoop. |
6 // These objects are NOT thread safe. They use WSAEVENT handles to monitor | 6 // These objects are NOT thread safe. They use WSAEVENT handles to monitor |
7 // activity in a given MessageLoop. This means that callbacks will | 7 // activity in a given MessageLoop. This means that callbacks will |
8 // happen in that loop's thread always and that all other methods (including | 8 // happen in that loop's thread always and that all other methods (including |
9 // constructors and destructors) should also be called from the same thread. | 9 // constructors and destructors) should also be called from the same thread. |
10 | 10 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 // to split up the listener from the connected socket. Perhaps this class | 44 // to split up the listener from the connected socket. Perhaps this class |
45 // should be split up similarly. | 45 // should be split up similarly. |
46 class ListenSocketDelegate { | 46 class ListenSocketDelegate { |
47 public: | 47 public: |
48 virtual ~ListenSocketDelegate() {} | 48 virtual ~ListenSocketDelegate() {} |
49 | 49 |
50 // server is the original listening Socket, connection is the new | 50 // server is the original listening Socket, connection is the new |
51 // Socket that was created. Ownership of connection is transferred | 51 // Socket that was created. Ownership of connection is transferred |
52 // to the delegate with this call. | 52 // to the delegate with this call. |
53 virtual void DidAccept(ListenSocket *server, ListenSocket *connection) = 0; | 53 virtual void DidAccept(ListenSocket *server, ListenSocket *connection) = 0; |
54 virtual void DidRead(ListenSocket *connection, const std::string& data) = 0; | 54 virtual void DidRead(ListenSocket *connection, |
| 55 const char* data, |
| 56 int len) = 0; |
55 virtual void DidClose(ListenSocket *sock) = 0; | 57 virtual void DidClose(ListenSocket *sock) = 0; |
56 }; | 58 }; |
57 | 59 |
58 // Listen on port for the specified IP address. Use 127.0.0.1 to only | 60 // Listen on port for the specified IP address. Use 127.0.0.1 to only |
59 // accept local connections. | 61 // accept local connections. |
60 static ListenSocket* Listen(std::string ip, int port, | 62 static ListenSocket* Listen(std::string ip, int port, |
61 ListenSocketDelegate* del); | 63 ListenSocketDelegate* del); |
62 | 64 |
63 // Send data to the socket. | 65 // Send data to the socket. |
64 void Send(const char* bytes, int len, bool append_linefeed = false); | 66 void Send(const char* bytes, int len, bool append_linefeed = false); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 ListenSocketDelegate *socket_delegate_; | 121 ListenSocketDelegate *socket_delegate_; |
120 | 122 |
121 private: | 123 private: |
122 bool reads_paused_; | 124 bool reads_paused_; |
123 bool has_pending_reads_; | 125 bool has_pending_reads_; |
124 | 126 |
125 DISALLOW_COPY_AND_ASSIGN(ListenSocket); | 127 DISALLOW_COPY_AND_ASSIGN(ListenSocket); |
126 }; | 128 }; |
127 | 129 |
128 #endif // NET_BASE_LISTEN_SOCKET_H_ | 130 #endif // NET_BASE_LISTEN_SOCKET_H_ |
OLD | NEW |