#include "net/base/ip_endpoint.h"
#include "net/base/net_errors.h"
#include "net/server/http_server_request_info.h"
-#include "net/socket/tcp_listen_socket.h"
+#include "net/socket/tcp_server_socket.h"
#include "testing/gtest/include/gtest/gtest.h"
+const int kBufferSize = 100 * 1024 * 1024; // 100 MB
+
TestHttpServer::TestHttpServer()
: thread_("ServerThread"),
all_closed_event_(false, true),
return web_socket_url_;
}
+void TestHttpServer::OnConnect(int connection_id) {
+ server_->SetSendBufferSize(connection_id, kBufferSize);
+ server_->SetReceiveBufferSize(connection_id, kBufferSize);
+}
+
void TestHttpServer::OnWebSocketRequest(
int connection_id,
const net::HttpServerRequestInfo& info) {
server_->Send404(connection_id);
break;
case kClose:
- // net::HttpServer doesn't allow us to close connection during callback.
- base::MessageLoop::current()->PostTask(
- FROM_HERE,
- base::Bind(&net::HttpServer::Close, server_, connection_id));
+ server_->Close(connection_id);
break;
}
}
server_->SendOverWebSocket(connection_id, data);
break;
case kCloseOnMessage:
- // net::HttpServer doesn't allow us to close connection during callback.
- base::MessageLoop::current()->PostTask(
- FROM_HERE,
- base::Bind(&net::HttpServer::Close, server_, connection_id));
+ server_->Close(connection_id);
break;
}
}
void TestHttpServer::StartOnServerThread(bool* success,
base::WaitableEvent* event) {
- net::TCPListenSocketFactory factory("127.0.0.1", 0);
- server_ = new net::HttpServer(factory, this);
+ scoped_ptr<net::ServerSocket> server_socket(
+ new net::TCPServerSocket(NULL, net::NetLog::Source()));
+ server_socket->ListenWithAddressAndPort("127.0.0.1", 0, 1);
+ server_.reset(new net::HttpServer(server_socket.Pass(), this));
net::IPEndPoint address;
int error = server_->GetLocalAddress(&address);
web_socket_url_ = GURL(base::StringPrintf("ws://127.0.0.1:%d",
address.port()));
} else {
- server_ = NULL;
+ server_.reset(NULL);
}
*success = server_.get();
event->Signal();
}
void TestHttpServer::StopOnServerThread(base::WaitableEvent* event) {
- if (server_.get())
- server_ = NULL;
+ server_.reset(NULL);
event->Signal();
}