Index: net/base/tcp_listen_socket.cc |
diff --git a/net/base/listen_socket.cc b/net/base/tcp_listen_socket.cc |
similarity index 81% |
copy from net/base/listen_socket.cc |
copy to net/base/tcp_listen_socket.cc |
index c6005941a8c9b8e74c6d2d1fff7ea12da68cfafe..dfec16ffc7a114c8f21ce9ba756de9486cf11abc 100644 |
--- a/net/base/listen_socket.cc |
+++ b/net/base/tcp_listen_socket.cc |
@@ -21,7 +21,7 @@ |
#include "base/sys_byteorder.h" |
#include "base/threading/platform_thread.h" |
#include "net/base/net_util.h" |
-#include "net/base/listen_socket.h" |
+#include "net/base/tcp_listen_socket.h" |
#if defined(OS_WIN) |
typedef int socklen_t; |
@@ -36,43 +36,32 @@ const int kReadBufSize = 4096; |
} // namespace |
#if defined(OS_WIN) |
-const SOCKET ListenSocket::kInvalidSocket = INVALID_SOCKET; |
-const int ListenSocket::kSocketError = SOCKET_ERROR; |
+const SOCKET TCPListenSocket::kInvalidSocket = INVALID_SOCKET; |
+const int TCPListenSocket::kSocketError = SOCKET_ERROR; |
#elif defined(OS_POSIX) |
-const SOCKET ListenSocket::kInvalidSocket = -1; |
-const int ListenSocket::kSocketError = -1; |
+const SOCKET TCPListenSocket::kInvalidSocket = -1; |
+const int TCPListenSocket::kSocketError = -1; |
#endif |
-ListenSocket* ListenSocket::Listen(std::string ip, int port, |
- ListenSocketDelegate* del) { |
- SOCKET s = Listen(ip, port); |
+TCPListenSocket* TCPListenSocket::CreateAndListen( |
+ std::string ip, int port, ListenSocket::ListenSocketDelegate *del) { |
+ SOCKET s = CreateAndBind(ip, port); |
if (s == kInvalidSocket) { |
// TODO(erikkay): error handling |
} else { |
- ListenSocket* sock = new ListenSocket(s, del); |
+ TCPListenSocket* sock = new TCPListenSocket(s, del); |
sock->Listen(); |
return sock; |
} |
return NULL; |
} |
-void ListenSocket::Send(const char* bytes, int len, bool append_linefeed) { |
- SendInternal(bytes, len); |
- if (append_linefeed) { |
- SendInternal("\r\n", 2); |
- } |
-} |
- |
-void ListenSocket::Send(const std::string& str, bool append_linefeed) { |
- Send(str.data(), static_cast<int>(str.length()), append_linefeed); |
-} |
- |
-void ListenSocket::PauseReads() { |
+void TCPListenSocket::PauseReads() { |
DCHECK(!reads_paused_); |
reads_paused_ = true; |
} |
-void ListenSocket::ResumeReads() { |
+void TCPListenSocket::ResumeReads() { |
DCHECK(reads_paused_); |
reads_paused_ = false; |
if (has_pending_reads_) { |
@@ -81,9 +70,10 @@ void ListenSocket::ResumeReads() { |
} |
} |
-ListenSocket::ListenSocket(SOCKET s, ListenSocketDelegate *del) |
- : socket_(s), |
- socket_delegate_(del), |
+TCPListenSocket::TCPListenSocket(SOCKET s, |
+ ListenSocket::ListenSocketDelegate *del) |
+ : ListenSocket(del), |
+ socket_(s), |
reads_paused_(false), |
has_pending_reads_(false) { |
#if defined(OS_WIN) |
@@ -95,7 +85,7 @@ ListenSocket::ListenSocket(SOCKET s, ListenSocketDelegate *del) |
#endif |
} |
-ListenSocket::~ListenSocket() { |
+TCPListenSocket::~TCPListenSocket() { |
#if defined(OS_WIN) |
if (socket_event_) { |
WSACloseEvent(socket_event_); |
@@ -105,7 +95,7 @@ ListenSocket::~ListenSocket() { |
CloseSocket(socket_); |
} |
-SOCKET ListenSocket::Listen(std::string ip, int port) { |
+SOCKET TCPListenSocket::CreateAndBind(std::string ip, int port) { |
SOCKET s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); |
if (s != kInvalidSocket) { |
#if defined(OS_POSIX) |
@@ -130,7 +120,7 @@ SOCKET ListenSocket::Listen(std::string ip, int port) { |
return s; |
} |
-SOCKET ListenSocket::Accept(SOCKET s) { |
+SOCKET TCPListenSocket::Accept(SOCKET s) { |
sockaddr_in from; |
socklen_t from_len = sizeof(from); |
SOCKET conn = |
@@ -141,7 +131,7 @@ SOCKET ListenSocket::Accept(SOCKET s) { |
return conn; |
} |
-void ListenSocket::SendInternal(const char* bytes, int len) { |
+void TCPListenSocket::SendInternal(const char* bytes, int len) { |
char* send_buf = const_cast<char *>(bytes); |
int len_left = len; |
while (true) { |
@@ -171,7 +161,7 @@ void ListenSocket::SendInternal(const char* bytes, int len) { |
} |
} |
-void ListenSocket::Listen() { |
+void TCPListenSocket::Listen() { |
int backlog = 10; // TODO(erikkay): maybe don't allow any backlog? |
listen(socket_, backlog); |
// TODO(erikkay): error handling |
@@ -180,11 +170,11 @@ void ListenSocket::Listen() { |
#endif |
} |
-void ListenSocket::Accept() { |
+void TCPListenSocket::Accept() { |
SOCKET conn = Accept(socket_); |
if (conn != kInvalidSocket) { |
- scoped_refptr<ListenSocket> sock( |
- new ListenSocket(conn, socket_delegate_)); |
+ scoped_refptr<TCPListenSocket> sock( |
+ new TCPListenSocket(conn, socket_delegate_)); |
// it's up to the delegate to AddRef if it wants to keep it around |
#if defined(OS_POSIX) |
sock->WatchSocket(WAITING_READ); |
@@ -195,7 +185,7 @@ void ListenSocket::Accept() { |
} |
} |
-void ListenSocket::Read() { |
+void TCPListenSocket::Read() { |
char buf[kReadBufSize + 1]; // +1 for null termination |
int len; |
do { |
@@ -228,7 +218,7 @@ void ListenSocket::Read() { |
} while (len == kReadBufSize); |
} |
-void ListenSocket::Close() { |
+void TCPListenSocket::Close() { |
#if defined(OS_POSIX) |
if (wait_state_ == NOT_WAITING) |
return; |
@@ -238,7 +228,7 @@ void ListenSocket::Close() { |
socket_delegate_->DidClose(this); |
} |
-void ListenSocket::CloseSocket(SOCKET s) { |
+void TCPListenSocket::CloseSocket(SOCKET s) { |
if (s && s != kInvalidSocket) { |
UnwatchSocket(); |
#if defined(OS_WIN) |
@@ -249,7 +239,7 @@ void ListenSocket::CloseSocket(SOCKET s) { |
} |
} |
-void ListenSocket::WatchSocket(WaitState state) { |
+void TCPListenSocket::WatchSocket(WaitState state) { |
#if defined(OS_WIN) |
WSAEventSelect(socket_, socket_event_, FD_ACCEPT | FD_CLOSE | FD_READ); |
watcher_.StartWatching(socket_event_, this); |
@@ -261,7 +251,7 @@ void ListenSocket::WatchSocket(WaitState state) { |
#endif |
} |
-void ListenSocket::UnwatchSocket() { |
+void TCPListenSocket::UnwatchSocket() { |
#if defined(OS_WIN) |
watcher_.StopWatching(); |
#elif defined(OS_POSIX) |
@@ -272,7 +262,7 @@ void ListenSocket::UnwatchSocket() { |
// TODO(ibrar): We can add these functions into OS dependent files |
#if defined(OS_WIN) |
// MessageLoop watcher callback |
-void ListenSocket::OnObjectSignaled(HANDLE object) { |
+void TCPListenSocket::OnObjectSignaled(HANDLE object) { |
WSANETWORKEVENTS ev; |
if (kSocketError == WSAEnumNetworkEvents(socket_, socket_event_, &ev)) { |
// TODO |
@@ -302,7 +292,7 @@ void ListenSocket::OnObjectSignaled(HANDLE object) { |
} |
} |
#elif defined(OS_POSIX) |
-void ListenSocket::OnFileCanReadWithoutBlocking(int fd) { |
+void TCPListenSocket::OnFileCanReadWithoutBlocking(int fd) { |
switch (wait_state_) { |
case WAITING_ACCEPT: |
Accept(); |
@@ -321,7 +311,7 @@ void ListenSocket::OnFileCanReadWithoutBlocking(int fd) { |
} |
} |
-void ListenSocket::OnFileCanWriteWithoutBlocking(int fd) { |
+void TCPListenSocket::OnFileCanWriteWithoutBlocking(int fd) { |
// MessagePumpLibevent callback, we don't listen for write events |
// so we shouldn't ever reach here. |
NOTREACHED(); |