| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 #ifndef NET_SOCKET_TCP_CLIENT_SOCKET_LIBEVENT_H_ | 5 #ifndef NET_SOCKET_TCP_CLIENT_SOCKET_LIBEVENT_H_ |
| 6 #define NET_SOCKET_TCP_CLIENT_SOCKET_LIBEVENT_H_ | 6 #define NET_SOCKET_TCP_CLIENT_SOCKET_LIBEVENT_H_ |
| 7 | 7 |
| 8 #include <sys/socket.h> // for struct sockaddr | 8 #include <sys/socket.h> // for struct sockaddr |
| 9 | 9 |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/ref_counted.h" | 11 #include "base/ref_counted.h" |
| 12 #include "base/scoped_ptr.h" | 12 #include "base/scoped_ptr.h" |
| 13 #include "net/base/address_list.h" | 13 #include "net/base/address_list.h" |
| 14 #include "net/base/completion_callback.h" | 14 #include "net/base/completion_callback.h" |
| 15 #include "net/socket/client_socket.h" | 15 #include "net/socket/client_socket.h" |
| 16 | 16 |
| 17 struct event; // From libevent | 17 struct event; // From libevent |
| 18 | 18 |
| 19 namespace net { | 19 namespace net { |
| 20 | 20 |
| 21 class LoadLog; |
| 22 |
| 21 // A client socket that uses TCP as the transport layer. | 23 // A client socket that uses TCP as the transport layer. |
| 22 class TCPClientSocketLibevent : public ClientSocket { | 24 class TCPClientSocketLibevent : public ClientSocket { |
| 23 public: | 25 public: |
| 24 // The IP address(es) and port number to connect to. The TCP socket will try | 26 // The IP address(es) and port number to connect to. The TCP socket will try |
| 25 // each IP address in the list until it succeeds in establishing a | 27 // each IP address in the list until it succeeds in establishing a |
| 26 // connection. | 28 // connection. |
| 27 explicit TCPClientSocketLibevent(const AddressList& addresses); | 29 explicit TCPClientSocketLibevent(const AddressList& addresses); |
| 28 | 30 |
| 29 virtual ~TCPClientSocketLibevent(); | 31 virtual ~TCPClientSocketLibevent(); |
| 30 | 32 |
| 31 // ClientSocket methods: | 33 // ClientSocket methods: |
| 32 virtual int Connect(CompletionCallback* callback); | 34 virtual int Connect(CompletionCallback* callback, LoadLog* load_log); |
| 33 virtual void Disconnect(); | 35 virtual void Disconnect(); |
| 34 virtual bool IsConnected() const; | 36 virtual bool IsConnected() const; |
| 35 virtual bool IsConnectedAndIdle() const; | 37 virtual bool IsConnectedAndIdle() const; |
| 36 virtual int GetPeerName(struct sockaddr *name, socklen_t *namelen); | 38 virtual int GetPeerName(struct sockaddr *name, socklen_t *namelen); |
| 37 | 39 |
| 38 // Socket methods: | 40 // Socket methods: |
| 39 // Multiple outstanding requests are not supported. | 41 // Multiple outstanding requests are not supported. |
| 40 // Full duplex mode (reading and writing at the same time) is supported | 42 // Full duplex mode (reading and writing at the same time) is supported |
| 41 virtual int Read(IOBuffer* buf, int buf_len, CompletionCallback* callback); | 43 virtual int Read(IOBuffer* buf, int buf_len, CompletionCallback* callback); |
| 42 virtual int Write(IOBuffer* buf, int buf_len, CompletionCallback* callback); | 44 virtual int Write(IOBuffer* buf, int buf_len, CompletionCallback* callback); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 socket_->DidCompleteWrite(); | 80 socket_->DidCompleteWrite(); |
| 79 } | 81 } |
| 80 } | 82 } |
| 81 | 83 |
| 82 private: | 84 private: |
| 83 TCPClientSocketLibevent* const socket_; | 85 TCPClientSocketLibevent* const socket_; |
| 84 | 86 |
| 85 DISALLOW_COPY_AND_ASSIGN(WriteWatcher); | 87 DISALLOW_COPY_AND_ASSIGN(WriteWatcher); |
| 86 }; | 88 }; |
| 87 | 89 |
| 90 // Performs the actual connect(). Returns a net error code. |
| 91 int DoConnect(); |
| 92 |
| 88 void DoReadCallback(int rv); | 93 void DoReadCallback(int rv); |
| 89 void DoWriteCallback(int rv); | 94 void DoWriteCallback(int rv); |
| 90 void DidCompleteRead(); | 95 void DidCompleteRead(); |
| 91 void DidCompleteWrite(); | 96 void DidCompleteWrite(); |
| 92 void DidCompleteConnect(); | 97 void DidCompleteConnect(); |
| 93 | 98 |
| 94 int CreateSocket(const struct addrinfo* ai); | 99 int CreateSocket(const struct addrinfo* ai); |
| 95 | 100 |
| 96 int socket_; | 101 int socket_; |
| 97 | 102 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 119 // The buffer used by OnSocketReady to retry Write requests | 124 // The buffer used by OnSocketReady to retry Write requests |
| 120 scoped_refptr<IOBuffer> write_buf_; | 125 scoped_refptr<IOBuffer> write_buf_; |
| 121 int write_buf_len_; | 126 int write_buf_len_; |
| 122 | 127 |
| 123 // External callback; called when read is complete. | 128 // External callback; called when read is complete. |
| 124 CompletionCallback* read_callback_; | 129 CompletionCallback* read_callback_; |
| 125 | 130 |
| 126 // External callback; called when write is complete. | 131 // External callback; called when write is complete. |
| 127 CompletionCallback* write_callback_; | 132 CompletionCallback* write_callback_; |
| 128 | 133 |
| 134 scoped_refptr<LoadLog> load_log_; |
| 135 |
| 129 DISALLOW_COPY_AND_ASSIGN(TCPClientSocketLibevent); | 136 DISALLOW_COPY_AND_ASSIGN(TCPClientSocketLibevent); |
| 130 }; | 137 }; |
| 131 | 138 |
| 132 } // namespace net | 139 } // namespace net |
| 133 | 140 |
| 134 #endif // NET_SOCKET_TCP_CLIENT_SOCKET_LIBEVENT_H_ | 141 #endif // NET_SOCKET_TCP_CLIENT_SOCKET_LIBEVENT_H_ |
| OLD | NEW |