1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
|
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "net/socket/udp_server_socket.h"
#include <utility>
#include "build/build_config.h"
#include "net/base/net_errors.h"
namespace net {
UDPServerSocket::UDPServerSocket(net::NetLog* net_log,
const net::NetLogSource& source)
: socket_(DatagramSocket::DEFAULT_BIND, net_log, source) {}
UDPServerSocket::~UDPServerSocket() = default;
int UDPServerSocket::Listen(const IPEndPoint& address) {
int rv = socket_.Open(address.GetFamily());
if (rv != OK)
return rv;
if (allow_address_reuse_) {
rv = socket_.AllowAddressReuse();
if (rv != OK) {
socket_.Close();
return rv;
}
}
if (allow_broadcast_) {
rv = socket_.SetBroadcast(true);
if (rv != OK) {
socket_.Close();
return rv;
}
}
if (allow_address_sharing_for_multicast_) {
rv = socket_.AllowAddressSharingForMulticast();
if (rv != OK) {
socket_.Close();
return rv;
}
}
return socket_.Bind(address);
}
int UDPServerSocket::RecvFrom(IOBuffer* buf,
int buf_len,
IPEndPoint* address,
CompletionOnceCallback callback) {
return socket_.RecvFrom(buf, buf_len, address, std::move(callback));
}
int UDPServerSocket::SendTo(IOBuffer* buf,
int buf_len,
const IPEndPoint& address,
CompletionOnceCallback callback) {
return socket_.SendTo(buf, buf_len, address, std::move(callback));
}
int UDPServerSocket::SetReceiveBufferSize(int32_t size) {
return socket_.SetReceiveBufferSize(size);
}
int UDPServerSocket::SetSendBufferSize(int32_t size) {
return socket_.SetSendBufferSize(size);
}
int UDPServerSocket::SetDoNotFragment() {
return socket_.SetDoNotFragment();
}
int UDPServerSocket::SetRecvTos() {
return socket_.SetRecvTos();
}
void UDPServerSocket::SetMsgConfirm(bool confirm) {
return socket_.SetMsgConfirm(confirm);
}
void UDPServerSocket::Close() {
socket_.Close();
}
int UDPServerSocket::GetPeerAddress(IPEndPoint* address) const {
return socket_.GetPeerAddress(address);
}
int UDPServerSocket::GetLocalAddress(IPEndPoint* address) const {
return socket_.GetLocalAddress(address);
}
const NetLogWithSource& UDPServerSocket::NetLog() const {
return socket_.NetLog();
}
void UDPServerSocket::AllowAddressReuse() {
allow_address_reuse_ = true;
}
void UDPServerSocket::AllowBroadcast() {
allow_broadcast_ = true;
}
void UDPServerSocket::AllowAddressSharingForMulticast() {
allow_address_sharing_for_multicast_ = true;
}
int UDPServerSocket::JoinGroup(const IPAddress& group_address) const {
return socket_.JoinGroup(group_address);
}
int UDPServerSocket::LeaveGroup(const IPAddress& group_address) const {
return socket_.LeaveGroup(group_address);
}
int UDPServerSocket::SetMulticastInterface(uint32_t interface_index) {
return socket_.SetMulticastInterface(interface_index);
}
int UDPServerSocket::SetMulticastTimeToLive(int time_to_live) {
return socket_.SetMulticastTimeToLive(time_to_live);
}
int UDPServerSocket::SetMulticastLoopbackMode(bool loopback) {
return socket_.SetMulticastLoopbackMode(loopback);
}
int UDPServerSocket::SetDiffServCodePoint(DiffServCodePoint dscp) {
return socket_.SetDiffServCodePoint(dscp);
}
int UDPServerSocket::SetTos(DiffServCodePoint dscp, EcnCodePoint ecn) {
return socket_.SetTos(dscp, ecn);
}
void UDPServerSocket::DetachFromThread() {
socket_.DetachFromThread();
}
DscpAndEcn UDPServerSocket::GetLastTos() const {
return socket_.GetLastTos();
}
void UDPServerSocket::UseNonBlockingIO() {
#if BUILDFLAG(IS_WIN)
socket_.UseNonBlockingIO();
#endif
}
} // namespace net
|