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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 | 65 |
66 protected: | 66 protected: |
67 virtual ~Delegate() {} | 67 virtual ~Delegate() {} |
68 }; | 68 }; |
69 | 69 |
70 // Send data to the socket. | 70 // Send data to the socket. |
71 void Send(const char* bytes, int len, bool append_linefeed = false); | 71 void Send(const char* bytes, int len, bool append_linefeed = false); |
72 void Send(const std::string& str, bool append_linefeed = false); | 72 void Send(const std::string& str, bool append_linefeed = false); |
73 | 73 |
74 // Copies the local address to |address|. Returns a network error code. | 74 // Copies the local address to |address|. Returns a network error code. |
75 int GetLocalAddress(IPEndPoint* address); | 75 // This method is virtual to support unit testing. |
| 76 virtual int GetLocalAddress(IPEndPoint* address); |
76 // Copies the peer address to |address|. Returns a network error code. | 77 // Copies the peer address to |address|. Returns a network error code. |
77 int GetPeerAddress(IPEndPoint* address); | 78 // This method is virtual to support unit testing. |
| 79 virtual int GetPeerAddress(IPEndPoint* address); |
78 | 80 |
79 static const int kSocketError; | 81 static const int kSocketError; |
80 | 82 |
81 protected: | 83 protected: |
82 enum WaitState { | 84 enum WaitState { |
83 NOT_WAITING = 0, | 85 NOT_WAITING = 0, |
84 WAITING_ACCEPT = 1, | 86 WAITING_ACCEPT = 1, |
85 WAITING_READ = 2 | 87 WAITING_READ = 2 |
86 }; | 88 }; |
87 | 89 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 virtual ~StreamListenSocketFactory() {} | 143 virtual ~StreamListenSocketFactory() {} |
142 | 144 |
143 // Returns a new instance of StreamListenSocket or NULL if an error occurred. | 145 // Returns a new instance of StreamListenSocket or NULL if an error occurred. |
144 virtual scoped_ptr<StreamListenSocket> CreateAndListen( | 146 virtual scoped_ptr<StreamListenSocket> CreateAndListen( |
145 StreamListenSocket::Delegate* delegate) const = 0; | 147 StreamListenSocket::Delegate* delegate) const = 0; |
146 }; | 148 }; |
147 | 149 |
148 } // namespace net | 150 } // namespace net |
149 | 151 |
150 #endif // NET_SOCKET_STREAM_LISTEN_SOCKET_H_ | 152 #endif // NET_SOCKET_STREAM_LISTEN_SOCKET_H_ |
OLD | NEW |