1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "net/udp/udp_server_socket.h"
7 #include "net/base/net_errors.h"
8 #include "net/base/rand_callback.h"
12 UDPServerSocket::UDPServerSocket(net::NetLog
* net_log
,
13 const net::NetLog::Source
& source
)
14 : socket_(DatagramSocket::DEFAULT_BIND
,
18 allow_address_reuse_(false),
19 allow_broadcast_(false) {
22 UDPServerSocket::~UDPServerSocket() {
25 int UDPServerSocket::Listen(const IPEndPoint
& address
) {
26 int rv
= socket_
.Open(address
.GetFamily());
30 if (allow_address_reuse_
) {
31 rv
= socket_
.AllowAddressReuse();
38 if (allow_broadcast_
) {
39 rv
= socket_
.SetBroadcast(true);
46 return socket_
.Bind(address
);
49 int UDPServerSocket::RecvFrom(IOBuffer
* buf
,
52 const CompletionCallback
& callback
) {
53 return socket_
.RecvFrom(buf
, buf_len
, address
, callback
);
56 int UDPServerSocket::SendTo(IOBuffer
* buf
,
58 const IPEndPoint
& address
,
59 const CompletionCallback
& callback
) {
60 return socket_
.SendTo(buf
, buf_len
, address
, callback
);
63 int UDPServerSocket::SetReceiveBufferSize(int32 size
) {
64 return socket_
.SetReceiveBufferSize(size
);
67 int UDPServerSocket::SetSendBufferSize(int32 size
) {
68 return socket_
.SetSendBufferSize(size
);
71 void UDPServerSocket::Close() {
75 int UDPServerSocket::GetPeerAddress(IPEndPoint
* address
) const {
76 return socket_
.GetPeerAddress(address
);
79 int UDPServerSocket::GetLocalAddress(IPEndPoint
* address
) const {
80 return socket_
.GetLocalAddress(address
);
83 const BoundNetLog
& UDPServerSocket::NetLog() const {
84 return socket_
.NetLog();
87 void UDPServerSocket::AllowAddressReuse() {
88 allow_address_reuse_
= true;
91 void UDPServerSocket::AllowBroadcast() {
92 allow_broadcast_
= true;
95 int UDPServerSocket::JoinGroup(const IPAddressNumber
& group_address
) const {
96 return socket_
.JoinGroup(group_address
);
99 int UDPServerSocket::LeaveGroup(const IPAddressNumber
& group_address
) const {
100 return socket_
.LeaveGroup(group_address
);
103 int UDPServerSocket::SetMulticastInterface(uint32 interface_index
) {
104 return socket_
.SetMulticastInterface(interface_index
);
107 int UDPServerSocket::SetMulticastTimeToLive(int time_to_live
) {
108 return socket_
.SetMulticastTimeToLive(time_to_live
);
111 int UDPServerSocket::SetMulticastLoopbackMode(bool loopback
) {
112 return socket_
.SetMulticastLoopbackMode(loopback
);
115 int UDPServerSocket::SetDiffServCodePoint(DiffServCodePoint dscp
) {
116 return socket_
.SetDiffServCodePoint(dscp
);
119 void UDPServerSocket::DetachFromThread() {
120 socket_
.DetachFromThread();
124 void UDPServerSocket::UseNonBlockingIO() {
125 socket_
.UseNonBlockingIO();