summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorojan@google.com <ojan@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-12 19:55:17 +0000
committerojan@google.com <ojan@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-12 19:55:17 +0000
commit900342a3e34354312a2ce854196e95fa8a0c07c4 (patch)
tree8d73bce7518e4077c805053cb553ef11b3b1949d /net
parentab844167875b2003cb44081c6b64c0097df30b48 (diff)
downloadchromium_src-900342a3e34354312a2ce854196e95fa8a0c07c4.zip
chromium_src-900342a3e34354312a2ce854196e95fa8a0c07c4.tar.gz
chromium_src-900342a3e34354312a2ce854196e95fa8a0c07c4.tar.bz2
Reverting 6911.
Review URL: http://codereview.chromium.org/14068 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6916 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/base/listen_socket.cc23
-rw-r--r--net/base/listen_socket.h23
-rw-r--r--net/base/tcp_client_socket.h13
-rw-r--r--net/base/tcp_client_socket_libevent.cc39
4 files changed, 47 insertions, 51 deletions
diff --git a/net/base/listen_socket.cc b/net/base/listen_socket.cc
index b2185a2..8428e06 100644
--- a/net/base/listen_socket.cc
+++ b/net/base/listen_socket.cc
@@ -12,6 +12,7 @@
#include <errno.h>
#include <sys/socket.h>
#include <arpa/inet.h>
+#include "base/message_loop.h"
#include "net/base/net_errors.h"
#include "third_party/libevent/event.h"
#endif
@@ -29,7 +30,12 @@ const int SOCKET_ERROR = -1;
const int kReadBufSize = 200;
ListenSocket::ListenSocket(SOCKET s, ListenSocketDelegate *del)
+#if defined(OS_WIN)
: socket_(s),
+#elif defined(OS_POSIX)
+ : event_(new event),
+ socket_(s),
+#endif
socket_delegate_(del) {
#if defined(OS_WIN)
socket_event_ = WSACreateEvent();
@@ -171,7 +177,8 @@ void ListenSocket::UnwatchSocket() {
#if defined(OS_WIN)
watcher_.StopWatching();
#elif defined(OS_POSIX)
- watcher_.StopWatchingFileDescriptor();
+ MessageLoopForIO::current()->UnwatchSocket(event_.get());
+ wait_state_ = NOT_WAITING;
#endif
}
@@ -180,9 +187,8 @@ void ListenSocket::WatchSocket(WaitState state) {
WSAEventSelect(socket_, socket_event_, FD_ACCEPT | FD_CLOSE | FD_READ);
watcher_.StartWatching(socket_event_, this);
#elif defined(OS_POSIX)
- // Implicitly calls StartWatchingFileDescriptor().
- MessageLoopForIO::current()->WatchFileDescriptor(
- socket_, true, MessageLoopForIO::WATCH_READ, &watcher_, this);
+ MessageLoopForIO::current()->WatchSocket(
+ socket_, EV_READ|EV_PERSIST, event_.get(),this);
wait_state_ = state;
#endif
}
@@ -244,7 +250,7 @@ void ListenSocket::OnObjectSignaled(HANDLE object) {
}
}
#elif defined(OS_POSIX)
-void ListenSocket::OnFileCanReadWithoutBlocking(int fd) {
+void ListenSocket::OnSocketReady(short flags) {
if (wait_state_ == WAITING_ACCEPT) {
Accept();
}
@@ -256,11 +262,4 @@ void ListenSocket::OnFileCanReadWithoutBlocking(int fd) {
// TODO(erikkay): this seems to get hit multiple times after the close
}
}
-
-void ListenSocket::OnFileCanWriteWithoutBlocking(int fd) {
- // MessagePumpLibevent callback, we don't listen for write events
- // so we shouldn't ever reach here.
- NOTREACHED();
-}
-
#endif
diff --git a/net/base/listen_socket.h b/net/base/listen_socket.h
index f5f8977..2b32b5b 100644
--- a/net/base/listen_socket.h
+++ b/net/base/listen_socket.h
@@ -11,7 +11,6 @@
#ifndef NET_BASE_SOCKET_H_
#define NET_BASE_SOCKET_H_
-#include <string>
#if defined(OS_WIN)
#include <winsock2.h>
#include "base/object_watcher.h"
@@ -19,6 +18,8 @@
#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"
@@ -34,7 +35,7 @@ class ListenSocket : public base::RefCountedThreadSafe<ListenSocket>,
#if defined(OS_WIN)
public base::ObjectWatcher::Delegate
#elif defined(OS_POSIX)
- public MessageLoopForIO::Watcher
+ public base::MessagePumpLibevent::Watcher
#endif
{
public:
@@ -79,11 +80,11 @@ class ListenSocket : public base::RefCountedThreadSafe<ListenSocket>,
NOT_WAITING = 0,
WAITING_ACCEPT = 1,
WAITING_READ = 3,
- WAITING_CLOSE = 4
+ WAITING_CLOSE = 4
};
- // Pass any value in case of Windows, because in Windows
- // we are not using state.
- void WatchSocket(WaitState state);
+ // 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)
@@ -94,17 +95,17 @@ class ListenSocket : public base::RefCountedThreadSafe<ListenSocket>,
#elif defined(OS_POSIX)
WaitState wait_state_;
// The socket's libevent wrapper
- MessageLoopForIO::FileDescriptorWatcher watcher_;
+ scoped_ptr<event> event_;
// Called by MessagePumpLibevent when the socket is ready to do I/O
- void OnFileCanReadWithoutBlocking(int fd);
- void OnFileCanWriteWithoutBlocking(int fd);
+ void OnSocketReady(short flags);
#endif
- SOCKET socket_;
+ SOCKET socket_;
ListenSocketDelegate *socket_delegate_;
private:
DISALLOW_EVIL_CONSTRUCTORS(ListenSocket);
};
-#endif // NET_BASE_SOCKET_H_
+#endif // NET_BASE_SOCKET_H_
+
diff --git a/net/base/tcp_client_socket.h b/net/base/tcp_client_socket.h
index 5fca519..05a433e 100644
--- a/net/base/tcp_client_socket.h
+++ b/net/base/tcp_client_socket.h
@@ -14,7 +14,7 @@
struct event; // From libevent
#include <sys/socket.h> // for struct sockaddr
#define SOCKET int
-#include "base/message_loop.h"
+#include "base/message_pump_libevent.h"
#endif
#include "base/scoped_ptr.h"
@@ -26,7 +26,7 @@ namespace net {
// A client socket that uses TCP as the transport layer.
//
-// NOTE: The windows implementation supports half duplex only.
+// NOTE: The windows implementation supports half duplex only.
// Read and Write calls must not be in progress at the same time.
// The libevent implementation supports full duplex because that
// made it slightly easier to implement ssl.
@@ -34,7 +34,7 @@ class TCPClientSocket : public ClientSocket,
#if defined(OS_WIN)
public base::ObjectWatcher::Delegate
#elif defined(OS_POSIX)
- public MessageLoopForIO::Watcher
+ public base::MessagePumpLibevent::Watcher
#endif
{
public:
@@ -52,7 +52,7 @@ class TCPClientSocket : public ClientSocket,
virtual bool IsConnected() const;
// Socket methods:
- // Multiple outstanding requests are not supported.
+ // Multiple outstanding requests are not supported.
// Full duplex mode (reading and writing at the same time) is not supported
// on Windows (but is supported on Linux and Mac for ease of implementation
// of SSLClientSocket)
@@ -97,11 +97,10 @@ class TCPClientSocket : public ClientSocket,
bool waiting_connect_;
// The socket's libevent wrapper
- MessageLoopForIO::FileDescriptorWatcher socket_watcher_;
+ scoped_ptr<event> event_;
// Called by MessagePumpLibevent when the socket is ready to do I/O
- void OnFileCanReadWithoutBlocking(int fd);
- void OnFileCanWriteWithoutBlocking(int fd);
+ void OnSocketReady(short flags);
// The buffer used by OnSocketReady to retry Read requests
char* buf_;
diff --git a/net/base/tcp_client_socket_libevent.cc b/net/base/tcp_client_socket_libevent.cc
index 933e95b..79909c20 100644
--- a/net/base/tcp_client_socket_libevent.cc
+++ b/net/base/tcp_client_socket_libevent.cc
@@ -68,6 +68,7 @@ TCPClientSocket::TCPClientSocket(const AddressList& addresses)
addresses_(addresses),
current_ai_(addresses_.head()),
waiting_connect_(false),
+ event_(new event),
write_callback_(NULL),
callback_(NULL) {
}
@@ -109,8 +110,8 @@ int TCPClientSocket::Connect(CompletionCallback* callback) {
// POLLOUT is set if the connection is established.
// POLLIN is set if the connection fails,
// so select for both read and write.
- MessageLoopForIO::current()->WatchFileDescriptor(
- socket_, true, MessageLoopForIO::WATCH_READ_WRITE, &socket_watcher_, this);
+ MessageLoopForIO::current()->WatchSocket(
+ socket_, EV_READ|EV_WRITE|EV_PERSIST, event_.get(), this);
waiting_connect_ = true;
callback_ = callback;
@@ -126,7 +127,7 @@ void TCPClientSocket::Disconnect() {
if (socket_ == kInvalidSocket)
return;
- socket_watcher_.StopWatchingFileDescriptor();
+ MessageLoopForIO::current()->UnwatchSocket(event_.get());
close(socket_);
socket_ = kInvalidSocket;
waiting_connect_ = false;
@@ -169,8 +170,8 @@ int TCPClientSocket::Read(char* buf,
return MapPosixError(errno);
}
- MessageLoopForIO::current()->WatchFileDescriptor(
- socket_, true, MessageLoopForIO::WATCH_READ, &socket_watcher_, this);
+ MessageLoopForIO::current()->WatchSocket(
+ socket_, EV_READ|EV_PERSIST, event_.get(), this);
buf_ = buf;
buf_len_ = buf_len;
@@ -195,9 +196,8 @@ int TCPClientSocket::Write(const char* buf,
if (errno != EAGAIN && errno != EWOULDBLOCK)
return MapPosixError(errno);
- MessageLoopForIO::current()->WatchFileDescriptor(
- socket_, true, MessageLoopForIO::WATCH_WRITE, &socket_watcher_, this);
-
+ MessageLoopForIO::current()->WatchSocket(
+ socket_, EV_WRITE|EV_PERSIST, event_.get(), this);
write_buf_ = buf;
write_buf_len_ = buf_len;
@@ -263,7 +263,7 @@ void TCPClientSocket::DidCompleteConnect() {
result = Connect(callback_);
} else {
result = MapPosixError(error_code);
- socket_watcher_.StopWatchingFileDescriptor();
+ MessageLoopForIO::current()->UnwatchSocket(event_.get());
waiting_connect_ = false;
}
@@ -285,7 +285,7 @@ void TCPClientSocket::DidCompleteRead() {
if (result != ERR_IO_PENDING) {
buf_ = NULL;
buf_len_ = 0;
- socket_watcher_.StopWatchingFileDescriptor();
+ MessageLoopForIO::current()->UnwatchSocket(event_.get());
DoCallback(result);
}
}
@@ -304,24 +304,21 @@ void TCPClientSocket::DidCompleteWrite() {
if (result != ERR_IO_PENDING) {
write_buf_ = NULL;
write_buf_len_ = 0;
- socket_watcher_.StopWatchingFileDescriptor();
+ MessageLoopForIO::current()->UnwatchSocket(event_.get());
DoWriteCallback(result);
}
}
-void TCPClientSocket::OnFileCanReadWithoutBlocking(int fd) {
- if (waiting_connect_) {
- DidCompleteConnect();
- } else if (callback_) {
- DidCompleteRead();
- }
-}
+void TCPClientSocket::OnSocketReady(short flags) {
+ // the only used bits of flags are EV_READ and EV_WRITE
-void TCPClientSocket::OnFileCanWriteWithoutBlocking(int fd) {
if (waiting_connect_) {
DidCompleteConnect();
- } else if (write_callback_) {
- DidCompleteWrite();
+ } else {
+ if ((flags & EV_WRITE) && write_callback_)
+ DidCompleteWrite();
+ if ((flags & EV_READ) && callback_)
+ DidCompleteRead();
}
}