OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 13 matching lines...) Expand all Loading... |
24 // TODO(erikkay): this delegate should really be split into two parts | 24 // TODO(erikkay): this delegate should really be split into two parts |
25 // to split up the listener from the connected socket. Perhaps this class | 25 // to split up the listener from the connected socket. Perhaps this class |
26 // should be split up similarly. | 26 // should be split up similarly. |
27 class ListenSocketDelegate { | 27 class ListenSocketDelegate { |
28 public: | 28 public: |
29 virtual ~ListenSocketDelegate() {} | 29 virtual ~ListenSocketDelegate() {} |
30 | 30 |
31 // server is the original listening Socket, connection is the new | 31 // server is the original listening Socket, connection is the new |
32 // Socket that was created. Ownership of connection is transferred | 32 // Socket that was created. Ownership of connection is transferred |
33 // to the delegate with this call. | 33 // to the delegate with this call. |
34 virtual void DidAccept(ListenSocket *server, | 34 virtual void DidAccept(ListenSocket* server, |
35 ListenSocket *connection) = 0; | 35 ListenSocket* connection) = 0; |
36 virtual void DidRead(ListenSocket *connection, | 36 virtual void DidRead(ListenSocket* connection, |
37 const char* data, | 37 const char* data, |
38 int len) = 0; | 38 int len) = 0; |
39 virtual void DidClose(ListenSocket *sock) = 0; | 39 virtual void DidClose(ListenSocket* sock) = 0; |
40 }; | 40 }; |
41 | 41 |
42 // Send data to the socket. | 42 // Send data to the socket. |
43 void Send(const char* bytes, int len, bool append_linefeed = false) { | 43 void Send(const char* bytes, int len, bool append_linefeed = false) { |
44 SendInternal(bytes, len); | 44 SendInternal(bytes, len); |
45 if (append_linefeed) SendInternal("\r\n", 2); | 45 if (append_linefeed) SendInternal("\r\n", 2); |
46 } | 46 } |
47 | 47 |
48 void Send(const std::string& str, bool append_linefeed = false) { | 48 void Send(const std::string& str, bool append_linefeed = false) { |
49 Send(str.data(), static_cast<int>(str.length()), append_linefeed); | 49 Send(str.data(), static_cast<int>(str.length()), append_linefeed); |
50 } | 50 } |
51 | 51 |
52 protected: | 52 protected: |
53 friend class base::RefCountedThreadSafe<ListenSocket>; | 53 friend class base::RefCountedThreadSafe<ListenSocket>; |
54 | 54 |
55 ListenSocket(ListenSocketDelegate *del) : socket_delegate_(del) {} | 55 ListenSocket(ListenSocketDelegate* del); |
56 virtual ~ListenSocket() {} | 56 virtual ~ListenSocket(); |
57 | 57 |
58 virtual void SendInternal(const char* bytes, int len) = 0; | 58 virtual void SendInternal(const char* bytes, int len) = 0; |
59 | 59 |
60 ListenSocketDelegate *socket_delegate_; | 60 ListenSocketDelegate* const socket_delegate_; |
61 | 61 |
62 private: | 62 private: |
63 DISALLOW_COPY_AND_ASSIGN(ListenSocket); | 63 DISALLOW_COPY_AND_ASSIGN(ListenSocket); |
64 }; | 64 }; |
65 | 65 |
66 } // namespace net | 66 } // namespace net |
67 | 67 |
68 #endif // NET_BASE_LISTEN_SOCKET_H_ | 68 #endif // NET_BASE_LISTEN_SOCKET_H_ |
OLD | NEW |