OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/udp/udp_server_socket.h" | 5 #include "net/udp/udp_server_socket.h" |
6 | 6 |
| 7 #include "net/base/net_errors.h" |
7 #include "net/base/rand_callback.h" | 8 #include "net/base/rand_callback.h" |
8 | 9 |
9 namespace net { | 10 namespace net { |
10 | 11 |
11 UDPServerSocket::UDPServerSocket(net::NetLog* net_log, | 12 UDPServerSocket::UDPServerSocket(net::NetLog* net_log, |
12 const net::NetLog::Source& source) | 13 const net::NetLog::Source& source) |
13 : socket_(DatagramSocket::DEFAULT_BIND, | 14 : socket_(DatagramSocket::DEFAULT_BIND, |
14 RandIntCallback(), | 15 RandIntCallback(), |
15 net_log, | 16 net_log, |
16 source) { | 17 source), |
| 18 allow_broadcast_(false) { |
17 } | 19 } |
18 | 20 |
19 UDPServerSocket::~UDPServerSocket() { | 21 UDPServerSocket::~UDPServerSocket() { |
20 } | 22 } |
21 | 23 |
22 int UDPServerSocket::Listen(const IPEndPoint& address) { | 24 int UDPServerSocket::Listen(const IPEndPoint& address) { |
| 25 int rv = socket_.Open(address.GetFamily()); |
| 26 if (rv != OK) |
| 27 return rv; |
| 28 |
| 29 if (allow_broadcast_) { |
| 30 rv = socket_.SetBroadcast(true); |
| 31 if (rv != OK) { |
| 32 socket_.Close(); |
| 33 return rv; |
| 34 } |
| 35 } |
| 36 |
23 return socket_.Bind(address); | 37 return socket_.Bind(address); |
24 } | 38 } |
25 | 39 |
26 int UDPServerSocket::RecvFrom(IOBuffer* buf, | 40 int UDPServerSocket::RecvFrom(IOBuffer* buf, |
27 int buf_len, | 41 int buf_len, |
28 IPEndPoint* address, | 42 IPEndPoint* address, |
29 const CompletionCallback& callback) { | 43 const CompletionCallback& callback) { |
30 return socket_.RecvFrom(buf, buf_len, address, callback); | 44 return socket_.RecvFrom(buf, buf_len, address, callback); |
31 } | 45 } |
32 | 46 |
(...skipping 26 matching lines...) Expand all Loading... |
59 | 73 |
60 const BoundNetLog& UDPServerSocket::NetLog() const { | 74 const BoundNetLog& UDPServerSocket::NetLog() const { |
61 return socket_.NetLog(); | 75 return socket_.NetLog(); |
62 } | 76 } |
63 | 77 |
64 void UDPServerSocket::AllowAddressReuse() { | 78 void UDPServerSocket::AllowAddressReuse() { |
65 socket_.AllowAddressReuse(); | 79 socket_.AllowAddressReuse(); |
66 } | 80 } |
67 | 81 |
68 void UDPServerSocket::AllowBroadcast() { | 82 void UDPServerSocket::AllowBroadcast() { |
69 socket_.AllowBroadcast(); | 83 allow_broadcast_ = true; |
70 } | 84 } |
71 | 85 |
72 int UDPServerSocket::JoinGroup(const IPAddressNumber& group_address) const { | 86 int UDPServerSocket::JoinGroup(const IPAddressNumber& group_address) const { |
73 return socket_.JoinGroup(group_address); | 87 return socket_.JoinGroup(group_address); |
74 } | 88 } |
75 | 89 |
76 int UDPServerSocket::LeaveGroup(const IPAddressNumber& group_address) const { | 90 int UDPServerSocket::LeaveGroup(const IPAddressNumber& group_address) const { |
77 return socket_.LeaveGroup(group_address); | 91 return socket_.LeaveGroup(group_address); |
78 } | 92 } |
79 | 93 |
(...skipping 11 matching lines...) Expand all Loading... |
91 | 105 |
92 int UDPServerSocket::SetDiffServCodePoint(DiffServCodePoint dscp) { | 106 int UDPServerSocket::SetDiffServCodePoint(DiffServCodePoint dscp) { |
93 return socket_.SetDiffServCodePoint(dscp); | 107 return socket_.SetDiffServCodePoint(dscp); |
94 } | 108 } |
95 | 109 |
96 void UDPServerSocket::DetachFromThread() { | 110 void UDPServerSocket::DetachFromThread() { |
97 socket_.DetachFromThread(); | 111 socket_.DetachFromThread(); |
98 } | 112 } |
99 | 113 |
100 } // namespace net | 114 } // namespace net |
OLD | NEW |