| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef NET_BASE_TCP_CLIENT_SOCKET_WIN_H_ | |
| 6 #define NET_BASE_TCP_CLIENT_SOCKET_WIN_H_ | |
| 7 | |
| 8 #include <ws2tcpip.h> | |
| 9 | |
| 10 #include "base/object_watcher.h" | |
| 11 #include "net/base/address_list.h" | |
| 12 #include "net/base/client_socket.h" | |
| 13 #include "net/base/completion_callback.h" | |
| 14 | |
| 15 namespace net { | |
| 16 | |
| 17 class TCPClientSocketWin : public ClientSocket { | |
| 18 public: | |
| 19 // The IP address(es) and port number to connect to. The TCP socket will try | |
| 20 // each IP address in the list until it succeeds in establishing a | |
| 21 // connection. | |
| 22 explicit TCPClientSocketWin(const AddressList& addresses); | |
| 23 | |
| 24 ~TCPClientSocketWin(); | |
| 25 | |
| 26 // ClientSocket methods: | |
| 27 virtual int Connect(CompletionCallback* callback); | |
| 28 virtual void Disconnect(); | |
| 29 virtual bool IsConnected() const; | |
| 30 virtual bool IsConnectedAndIdle() const; | |
| 31 | |
| 32 // Socket methods: | |
| 33 // Multiple outstanding requests are not supported. | |
| 34 // Full duplex mode (reading and writing at the same time) is supported | |
| 35 virtual int Read(IOBuffer* buf, int buf_len, CompletionCallback* callback); | |
| 36 virtual int Write(IOBuffer* buf, int buf_len, CompletionCallback* callback); | |
| 37 | |
| 38 private: | |
| 39 class Core; | |
| 40 | |
| 41 int CreateSocket(const struct addrinfo* ai); | |
| 42 void DoReadCallback(int rv); | |
| 43 void DoWriteCallback(int rv); | |
| 44 void DidCompleteConnect(); | |
| 45 void DidCompleteRead(); | |
| 46 void DidCompleteWrite(); | |
| 47 | |
| 48 SOCKET socket_; | |
| 49 | |
| 50 // The list of addresses we should try in order to establish a connection. | |
| 51 AddressList addresses_; | |
| 52 | |
| 53 // Where we are in above list, or NULL if all addrinfos have been tried. | |
| 54 const struct addrinfo* current_ai_; | |
| 55 | |
| 56 // The various states that the socket could be in. | |
| 57 bool waiting_connect_; | |
| 58 bool waiting_read_; | |
| 59 bool waiting_write_; | |
| 60 | |
| 61 // The core of the socket that can live longer than the socket itself. We pass | |
| 62 // resources to the Windows async IO functions and we have to make sure that | |
| 63 // they are not destroyed while the OS still references them. | |
| 64 scoped_refptr<Core> core_; | |
| 65 | |
| 66 // External callback; called when connect or read is complete. | |
| 67 CompletionCallback* read_callback_; | |
| 68 | |
| 69 // External callback; called when write is complete. | |
| 70 CompletionCallback* write_callback_; | |
| 71 | |
| 72 DISALLOW_COPY_AND_ASSIGN(TCPClientSocketWin); | |
| 73 }; | |
| 74 | |
| 75 } // namespace net | |
| 76 | |
| 77 #endif // NET_BASE_TCP_CLIENT_SOCKET_WIN_H_ | |
| OLD | NEW |