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_socket_libevent.h" | 5 #include "net/udp/udp_socket_libevent.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <netdb.h> | 9 #include <netdb.h> |
10 #include <net/if.h> | 10 #include <net/if.h> |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 } | 308 } |
309 rv = DoBind(address); | 309 rv = DoBind(address); |
310 if (rv < 0) { | 310 if (rv < 0) { |
311 Close(); | 311 Close(); |
312 return rv; | 312 return rv; |
313 } | 313 } |
314 local_address_.reset(); | 314 local_address_.reset(); |
315 return rv; | 315 return rv; |
316 } | 316 } |
317 | 317 |
318 bool UDPSocketLibevent::SetReceiveBufferSize(int32 size) { | 318 int UDPSocketLibevent::SetReceiveBufferSize(int32 size) { |
319 DCHECK(CalledOnValidThread()); | 319 DCHECK(CalledOnValidThread()); |
320 int rv = setsockopt(socket_, SOL_SOCKET, SO_RCVBUF, | 320 int rv = setsockopt(socket_, SOL_SOCKET, SO_RCVBUF, |
321 reinterpret_cast<const char*>(&size), sizeof(size)); | 321 reinterpret_cast<const char*>(&size), sizeof(size)); |
322 DCHECK(!rv) << "Could not set socket receive buffer size: " << errno; | 322 int last_error = errno; |
323 return rv == 0; | 323 DCHECK(!rv) << "Could not set socket receive buffer size: " << last_error; |
| 324 return rv == 0 ? OK : MapSystemError(last_error); |
324 } | 325 } |
325 | 326 |
326 bool UDPSocketLibevent::SetSendBufferSize(int32 size) { | 327 int UDPSocketLibevent::SetSendBufferSize(int32 size) { |
327 DCHECK(CalledOnValidThread()); | 328 DCHECK(CalledOnValidThread()); |
328 int rv = setsockopt(socket_, SOL_SOCKET, SO_SNDBUF, | 329 int rv = setsockopt(socket_, SOL_SOCKET, SO_SNDBUF, |
329 reinterpret_cast<const char*>(&size), sizeof(size)); | 330 reinterpret_cast<const char*>(&size), sizeof(size)); |
330 DCHECK(!rv) << "Could not set socket send buffer size: " << errno; | 331 int last_error = errno; |
331 return rv == 0; | 332 DCHECK(!rv) << "Could not set socket send buffer size: " << last_error; |
| 333 return rv == 0 ? OK : MapSystemError(last_error); |
332 } | 334 } |
333 | 335 |
334 void UDPSocketLibevent::AllowAddressReuse() { | 336 void UDPSocketLibevent::AllowAddressReuse() { |
335 DCHECK(CalledOnValidThread()); | 337 DCHECK(CalledOnValidThread()); |
336 DCHECK(!is_connected()); | 338 DCHECK(!is_connected()); |
337 | 339 |
338 socket_options_ |= SOCKET_OPTION_REUSE_ADDRESS; | 340 socket_options_ |= SOCKET_OPTION_REUSE_ADDRESS; |
339 } | 341 } |
340 | 342 |
341 void UDPSocketLibevent::AllowBroadcast() { | 343 void UDPSocketLibevent::AllowBroadcast() { |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
765 return MapSystemError(errno); | 767 return MapSystemError(errno); |
766 | 768 |
767 return OK; | 769 return OK; |
768 } | 770 } |
769 | 771 |
770 void UDPSocketLibevent::DetachFromThread() { | 772 void UDPSocketLibevent::DetachFromThread() { |
771 base::NonThreadSafe::DetachFromThread(); | 773 base::NonThreadSafe::DetachFromThread(); |
772 } | 774 } |
773 | 775 |
774 } // namespace net | 776 } // namespace net |
OLD | NEW |