#include "services/network/public/cpp/transferable_socket.h"
#if BUILDFLAG(IS_WIN)
#include <winsock2.h>
#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
#include "base/files/scoped_file.h"
#include "mojo/public/cpp/platform/platform_handle.h"
#else
#error "unsupported platform"
#endif
#include "base/dcheck_is_on.h"
#include "base/logging.h"
#include "base/notreached.h"
#include "base/process/process_handle.h"
#include "net/socket/tcp_socket.h"
#include "net/socket/udp_socket.h"
namespace network {
TransferableSocket::TransferableSocket() = default;
#if BUILDFLAG(IS_WIN)
TransferableSocket::TransferableSocket(net::SocketDescriptor socket,
const base::Process& destination_process)
: wsa_info_buffer_(sizeof(WSAPROTOCOL_INFOW), 0) {
DCHECK(destination_process.IsValid());
if (socket == net::kInvalidSocket) {
wsa_info_buffer_.clear();
return;
}
if (::WSADuplicateSocketW(socket, destination_process.Pid(),
reinterpret_cast<LPWSAPROTOCOL_INFOW>(
wsa_info_buffer_.data())) != 0) {
wsa_info_buffer_.clear();
}
::closesocket(socket);
}
#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
TransferableSocket::TransferableSocket(net::SocketDescriptor socket)
: … { … }
#else
#error "Unsupported Platform"
#endif
TransferableSocket::~TransferableSocket() = default;
TransferableSocket& TransferableSocket::operator=(TransferableSocket&& other) =
default;
TransferableSocket::TransferableSocket(TransferableSocket&& other) = default;
#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
TransferableSocket::TransferableSocket(mojo::PlatformHandle socket)
: … { … }
#elif !BUILDFLAG(IS_WIN)
#error "Unsupported Platform"
#endif
net::SocketDescriptor TransferableSocket::TakeSocket() { … }
}