Index: net/base/tcp_client_socket.h |
=================================================================== |
--- net/base/tcp_client_socket.h (revision 2108) |
+++ net/base/tcp_client_socket.h (working copy) |
@@ -5,20 +5,32 @@ |
#ifndef NET_BASE_TCP_CLIENT_SOCKET_H_ |
#define NET_BASE_TCP_CLIENT_SOCKET_H_ |
+#if defined(OS_WIN) |
#include <ws2tcpip.h> |
- |
#include "base/object_watcher.h" |
+#endif |
#include "net/base/address_list.h" |
#include "net/base/client_socket.h" |
+#if defined(OS_LINUX) |
+// From libevent. (Why did they pick such a generic name?) |
+struct event; |
+ |
+// The callback we pass to libevent for everything |
+extern "C" void TCPClientSocket_libevent_cb(int socket, short flags, void *context); |
+#endif |
+ |
namespace net { |
// A client socket that uses TCP as the transport layer. |
// |
// NOTE: The implementation supports half duplex only. Read and Write calls |
// must not be in progress at the same time. |
-class TCPClientSocket : public ClientSocket, |
- public base::ObjectWatcher::Delegate { |
+class TCPClientSocket : public ClientSocket |
+#ifdef OS_WIN |
+ , public base::ObjectWatcher::Delegate |
+#endif |
+{ |
public: |
// The IP address(es) and port number to connect to. The TCP socket will try |
// each IP address in the list until it succeeds in establishing a |
@@ -34,6 +46,11 @@ |
virtual bool IsConnected() const; |
// Socket methods: |
+ // Try to transfer buf_len bytes to/from socket. |
+ // If a result is available immediately, return it; otherwise call back later with the result. |
+ // If any bytes were transferred, the result is the byte count. |
+ // If there was an error, the result is a negative error code; see net/base/net_error_list.h |
+ // TODO: what would a zero return value indicate? |
virtual int Read(char* buf, int buf_len, CompletionCallback* callback); |
virtual int Write(const char* buf, int buf_len, CompletionCallback* callback); |
@@ -43,6 +60,7 @@ |
void DidCompleteConnect(); |
void DidCompleteIO(); |
+#ifdef OS_WIN |
// base::ObjectWatcher::Delegate methods: |
virtual void OnObjectSignaled(HANDLE object); |
@@ -51,7 +69,18 @@ |
WSABUF buffer_; |
base::ObjectWatcher watcher_; |
+#else |
+ friend void ::TCPClientSocket_libevent_cb(int socket, short flags, void *context); |
+public: // FIXME: friend isn't working, so make these public |
+ void OnLibeventNotification(short flags); |
+ int socket_; |
+private: |
+ ::event* event_; |
+ char *buf_; |
+ int buf_len_; |
+#endif |
+ |
CompletionCallback* callback_; |
// The list of addresses we should try in order to establish a connection. |