| Index: net/socket/tcp_client_socket_libevent.h
|
| ===================================================================
|
| --- net/socket/tcp_client_socket_libevent.h (revision 47718)
|
| +++ net/socket/tcp_client_socket_libevent.h (working copy)
|
| @@ -47,6 +47,13 @@
|
| virtual bool SetSendBufferSize(int32 size);
|
|
|
| private:
|
| + // State machine for connecting the socket.
|
| + enum ConnectState {
|
| + CONNECT_STATE_CONNECT,
|
| + CONNECT_STATE_CONNECT_COMPLETE,
|
| + CONNECT_STATE_NONE,
|
| + };
|
| +
|
| class ReadWatcher : public MessageLoopForIO::Watcher {
|
| public:
|
| explicit ReadWatcher(TCPClientSocketLibevent* socket) : socket_(socket) {}
|
| @@ -75,7 +82,7 @@
|
| virtual void OnFileCanReadWithoutBlocking(int /* fd */) {}
|
|
|
| virtual void OnFileCanWriteWithoutBlocking(int /* fd */) {
|
| - if (socket_->waiting_connect_) {
|
| + if (socket_->waiting_connect()) {
|
| socket_->DidCompleteConnect();
|
| } else if (socket_->write_callback_) {
|
| socket_->DidCompleteWrite();
|
| @@ -88,15 +95,28 @@
|
| DISALLOW_COPY_AND_ASSIGN(WriteWatcher);
|
| };
|
|
|
| - // Performs the actual connect(). Returns a net error code.
|
| + // State machine used by Connect().
|
| + int DoConnectLoop(int result);
|
| int DoConnect();
|
| + int DoConnectComplete(int result);
|
|
|
| + // Helper used by Disconnect(), which disconnects minus the logging and
|
| + // resetting of current_ai_.
|
| + void DoDisconnect();
|
| +
|
| +
|
| void DoReadCallback(int rv);
|
| void DoWriteCallback(int rv);
|
| void DidCompleteRead();
|
| void DidCompleteWrite();
|
| void DidCompleteConnect();
|
|
|
| + // Returns true if a Connect() is in progress.
|
| + bool waiting_connect() const {
|
| + return next_connect_state_ != CONNECT_STATE_NONE;
|
| + }
|
| +
|
| + // Returns the OS error code (or 0 on success).
|
| int CreateSocket(const struct addrinfo* ai);
|
|
|
| int socket_;
|
| @@ -107,9 +127,6 @@
|
| // Where we are in above list, or NULL if all addrinfos have been tried.
|
| const struct addrinfo* current_ai_;
|
|
|
| - // Whether we're currently waiting for connect() to complete
|
| - bool waiting_connect_;
|
| -
|
| // The socket's libevent wrappers
|
| MessageLoopForIO::FileDescriptorWatcher read_socket_watcher_;
|
| MessageLoopForIO::FileDescriptorWatcher write_socket_watcher_;
|
| @@ -132,6 +149,9 @@
|
| // External callback; called when write is complete.
|
| CompletionCallback* write_callback_;
|
|
|
| + // The next state for the Connect() state machine.
|
| + ConnectState next_connect_state_;
|
| +
|
| BoundNetLog net_log_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(TCPClientSocketLibevent);
|
|
|