Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(602)

Unified Diff: net/socket/tcp_listen_socket.cc

Issue 992733002: Remove //net (except for Android test stuff) and sdch (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/socket/tcp_listen_socket.h ('k') | net/socket/tcp_listen_socket_unittest.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/socket/tcp_listen_socket.cc
diff --git a/net/socket/tcp_listen_socket.cc b/net/socket/tcp_listen_socket.cc
deleted file mode 100644
index 11b23908ab10f8a0c04f452d5768a0734c5cd836..0000000000000000000000000000000000000000
--- a/net/socket/tcp_listen_socket.cc
+++ /dev/null
@@ -1,115 +0,0 @@
-// Copyright (c) 2012 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 "net/socket/tcp_listen_socket.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 <arpa/inet.h>
-#include <errno.h>
-#include <netinet/in.h>
-#include <sys/socket.h>
-#include <sys/types.h>
-#include "net/base/net_errors.h"
-#endif
-
-#include "base/logging.h"
-#include "base/sys_byteorder.h"
-#include "base/threading/platform_thread.h"
-#include "build/build_config.h"
-#include "net/base/net_util.h"
-#include "net/base/winsock_init.h"
-#include "net/socket/socket_descriptor.h"
-
-using std::string;
-
-namespace net {
-
-// static
-scoped_ptr<TCPListenSocket> TCPListenSocket::CreateAndListen(
- const string& ip,
- uint16 port,
- StreamListenSocket::Delegate* del) {
- SocketDescriptor s = CreateAndBind(ip, port);
- if (s == kInvalidSocket)
- return scoped_ptr<TCPListenSocket>();
- scoped_ptr<TCPListenSocket> sock(new TCPListenSocket(s, del));
- sock->Listen();
- return sock.Pass();
-}
-
-TCPListenSocket::TCPListenSocket(SocketDescriptor s,
- StreamListenSocket::Delegate* del)
- : StreamListenSocket(s, del) {
-}
-
-TCPListenSocket::~TCPListenSocket() {}
-
-SocketDescriptor TCPListenSocket::CreateAndBind(const string& ip, uint16 port) {
- SocketDescriptor s = CreatePlatformSocket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
- if (s != kInvalidSocket) {
-#if defined(OS_POSIX)
- // Allow rapid reuse.
- static const int kOn = 1;
- setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &kOn, sizeof(kOn));
-#endif
- sockaddr_in addr;
- memset(&addr, 0, sizeof(addr));
- addr.sin_family = AF_INET;
- addr.sin_addr.s_addr = inet_addr(ip.c_str());
- addr.sin_port = base::HostToNet16(port);
- if (bind(s, reinterpret_cast<sockaddr*>(&addr), sizeof(addr))) {
-#if defined(OS_WIN)
- closesocket(s);
-#elif defined(OS_POSIX)
- close(s);
-#endif
- LOG(ERROR) << "Could not bind socket to " << ip << ":" << port;
- s = kInvalidSocket;
- }
- }
- return s;
-}
-
-SocketDescriptor TCPListenSocket::CreateAndBindAnyPort(const string& ip,
- uint16* port) {
- SocketDescriptor s = CreateAndBind(ip, 0);
- if (s == kInvalidSocket)
- return kInvalidSocket;
- sockaddr_in addr;
- socklen_t addr_size = sizeof(addr);
- bool failed = getsockname(s, reinterpret_cast<struct sockaddr*>(&addr),
- &addr_size) != 0;
- if (addr_size != sizeof(addr))
- failed = true;
- if (failed) {
- LOG(ERROR) << "Could not determine bound port, getsockname() failed";
-#if defined(OS_WIN)
- closesocket(s);
-#elif defined(OS_POSIX)
- close(s);
-#endif
- return kInvalidSocket;
- }
- *port = base::NetToHost16(addr.sin_port);
- return s;
-}
-
-void TCPListenSocket::Accept() {
- SocketDescriptor conn = AcceptSocket();
- if (conn == kInvalidSocket)
- return;
- scoped_ptr<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);
-#endif
- socket_delegate_->DidAccept(this, sock.Pass());
-}
-
-} // namespace net
« no previous file with comments | « net/socket/tcp_listen_socket.h ('k') | net/socket/tcp_listen_socket_unittest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698