| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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, const std::string& data) = 0; |
| 55 virtual void DidClose(ListenSocket *sock) = 0; | 55 virtual void DidClose(ListenSocket *sock) = 0; |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 // Listen on port for the specified IP address. Use 127.0.0.1 to only | 58 // Listen on port for the specified IP address. Use 127.0.0.1 to only |
| 59 // accept local connections. | 59 // accept local connections. |
| 60 static ListenSocket* Listen(std::string ip, int port, | 60 static ListenSocket* Listen(std::string ip, int port, |
| 61 ListenSocketDelegate* del); | 61 ListenSocketDelegate* del); |
| 62 virtual ~ListenSocket(); | |
| 63 | 62 |
| 64 // Send data to the socket. | 63 // Send data to the socket. |
| 65 void Send(const char* bytes, int len, bool append_linefeed = false); | 64 void Send(const char* bytes, int len, bool append_linefeed = false); |
| 66 void Send(const std::string& str, bool append_linefeed = false); | 65 void Send(const std::string& str, bool append_linefeed = false); |
| 67 | 66 |
| 68 // NOTE: This is for unit test use only! | 67 // NOTE: This is for unit test use only! |
| 69 // Pause/Resume calling Read(). Note that ResumeReads() will also call | 68 // Pause/Resume calling Read(). Note that ResumeReads() will also call |
| 70 // Read() if there is anything to read. | 69 // Read() if there is anything to read. |
| 71 void PauseReads(); | 70 void PauseReads(); |
| 72 void ResumeReads(); | 71 void ResumeReads(); |
| 73 | 72 |
| 74 protected: | 73 protected: |
| 74 friend class base::RefCountedThreadSafe<ListenSocket>; |
| 75 |
| 75 static const SOCKET kInvalidSocket; | 76 static const SOCKET kInvalidSocket; |
| 76 static const int kSocketError; | 77 static const int kSocketError; |
| 77 | 78 |
| 78 ListenSocket(SOCKET s, ListenSocketDelegate* del); | 79 ListenSocket(SOCKET s, ListenSocketDelegate* del); |
| 80 virtual ~ListenSocket(); |
| 79 static SOCKET Listen(std::string ip, int port); | 81 static SOCKET Listen(std::string ip, int port); |
| 80 // if valid, returned SOCKET is non-blocking | 82 // if valid, returned SOCKET is non-blocking |
| 81 static SOCKET Accept(SOCKET s); | 83 static SOCKET Accept(SOCKET s); |
| 82 | 84 |
| 83 virtual void SendInternal(const char* bytes, int len); | 85 virtual void SendInternal(const char* bytes, int len); |
| 84 | 86 |
| 85 virtual void Listen(); | 87 virtual void Listen(); |
| 86 virtual void Accept(); | 88 virtual void Accept(); |
| 87 virtual void Read(); | 89 virtual void Read(); |
| 88 virtual void Close(); | 90 virtual void Close(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 117 ListenSocketDelegate *socket_delegate_; | 119 ListenSocketDelegate *socket_delegate_; |
| 118 | 120 |
| 119 private: | 121 private: |
| 120 bool reads_paused_; | 122 bool reads_paused_; |
| 121 bool has_pending_reads_; | 123 bool has_pending_reads_; |
| 122 | 124 |
| 123 DISALLOW_COPY_AND_ASSIGN(ListenSocket); | 125 DISALLOW_COPY_AND_ASSIGN(ListenSocket); |
| 124 }; | 126 }; |
| 125 | 127 |
| 126 #endif // NET_BASE_LISTEN_SOCKET_H_ | 128 #endif // NET_BASE_LISTEN_SOCKET_H_ |
| OLD | NEW |