Chromium Code Reviews| 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 // Abstract socket server that handles IO asynchronously in the specified | 5 // Abstract socket server that handles IO asynchronously in the specified |
| 6 // MessageLoop. | 6 // MessageLoop. |
| 7 | 7 |
| 8 #ifndef NET_BASE_LISTEN_SOCKET_H_ | 8 #ifndef NET_BASE_LISTEN_SOCKET_H_ |
| 9 #define NET_BASE_LISTEN_SOCKET_H_ | 9 #define NET_BASE_LISTEN_SOCKET_H_ |
| 10 #pragma once | 10 #pragma once |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 class NET_EXPORT ListenSocket | 22 class NET_EXPORT ListenSocket |
| 23 : public base::RefCountedThreadSafe<ListenSocket> { | 23 : public base::RefCountedThreadSafe<ListenSocket> { |
| 24 public: | 24 public: |
| 25 // TODO(erikkay): this delegate should really be split into two parts | 25 // TODO(erikkay): this delegate should really be split into two parts |
| 26 // to split up the listener from the connected socket. Perhaps this class | 26 // to split up the listener from the connected socket. Perhaps this class |
| 27 // should be split up similarly. | 27 // should be split up similarly. |
| 28 class ListenSocketDelegate { | 28 class ListenSocketDelegate { |
| 29 public: | 29 public: |
| 30 virtual ~ListenSocketDelegate() {} | 30 virtual ~ListenSocketDelegate() {} |
| 31 | 31 |
| 32 // server is the original listening Socket, connection is the new | 32 // server is the original listening Socket, connection is the new |
|
mmenke
2012/04/25 17:25:31
nit: |server|
Philippe
2012/04/30 06:55:21
Done. Note that this interface is now part of Stre
| |
| 33 // Socket that was created. Ownership of connection is transferred | 33 // Socket that was created. Ownership of connection is transferred |
| 34 // to the delegate with this call. | 34 // to the delegate with this call. |
| 35 virtual void DidAccept(ListenSocket *server, | 35 virtual void DidAccept(ListenSocket* server, |
| 36 ListenSocket *connection) = 0; | 36 ListenSocket* connection) = 0; |
| 37 virtual void DidRead(ListenSocket *connection, | 37 virtual void DidRead(ListenSocket* connection, |
| 38 const char* data, | 38 const char* data, |
| 39 int len) = 0; | 39 int len) = 0; |
| 40 virtual void DidClose(ListenSocket *sock) = 0; | 40 virtual void DidClose(ListenSocket* sock) = 0; |
| 41 }; | 41 }; |
| 42 | 42 |
| 43 // Send data to the socket. | 43 // Send data to the socket. |
| 44 void Send(const char* bytes, int len, bool append_linefeed = false); | 44 void Send(const char* bytes, int len, bool append_linefeed = false); |
| 45 void Send(const std::string& str, bool append_linefeed = false); | 45 void Send(const std::string& str, bool append_linefeed = false); |
| 46 | 46 |
| 47 protected: | 47 protected: |
| 48 ListenSocket(ListenSocketDelegate* del); | 48 ListenSocket(ListenSocketDelegate* del); |
| 49 virtual ~ListenSocket(); | 49 virtual ~ListenSocket(); |
| 50 | 50 |
| 51 virtual void SendInternal(const char* bytes, int len) = 0; | 51 virtual void SendInternal(const char* bytes, int len) = 0; |
| 52 | 52 |
| 53 ListenSocketDelegate* const socket_delegate_; | 53 ListenSocketDelegate* const socket_delegate_; |
| 54 | 54 |
| 55 private: | 55 private: |
| 56 friend class base::RefCountedThreadSafe<ListenSocket>; | 56 friend class base::RefCountedThreadSafe<ListenSocket>; |
| 57 | 57 |
| 58 DISALLOW_COPY_AND_ASSIGN(ListenSocket); | 58 DISALLOW_COPY_AND_ASSIGN(ListenSocket); |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 } // namespace net | 61 } // namespace net |
| 62 | 62 |
| 63 #endif // NET_BASE_LISTEN_SOCKET_H_ | 63 #endif // NET_BASE_LISTEN_SOCKET_H_ |
| OLD | NEW |