| 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::NetLog::Source& source) | |
| 14 : socket_(DatagramSocket::DEFAULT_BIND, | |
| 15 RandIntCallback(), | |
| 16 net_log, | |
| 17 source), | |
| 18 allow_address_reuse_(false), | |
| 19 allow_broadcast_(false) { | |
| 20 } | |
| 21 | |
| 22 UDPServerSocket::~UDPServerSocket() { | |
| 23 } | |
| 24 | |
| 25 int UDPServerSocket::Listen(const IPEndPoint& address) { | |
| 26 int rv = socket_.Open(address.GetFamily()); | |
| 27 if (rv != OK) | |
| 28 return rv; | |
| 29 | |
| 30 if (allow_address_reuse_) { | |
| 31 rv = socket_.AllowAddressReuse(); | |
| 32 if (rv != OK) { | |
| 33 socket_.Close(); | |
| 34 return rv; | |
| 35 } | |
| 36 } | |
| 37 | |
| 38 if (allow_broadcast_) { | |
| 39 rv = socket_.SetBroadcast(true); | |
| 40 if (rv != OK) { | |
| 41 socket_.Close(); | |
| 42 return rv; | |
| 43 } | |
| 44 } | |
| 45 | |
| 46 return socket_.Bind(address); | |
| 47 } | |
| 48 | |
| 49 int UDPServerSocket::RecvFrom(IOBuffer* buf, | |
| 50 int buf_len, | |
| 51 IPEndPoint* address, | |
| 52 const CompletionCallback& callback) { | |
| 53 return socket_.RecvFrom(buf, buf_len, address, callback); | |
| 54 } | |
| 55 | |
| 56 int UDPServerSocket::SendTo(IOBuffer* buf, | |
| 57 int buf_len, | |
| 58 const IPEndPoint& address, | |
| 59 const CompletionCallback& callback) { | |
| 60 return socket_.SendTo(buf, buf_len, address, callback); | |
| 61 } | |
| 62 | |
| 63 int UDPServerSocket::SetReceiveBufferSize(int32 size) { | |
| 64 return socket_.SetReceiveBufferSize(size); | |
| 65 } | |
| 66 | |
| 67 int UDPServerSocket::SetSendBufferSize(int32 size) { | |
| 68 return socket_.SetSendBufferSize(size); | |
| 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 BoundNetLog& 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 IPAddressNumber& group_address) const { | |
| 96 return socket_.JoinGroup(group_address); | |
| 97 } | |
| 98 | |
| 99 int UDPServerSocket::LeaveGroup(const IPAddressNumber& group_address) const { | |
| 100 return socket_.LeaveGroup(group_address); | |
| 101 } | |
| 102 | |
| 103 int UDPServerSocket::SetMulticastInterface(uint32 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 #if defined(OS_WIN) | |
| 124 void UDPServerSocket::UseNonBlockingIO() { | |
| 125 socket_.UseNonBlockingIO(); | |
| 126 } | |
| 127 #endif | |
| 128 | |
| 129 } // namespace net | |
| OLD | NEW |