summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-30 17:37:35 +0000
committeragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-30 17:37:35 +0000
commit009aa841199a2786b5eb760a86c40ec568011e57 (patch)
tree3f5d8dca7ffcac7fec11ce3b3f4a4a1c1af6855e
parent046ae6b3ed16d57a1583680d792653b29ff8bd17 (diff)
downloadchromium_src-009aa841199a2786b5eb760a86c40ec568011e57.zip
chromium_src-009aa841199a2786b5eb760a86c40ec568011e57.tar.gz
chromium_src-009aa841199a2786b5eb760a86c40ec568011e57.tar.bz2
Deflake ListenSocketTest.ServerSend and remove unused telnet code.
http://codereview.chromium.org/2847089/show BUG=48562 TEST=net_unittests git-svn-id: svn://svn.chromium.org/chrome/trunk/src@54336 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--net/base/listen_socket_unittest.cc161
-rw-r--r--net/base/listen_socket_unittest.h27
-rw-r--r--net/base/telnet_server.cc284
-rw-r--r--net/base/telnet_server.h62
-rw-r--r--net/base/telnet_server_unittest.cc73
-rw-r--r--net/net.gyp3
6 files changed, 47 insertions, 563 deletions
diff --git a/net/base/listen_socket_unittest.cc b/net/base/listen_socket_unittest.cc
index b38019d..23dd089 100644
--- a/net/base/listen_socket_unittest.cc
+++ b/net/base/listen_socket_unittest.cc
@@ -5,6 +5,7 @@
#include "net/base/listen_socket_unittest.h"
#include <fcntl.h>
+#include <sys/types.h>
#include "base/eintr_wrapper.h"
#include "net/base/net_util.h"
@@ -13,31 +14,16 @@
const int ListenSocketTester::kTestPort = 9999;
static const int kReadBufSize = 1024;
-static const char* kHelloWorld = "HELLO, WORLD";
+static const char kHelloWorld[] = "HELLO, WORLD";
static const int kMaxQueueSize = 20;
-static const char* kLoopback = "127.0.0.1";
+static const char kLoopback[] = "127.0.0.1";
static const int kDefaultTimeoutMs = 5000;
-#if defined(OS_POSIX)
-static const char* kSemaphoreName = "chromium.listen_socket";
-#endif
-
ListenSocket* ListenSocketTester::DoListen() {
return ListenSocket::Listen(kLoopback, kTestPort, this);
}
void ListenSocketTester::SetUp() {
-#if defined(OS_WIN)
- InitializeCriticalSection(&lock_);
- semaphore_ = CreateSemaphore(NULL, 0, kMaxQueueSize, NULL);
- server_ = NULL;
- net::EnsureWinsockInit();
-#elif defined(OS_POSIX)
- ASSERT_EQ(0, pthread_mutex_init(&lock_, NULL));
- sem_unlink(kSemaphoreName);
- semaphore_ = sem_open(kSemaphoreName, O_CREAT, 0, 0);
- ASSERT_NE(SEM_FAILED, semaphore_);
-#endif
base::Thread::Options options;
options.message_loop_type = MessageLoop::TYPE_IO;
thread_.reset(new base::Thread("socketio_test"));
@@ -48,7 +34,7 @@ void ListenSocketTester::SetUp() {
this, &ListenSocketTester::Listen));
// verify Listen succeeded
- ASSERT_TRUE(NextAction(kDefaultTimeoutMs));
+ NextAction();
ASSERT_FALSE(server_ == NULL);
ASSERT_EQ(ACTION_LISTEN, last_action_.type());
@@ -59,124 +45,55 @@ void ListenSocketTester::SetUp() {
client.sin_family = AF_INET;
client.sin_addr.s_addr = inet_addr(kLoopback);
client.sin_port = htons(kTestPort);
- int ret =
- HANDLE_EINTR(connect(test_socket_, reinterpret_cast<sockaddr*>(&client),
- sizeof(client)));
+ int ret = HANDLE_EINTR(
+ connect(test_socket_, reinterpret_cast<sockaddr*>(&client),
+ sizeof(client)));
ASSERT_NE(ret, SOCKET_ERROR);
- net::SetNonBlocking(test_socket_);
- ASSERT_TRUE(NextAction(kDefaultTimeoutMs));
+ NextAction();
ASSERT_EQ(ACTION_ACCEPT, last_action_.type());
}
void ListenSocketTester::TearDown() {
- // verify close
#if defined(OS_WIN)
- closesocket(test_socket_);
+ ASSERT_EQ(0, closesocket(test_socket_));
#elif defined(OS_POSIX)
- close(test_socket_);
+ ASSERT_EQ(0, HANDLE_EINTR(close(test_socket_)));
#endif
- ASSERT_TRUE(NextAction(kDefaultTimeoutMs));
+ NextAction();
ASSERT_EQ(ACTION_CLOSE, last_action_.type());
loop_->PostTask(FROM_HERE, NewRunnableMethod(
this, &ListenSocketTester::Shutdown));
- ASSERT_TRUE(NextAction(kDefaultTimeoutMs));
+ NextAction();
ASSERT_EQ(ACTION_SHUTDOWN, last_action_.type());
-#if defined(OS_WIN)
- CloseHandle(semaphore_);
- semaphore_ = 0;
- DeleteCriticalSection(&lock_);
-#elif defined(OS_POSIX)
- ASSERT_EQ(0, pthread_mutex_lock(&lock_));
- semaphore_ = NULL;
- ASSERT_EQ(0, pthread_mutex_unlock(&lock_));
- ASSERT_EQ(0, sem_unlink(kSemaphoreName));
- ASSERT_EQ(0, pthread_mutex_destroy(&lock_));
-#endif
-
thread_.reset();
loop_ = NULL;
}
void ListenSocketTester::ReportAction(const ListenSocketTestAction& action) {
-#if defined(OS_WIN)
- EnterCriticalSection(&lock_);
+ AutoLock locked(lock_);
queue_.push_back(action);
- LeaveCriticalSection(&lock_);
- ReleaseSemaphore(semaphore_, 1, NULL);
-#elif defined(OS_POSIX)
- ASSERT_EQ(0, pthread_mutex_lock(&lock_));
- queue_.push_back(action);
- ASSERT_EQ(0, pthread_mutex_unlock(&lock_));
- ASSERT_EQ(0, sem_post(semaphore_));
-#endif
+ cv_.Broadcast();
}
-bool ListenSocketTester::NextAction(int timeout) {
-#if defined(OS_WIN)
- DWORD ret = ::WaitForSingleObject(semaphore_, timeout);
- if (ret != WAIT_OBJECT_0)
- return false;
- EnterCriticalSection(&lock_);
- if (queue_.size() == 0) {
- LeaveCriticalSection(&lock_);
- return false;
- }
+void ListenSocketTester::NextAction() {
+ AutoLock locked(lock_);
+ while (queue_.empty())
+ cv_.Wait();
last_action_ = queue_.front();
queue_.pop_front();
- LeaveCriticalSection(&lock_);
- return true;
-#elif defined(OS_POSIX)
- if (semaphore_ == SEM_FAILED)
- return false;
- while (true) {
- int result = sem_trywait(semaphore_);
- PlatformThread::Sleep(1); // 1MS sleep
- timeout--;
- if (timeout <= 0)
- return false;
- if (result == 0)
- break;
- }
- pthread_mutex_lock(&lock_);
- if (queue_.size() == 0) {
- pthread_mutex_unlock(&lock_);
- return false;
- }
- last_action_ = queue_.front();
- queue_.pop_front();
- pthread_mutex_unlock(&lock_);
- return true;
-#endif
}
int ListenSocketTester::ClearTestSocket() {
char buf[kReadBufSize];
int len_ret = 0;
- int time_out = 0;
do {
int len = HANDLE_EINTR(recv(test_socket_, buf, kReadBufSize, 0));
-#if defined(OS_WIN)
- if (len == SOCKET_ERROR) {
- int err = WSAGetLastError();
- if (err == WSAEWOULDBLOCK) {
-#elif defined(OS_POSIX)
- if (len == SOCKET_ERROR) {
- if (errno == EWOULDBLOCK || errno == EAGAIN) {
-#endif
- PlatformThread::Sleep(1);
- time_out++;
- if (time_out > 10)
- break;
- continue; // still trying
- }
- } else if (len == 0) {
- // socket closed
+ if (len == SOCKET_ERROR || len == 0) {
break;
} else {
- time_out = 0;
len_ret += len;
}
} while (true);
@@ -236,30 +153,30 @@ bool ListenSocketTester::Send(SOCKET sock, const std::string& str) {
void ListenSocketTester::TestClientSend() {
ASSERT_TRUE(Send(test_socket_, kHelloWorld));
- ASSERT_TRUE(NextAction(kDefaultTimeoutMs));
+ NextAction();
ASSERT_EQ(ACTION_READ, last_action_.type());
ASSERT_EQ(last_action_.data(), kHelloWorld);
}
void ListenSocketTester::TestClientSendLong() {
- int hello_len = strlen(kHelloWorld);
+ size_t hello_len = strlen(kHelloWorld);
std::string long_string;
- int long_len = 0;
+ size_t long_len = 0;
for (int i = 0; i < 200; i++) {
long_string += kHelloWorld;
long_len += hello_len;
}
ASSERT_TRUE(Send(test_socket_, long_string));
- int read_len = 0;
+ size_t read_len = 0;
while (read_len < long_len) {
- ASSERT_TRUE(NextAction(kDefaultTimeoutMs));
+ NextAction();
ASSERT_EQ(ACTION_READ, last_action_.type());
std::string last_data = last_action_.data();
size_t len = last_data.length();
if (long_string.compare(read_len, len, last_data)) {
ASSERT_EQ(long_string.compare(read_len, len, last_data), 0);
}
- read_len += static_cast<int>(last_data.length());
+ read_len += last_data.length();
}
ASSERT_EQ(read_len, long_len);
}
@@ -267,24 +184,18 @@ void ListenSocketTester::TestClientSendLong() {
void ListenSocketTester::TestServerSend() {
loop_->PostTask(FROM_HERE, NewRunnableMethod(
this, &ListenSocketTester::SendFromTester));
- ASSERT_TRUE(NextAction(kDefaultTimeoutMs));
+ NextAction();
ASSERT_EQ(ACTION_SEND, last_action_.type());
- // TODO(erikkay): Without this sleep, the recv seems to fail a small amount
- // of the time. I could fix this by making the socket blocking, but then
- // this test might hang in the case of errors. It would be nice to do
- // something that felt more reliable here.
- PlatformThread::Sleep(10); // sleep for 10ms
const int buf_len = 200;
char buf[buf_len+1];
- int recv_len;
- do {
- recv_len = HANDLE_EINTR(recv(test_socket_, buf, buf_len, 0));
-#if defined(OS_POSIX)
- } while (recv_len == SOCKET_ERROR && errno == EINTR);
-#else
- } while (false);
-#endif
- ASSERT_NE(recv_len, SOCKET_ERROR);
+ unsigned recv_len = 0;
+ while (recv_len < strlen(kHelloWorld)) {
+ int r = HANDLE_EINTR(recv(test_socket_, buf, buf_len, 0));
+ ASSERT_GE(r, 0);
+ recv_len += static_cast<unsigned>(r);
+ if (!r)
+ break;
+ }
buf[recv_len] = 0;
ASSERT_STREQ(buf, kHelloWorld);
}
@@ -319,8 +230,6 @@ TEST_F(ListenSocketTest, ClientSendLong) {
tester_->TestClientSendLong();
}
-// This test is flaky; see comment in ::TestServerSend.
-// http://code.google.com/p/chromium/issues/detail?id=48562
-TEST_F(ListenSocketTest, FLAKY_ServerSend) {
+TEST_F(ListenSocketTest, ServerSend) {
tester_->TestServerSend();
}
diff --git a/net/base/listen_socket_unittest.h b/net/base/listen_socket_unittest.h
index f509093..6658d91 100644
--- a/net/base/listen_socket_unittest.h
+++ b/net/base/listen_socket_unittest.h
@@ -13,18 +13,18 @@
#elif defined(OS_POSIX)
#include <sys/socket.h>
#include <errno.h>
-#include <semaphore.h>
#include <arpa/inet.h>
#endif
-#include "base/scoped_ptr.h"
-#include "base/thread.h"
#include "base/basictypes.h"
+#include "base/condition_variable.h"
+#include "base/lock.h"
#include "base/message_loop.h"
+#include "base/scoped_ptr.h"
#include "base/string_util.h"
#include "base/thread.h"
-#include "net/base/net_util.h"
#include "net/base/listen_socket.h"
+#include "net/base/net_util.h"
#include "net/base/winsock_init.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -80,14 +80,15 @@ class ListenSocketTester :
: thread_(NULL),
loop_(NULL),
server_(NULL),
- connection_(NULL){
+ connection_(NULL),
+ cv_(&lock_) {
}
virtual void SetUp();
virtual void TearDown();
void ReportAction(const ListenSocketTestAction& action);
- bool NextAction(int timeout);
+ void NextAction();
// read all pending data from the test socket
int ClearTestSocket();
@@ -106,22 +107,18 @@ class ListenSocketTester :
// verify a send/read from server to client
void TestServerSend();
-#if defined(OS_WIN)
- CRITICAL_SECTION lock_;
- HANDLE semaphore_;
-#elif defined(OS_POSIX)
- pthread_mutex_t lock_;
- sem_t* semaphore_;
-#endif
-
scoped_ptr<base::Thread> thread_;
MessageLoopForIO* loop_;
ListenSocket* server_;
ListenSocket* connection_;
ListenSocketTestAction last_action_;
- std::deque<ListenSocketTestAction> queue_;
+
SOCKET test_socket_;
static const int kTestPort;
+
+ Lock lock_; // protects |queue_| and wraps |cv_|
+ ConditionVariable cv_;
+ std::deque<ListenSocketTestAction> queue_;
};
#endif // NET_BASE_LISTEN_SOCKET_UNITTEST_H_
diff --git a/net/base/telnet_server.cc b/net/base/telnet_server.cc
deleted file mode 100644
index 5b027d7..0000000
--- a/net/base/telnet_server.cc
+++ /dev/null
@@ -1,284 +0,0 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "build/build_config.h"
-
-#if defined(OS_WIN)
-// winsock2.h must be included first in order to ensure it is included before
-// windows.h.
-#include <winsock2.h>
-#elif defined(OS_POSIX)
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include "base/message_loop.h"
-#include "net/base/net_errors.h"
-#if defined(USE_SYSTEM_LIBEVENT)
-#include <event.h>
-#else
-#include "third_party/libevent/event.h"
-#endif
-#include "base/message_pump_libevent.h"
-#endif
-
-#include "base/eintr_wrapper.h"
-#include "net/base/telnet_server.h"
-
-#if defined(OS_POSIX)
-// Used same name as in Windows to avoid #ifdef where refrenced
-#define SOCKET int
-const int INVALID_SOCKET = -1;
-const int SOCKET_ERROR = -1;
-struct event; // From libevent
-#endif
-
-const int kReadBufSize = 200;
-
-// Telnet protocol constants.
-class TelnetProtocol {
- public:
- // Telnet command definitions (from arpa/telnet.h).
- enum Commands {
- IAC = 255, // Interpret as command.
- DONT = 254, // You are not to use option.
- DO = 253, // Please, you use option.
- WONT = 252, // I won't use option.
- WILL = 251, // I will use option.
- SB = 250, // Interpret as subnegotiation.
- GA = 249, // You may reverse the line.
- EL = 248, // Erase the current line.
- EC = 247, // Erase the current character.
- AYT = 246, // Are you there.
- AO = 245, // Abort output--but let prog finish.
- IP = 244, // Interrupt process--permanently.
- BREAK = 243, // Break.
- DM = 242, // Data mark--for connect. cleaning.
- NOP = 241, // Nop.
- SE = 240, // End sub negotiation.
- EOR = 239, // End of record (transparent mode).
- ABORT = 238, // Abort process.
- SUSP = 237, // Suspend process.
- XEOF = 236 // End of file: EOF is already used...
- };
-
- // Telnet options (from arpa/telnet.h).
- enum Options {
- BINARY = 0, // 8-bit data path.
- ECHO = 1, // Echo.
- SGA = 3, // Suppress go ahead.
- NAWS = 31, // Window size.
- LFLOW = 33 // Remote flow control.
- };
-
- // Fixed character definitions mentioned in RFC 854.
- enum Characters {
- NUL = 0x00,
- LF = 0x0A,
- CR = 0x0D,
- BELL = 0x07,
- BS = 0x08,
- HT = 0x09,
- VT = 0x0B,
- FF = 0x0C,
- DEL = 0x7F,
- ESC = 0x1B
- };
-};
-
-
-///////////////////////
-
-// must run in the IO thread
-TelnetServer::TelnetServer(SOCKET s, ListenSocketDelegate* del)
- : ListenSocket(s, del) {
- input_state_ = NOT_IN_IAC_OR_ESC_SEQUENCE;
-}
-
-// must run in the IO thread
-TelnetServer::~TelnetServer() {
-}
-
-void TelnetServer::SendIAC(int command, int option) {
- char data[3];
- data[0] = static_cast<unsigned char>(TelnetProtocol::IAC);
- data[1] = static_cast<unsigned char>(command);
- data[2] = option;
- Send(data, 3);
-}
-
-// always fixup \n to \r\n
-void TelnetServer::SendInternal(const char* data, int len) {
- int begin_index = 0;
- for (int i = 0; i < len; i++) {
- if (data[i] == TelnetProtocol::LF) {
- // Send CR before LF if missing before.
- if (i == 0 || data[i - 1] != TelnetProtocol::CR) {
- // Send til before LF.
- ListenSocket::SendInternal(data + begin_index, i - begin_index);
- // Send CRLF.
- ListenSocket::SendInternal("\r\n", 2);
- // Continue after LF.
- begin_index = i + 1;
- }
- }
- }
- // Send what is left (the whole string is sent here if CRLF was ok)
- ListenSocket::SendInternal(data + begin_index, len - begin_index);
-}
-
-void TelnetServer::Accept() {
- SOCKET conn = ListenSocket::Accept(socket_);
- if (conn == INVALID_SOCKET) {
- // TODO
- } else {
- scoped_refptr<TelnetServer> sock =
- new TelnetServer(conn, socket_delegate_);
-#if defined(OS_POSIX)
- sock->WatchSocket(WAITING_READ);
-#endif
- // Setup the way we want to communicate
- sock->SendIAC(TelnetProtocol::DO, TelnetProtocol::ECHO);
- sock->SendIAC(TelnetProtocol::DO, TelnetProtocol::NAWS);
- sock->SendIAC(TelnetProtocol::DO, TelnetProtocol::LFLOW);
- sock->SendIAC(TelnetProtocol::WILL, TelnetProtocol::ECHO);
- sock->SendIAC(TelnetProtocol::WILL, TelnetProtocol::SGA);
-
- // it's up to the delegate to AddRef if it wants to keep it around
- socket_delegate_->DidAccept(this, sock);
- }
-}
-
-TelnetServer* TelnetServer::Listen(std::string ip, int port,
- ListenSocketDelegate *del) {
- SOCKET s = ListenSocket::Listen(ip, port);
- if (s == INVALID_SOCKET) {
- // TODO (ibrar): error handling
- } else {
- TelnetServer *serv = new TelnetServer(s, del);
- serv->Listen();
- return serv;
- }
- return NULL;
-}
-
-void TelnetServer::StateMachineStep(unsigned char c) {
- switch (input_state_) {
- case NOT_IN_IAC_OR_ESC_SEQUENCE:
- if (c == TelnetProtocol::IAC) {
- // Expect IAC command
- input_state_ = EXPECTING_COMMAND;
- } else if (c == TelnetProtocol::ESC) {
- // Expect left suare bracket
- input_state_ = EXPECTING_FIRST_ESC_CHARACTER;
- } else {
- char data[1];
- data[0] = c;
- // handle backspace specially
- if (c == TelnetProtocol::DEL) {
- if (!command_line_.empty()) {
- command_line_.erase(--command_line_.end());
- Send(data, 1);
- }
- } else {
- // Collect command
- if (c >= ' ')
- command_line_ += c;
- // Echo character to client (for now ignore control characters).
- if (c >= ' ' || c == TelnetProtocol::CR) {
- Send(data, 1);
- }
- // Check for line termination
- if (c == TelnetProtocol::CR)
- input_state_ = EXPECTING_NEW_LINE;
- }
- }
- break;
- case EXPECTING_NEW_LINE:
- if (c == TelnetProtocol::LF) {
- Send("\n", 1);
- socket_delegate_->DidRead(this,
- command_line_.c_str(),
- command_line_.length());
- command_line_ = "";
- }
- input_state_ = NOT_IN_IAC_OR_ESC_SEQUENCE;
- break;
- case EXPECTING_COMMAND:
- // Read command, expect option.
- iac_command_ = c;
- input_state_ = EXPECTING_OPTION;
- break;
- case EXPECTING_OPTION:
- // Read option
- iac_option_ = c;
- // check for subnegoating if not done reading IAC.
- if (iac_command_ != TelnetProtocol::SB) {
- input_state_ = NOT_IN_IAC_OR_ESC_SEQUENCE;
- } else {
- input_state_ = SUBNEGOTIATION_EXPECTING_IAC;
- }
- break;
- case SUBNEGOTIATION_EXPECTING_IAC:
- // Currently ignore content of subnegotiation.
- if (c == TelnetProtocol::IAC)
- input_state_ = SUBNEGOTIATION_EXPECTING_SE;
- break;
- case SUBNEGOTIATION_EXPECTING_SE:
- // Character must be SE and subnegotiation is finished.
- input_state_ = NOT_IN_IAC_OR_ESC_SEQUENCE;
- break;
- case EXPECTING_FIRST_ESC_CHARACTER:
- if (c == '[') {
- // Expect ESC sequence content.
- input_state_ = EXPECTING_NUMBER_SEMICOLON_OR_END;
- } else if (c == 'O') {
- // VT100 "ESC O" sequence.
- input_state_ = EXPECTING_SECOND_ESC_CHARACTER;
- } else {
- // Unknown ESC sequence - ignore.
- }
- break;
- case EXPECTING_SECOND_ESC_CHARACTER:
- // Ignore ESC sequence content for now.
- input_state_ = NOT_IN_IAC_OR_ESC_SEQUENCE;
- break;
- case EXPECTING_NUMBER_SEMICOLON_OR_END:
- if (isdigit(c) || c ==';') {
- // Ignore ESC sequence content for now.
- } else {
- // Final character in ESC sequence.
- input_state_ = NOT_IN_IAC_OR_ESC_SEQUENCE;
- }
- break;
- }
-}
-
-void TelnetServer::Read() {
- char buf[kReadBufSize + 1];
- int len;
- do {
- len = HANDLE_EINTR(recv(socket_, buf, kReadBufSize, 0));
-
-#if defined(OS_WIN)
- if (len == SOCKET_ERROR) {
- int err = WSAGetLastError();
- if (err == WSAEWOULDBLOCK)
- break;
-#else
- if (len == SOCKET_ERROR) {
- if (errno == EWOULDBLOCK || errno == EAGAIN)
- break;
-#endif
- } else if (len == 0) {
- Close();
- } else {
- const char *data = buf;
- for (int i = 0; i < len; ++i) {
- unsigned char c = static_cast<unsigned char>(*data);
- StateMachineStep(c);
- data++;
- }
- }
- } while (len == kReadBufSize);
-}
diff --git a/net/base/telnet_server.h b/net/base/telnet_server.h
deleted file mode 100644
index ef367dd..0000000
--- a/net/base/telnet_server.h
+++ /dev/null
@@ -1,62 +0,0 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef NET_BASE_TELNET_SERVER_H_
-#define NET_BASE_TELNET_SERVER_H_
-#pragma once
-
-#include "net/base/listen_socket.h"
-
-// Implements the telnet protocol on top of the raw socket interface.
-// DidRead calls to the delegate are buffered on a line by line basis.
-// (for now this means that basic line editing is handled in this object)
-class TelnetServer : public ListenSocket {
-public:
- static TelnetServer* Listen(std::string ip, int port,
- ListenSocketDelegate *del);
-
-protected:
- void Listen() { ListenSocket::Listen(); }
- virtual void Read();
- virtual void Accept();
- virtual void SendInternal(const char* bytes, int len);
-
-private:
- enum TelnetInputState {
- // Currently not processing any IAC or ESC sequence.
- NOT_IN_IAC_OR_ESC_SEQUENCE,
- // Received carriage return (CR) expecting new line (LF).
- EXPECTING_NEW_LINE,
- // Processing IAC expecting command.
- EXPECTING_COMMAND,
- // Processing IAC expecting option.
- EXPECTING_OPTION,
- // Inside subnegoation IAC,SE will end it.
- SUBNEGOTIATION_EXPECTING_IAC,
- // Ending subnegoation expecting SE.
- SUBNEGOTIATION_EXPECTING_SE,
- // Processing ESC sequence.
- EXPECTING_FIRST_ESC_CHARACTER,
- // Processing ESC sequence with two characters.
- EXPECTING_SECOND_ESC_CHARACTER,
- // Processing "ESC [" sequence.
- EXPECTING_NUMBER_SEMICOLON_OR_END
- };
-
- TelnetServer(SOCKET s, ListenSocketDelegate* del);
- virtual ~TelnetServer();
-
- // telnet commands
- void SendIAC(int command, int option);
- void StateMachineStep(unsigned char c);
-
- TelnetInputState input_state_;
- int iac_command_; // Last command read.
- int iac_option_; // Last option read.
- std::string command_line_;
-
- DISALLOW_COPY_AND_ASSIGN(TelnetServer);
-};
-
-#endif // NET_BASE_TELNET_SERVER_H_
diff --git a/net/base/telnet_server_unittest.cc b/net/base/telnet_server_unittest.cc
deleted file mode 100644
index 1112bd2..0000000
--- a/net/base/telnet_server_unittest.cc
+++ /dev/null
@@ -1,73 +0,0 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Tests TelnetServer.
-
-#include "net/base/listen_socket_unittest.h"
-#include "net/base/telnet_server.h"
-#include "testing/platform_test.h"
-
-static const char* kCRLF = "\r\n";
-
-class TelnetServerTester : public ListenSocketTester {
-public:
- virtual ListenSocket* DoListen() {
- return TelnetServer::Listen("127.0.0.1", kTestPort, this);
- }
-
- virtual void SetUp() {
- ListenSocketTester::SetUp();
- // With TelnetServer, there's some control codes sent at connect time,
- // so we need to eat those to avoid affecting the subsequent tests.
- EXPECT_EQ(ClearTestSocket(), 15);
- }
-
- virtual bool Send(SOCKET sock, const std::string& str) {
- if (ListenSocketTester::Send(sock, str)) {
- // TelnetServer currently calls DidRead after a CRLF, so we need to
- // append one to the end of the data that we send.
- if (ListenSocketTester::Send(sock, kCRLF)) {
- return true;
- }
- }
- return false;
- }
-
-private:
- ~TelnetServerTester() {}
-};
-
-class TelnetServerTest: public PlatformTest {
-protected:
- TelnetServerTest() {
- tester_ = NULL;
- }
-
- virtual void SetUp() {
- PlatformTest::SetUp();
- tester_ = new TelnetServerTester();
- tester_->SetUp();
- }
-
- virtual void TearDown() {
- PlatformTest::TearDown();
- tester_->TearDown();
- tester_ = NULL;
- }
-
- scoped_refptr<TelnetServerTester> tester_;
-};
-
-// Flaky, http://crbug.com/38093.
-TEST_F(TelnetServerTest, FLAKY_ServerClientSend) {
- tester_->TestClientSend();
-}
-
-TEST_F(TelnetServerTest, ClientSendLong) {
- tester_->TestClientSendLong();
-}
-
-TEST_F(TelnetServerTest, ServerSend) {
- tester_->TestServerSend();
-}
diff --git a/net/net.gyp b/net/net.gyp
index 56edd4c..c98a86c 100644
--- a/net/net.gyp
+++ b/net/net.gyp
@@ -161,8 +161,6 @@
'base/transport_security_state.cc',
'base/transport_security_state.h',
'base/sys_addrinfo.h',
- 'base/telnet_server.cc',
- 'base/telnet_server.h',
'base/test_completion_callback.h',
'base/upload_data.cc',
'base/upload_data.h',
@@ -695,7 +693,6 @@
'base/ssl_config_service_win_unittest.cc',
'base/static_cookie_policy_unittest.cc',
'base/transport_security_state_unittest.cc',
- 'base/telnet_server_unittest.cc',
'base/test_certificate_data.h',
'base/test_completion_callback_unittest.cc',
'base/upload_data_stream_unittest.cc',