| Index: net/base/listen_socket.h
|
| ===================================================================
|
| --- net/base/listen_socket.h (revision 3911)
|
| +++ net/base/listen_socket.h (working copy)
|
| @@ -11,15 +11,33 @@
|
| #ifndef NET_BASE_SOCKET_H_
|
| #define NET_BASE_SOCKET_H_
|
|
|
| +#if defined(OS_WIN)
|
| +#include <winsock2.h>
|
| +#include "base/object_watcher.h"
|
| +#elif defined(OS_POSIX)
|
| +#include "base/message_loop.h"
|
| +#include "net/base/net_util.h"
|
| +#include "net/base/net_errors.h"
|
| +#include "third_party/libevent/event.h"
|
| +#include "base/message_pump_libevent.h"
|
| +#endif
|
| +
|
| #include "base/basictypes.h"
|
| -#include "base/object_watcher.h"
|
| #include "base/ref_counted.h"
|
|
|
| -#include <winsock2.h>
|
| +#if defined(OS_POSIX)
|
| +struct event; // From libevent
|
| +#define SOCKET int
|
| +#endif
|
|
|
| // Implements a raw socket interface
|
| class ListenSocket : public base::RefCountedThreadSafe<ListenSocket>,
|
| - public base::ObjectWatcher::Delegate {
|
| +#if defined(OS_WIN)
|
| + public base::ObjectWatcher::Delegate
|
| +#elif defined(OS_POSIX)
|
| + public base::MessagePumpLibevent::Watcher
|
| +#endif
|
| +{
|
| public:
|
| // TODO(erikkay): this delegate should really be split into two parts
|
| // to split up the listener from the connected socket. Perhaps this class
|
| @@ -52,19 +70,38 @@
|
|
|
| virtual void SendInternal(const char* bytes, int len);
|
|
|
| - // ObjectWatcher delegate
|
| - virtual void OnObjectSignaled(HANDLE object);
|
| -
|
| virtual void Listen();
|
| virtual void Accept();
|
| virtual void Read();
|
| virtual void Close();
|
| + virtual void CloseSocket(SOCKET s);
|
|
|
| - SOCKET socket_;
|
| + enum WaitState {
|
| + NOT_WAITING = 0,
|
| + WAITING_ACCEPT = 1,
|
| + WAITING_READ = 3,
|
| + WAITING_CLOSE = 4
|
| + };
|
| + // Pass any value in case of Windows, because in Windows
|
| + // we are not using state.
|
| + void WatchSocket(WaitState state);
|
| + void UnwatchSocket();
|
| +
|
| +#if defined(OS_WIN)
|
| + // ObjectWatcher delegate
|
| + virtual void OnObjectSignaled(HANDLE object);
|
| + base::ObjectWatcher watcher_;
|
| HANDLE socket_event_;
|
| +#elif defined(OS_POSIX)
|
| + WaitState wait_state_;
|
| + // The socket's libevent wrapper
|
| + scoped_ptr<event> event_;
|
| + // Called by MessagePumpLibevent when the socket is ready to do I/O
|
| + void OnSocketReady(short flags);
|
| +#endif
|
| +
|
| + SOCKET socket_;
|
| ListenSocketDelegate *socket_delegate_;
|
| -
|
| - base::ObjectWatcher watcher_;
|
|
|
| private:
|
| DISALLOW_EVIL_CONSTRUCTORS(ListenSocket);
|
|
|