OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "net/udp/udp_server_socket.h" | |
6 | |
7 #include "net/base/net_errors.h" | |
8 #include "net/base/rand_callback.h" | |
9 | |
10 namespace net { | |
11 | |
12 UDPServerSocket::UDPServerSocket(net::NetLog* net_log, | |
13 const net::NetLogSource& source) | |
14 : socket_(DatagramSocket::DEFAULT_BIND, RandIntCallback(), net_log, source), | |
15 allow_address_reuse_(false), | |
16 allow_broadcast_(false) {} | |
17 | |
18 UDPServerSocket::~UDPServerSocket() { | |
19 } | |
20 | |
21 int UDPServerSocket::Listen(const IPEndPoint& address) { | |
22 int rv = socket_.Open(address.GetFamily()); | |
23 if (rv != OK) | |
24 return rv; | |
25 | |
26 if (allow_address_reuse_) { | |
27 rv = socket_.AllowAddressReuse(); | |
28 if (rv != OK) { | |
29 socket_.Close(); | |
30 return rv; | |
31 } | |
32 } | |
33 | |
34 if (allow_broadcast_) { | |
35 rv = socket_.SetBroadcast(true); | |
36 if (rv != OK) { | |
37 socket_.Close(); | |
38 return rv; | |
39 } | |
40 } | |
41 | |
42 return socket_.Bind(address); | |
43 } | |
44 | |
45 int UDPServerSocket::RecvFrom(IOBuffer* buf, | |
46 int buf_len, | |
47 IPEndPoint* address, | |
48 const CompletionCallback& callback) { | |
49 return socket_.RecvFrom(buf, buf_len, address, callback); | |
50 } | |
51 | |
52 int UDPServerSocket::SendTo(IOBuffer* buf, | |
53 int buf_len, | |
54 const IPEndPoint& address, | |
55 const CompletionCallback& callback) { | |
56 return socket_.SendTo(buf, buf_len, address, callback); | |
57 } | |
58 | |
59 int UDPServerSocket::SetReceiveBufferSize(int32_t size) { | |
60 return socket_.SetReceiveBufferSize(size); | |
61 } | |
62 | |
63 int UDPServerSocket::SetSendBufferSize(int32_t size) { | |
64 return socket_.SetSendBufferSize(size); | |
65 } | |
66 | |
67 int UDPServerSocket::SetDoNotFragment() { | |
68 return socket_.SetDoNotFragment(); | |
69 } | |
70 | |
71 void UDPServerSocket::Close() { | |
72 socket_.Close(); | |
73 } | |
74 | |
75 int UDPServerSocket::GetPeerAddress(IPEndPoint* address) const { | |
76 return socket_.GetPeerAddress(address); | |
77 } | |
78 | |
79 int UDPServerSocket::GetLocalAddress(IPEndPoint* address) const { | |
80 return socket_.GetLocalAddress(address); | |
81 } | |
82 | |
83 const NetLogWithSource& UDPServerSocket::NetLog() const { | |
84 return socket_.NetLog(); | |
85 } | |
86 | |
87 void UDPServerSocket::AllowAddressReuse() { | |
88 allow_address_reuse_ = true; | |
89 } | |
90 | |
91 void UDPServerSocket::AllowBroadcast() { | |
92 allow_broadcast_ = true; | |
93 } | |
94 | |
95 int UDPServerSocket::JoinGroup(const IPAddress& group_address) const { | |
96 return socket_.JoinGroup(group_address); | |
97 } | |
98 | |
99 int UDPServerSocket::LeaveGroup(const IPAddress& group_address) const { | |
100 return socket_.LeaveGroup(group_address); | |
101 } | |
102 | |
103 int UDPServerSocket::SetMulticastInterface(uint32_t interface_index) { | |
104 return socket_.SetMulticastInterface(interface_index); | |
105 } | |
106 | |
107 int UDPServerSocket::SetMulticastTimeToLive(int time_to_live) { | |
108 return socket_.SetMulticastTimeToLive(time_to_live); | |
109 } | |
110 | |
111 int UDPServerSocket::SetMulticastLoopbackMode(bool loopback) { | |
112 return socket_.SetMulticastLoopbackMode(loopback); | |
113 } | |
114 | |
115 int UDPServerSocket::SetDiffServCodePoint(DiffServCodePoint dscp) { | |
116 return socket_.SetDiffServCodePoint(dscp); | |
117 } | |
118 | |
119 void UDPServerSocket::DetachFromThread() { | |
120 socket_.DetachFromThread(); | |
121 } | |
122 | |
123 void UDPServerSocket::UseNonBlockingIO() { | |
124 #if defined(OS_WIN) | |
125 socket_.UseNonBlockingIO(); | |
126 #endif | |
127 } | |
128 | |
129 } // namespace net | |
OLD | NEW |