Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(182)

Side by Side Diff: net/udp/udp_socket_libevent.cc

Issue 935333002: Update from https://crrev.com/316786 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/tools/tld_cleanup/tld_cleanup.gyp ('k') | net/udp/udp_socket_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
11 #include <netinet/in.h> 11 #include <netinet/in.h>
12 #include <sys/ioctl.h> 12 #include <sys/ioctl.h>
13 #include <sys/socket.h> 13 #include <sys/socket.h>
14 14
15 #include "base/callback.h" 15 #include "base/callback.h"
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/message_loop/message_loop.h" 17 #include "base/message_loop/message_loop.h"
18 #include "base/metrics/sparse_histogram.h" 18 #include "base/metrics/sparse_histogram.h"
19 #include "base/metrics/stats_counters.h"
20 #include "base/posix/eintr_wrapper.h" 19 #include "base/posix/eintr_wrapper.h"
21 #include "base/rand_util.h" 20 #include "base/rand_util.h"
22 #include "net/base/io_buffer.h" 21 #include "net/base/io_buffer.h"
23 #include "net/base/ip_endpoint.h" 22 #include "net/base/ip_endpoint.h"
24 #include "net/base/net_errors.h" 23 #include "net/base/net_errors.h"
25 #include "net/base/net_log.h" 24 #include "net/base/net_log.h"
26 #include "net/base/net_util.h" 25 #include "net/base/net_util.h"
27 #include "net/base/network_activity_monitor.h" 26 #include "net/base/network_activity_monitor.h"
28 #include "net/socket/socket_descriptor.h" 27 #include "net/socket/socket_descriptor.h"
29 #include "net/udp/udp_net_log_parameters.h" 28 #include "net/udp/udp_net_log_parameters.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 write_buf_ = NULL; 119 write_buf_ = NULL;
121 write_buf_len_ = 0; 120 write_buf_len_ = 0;
122 write_callback_.Reset(); 121 write_callback_.Reset();
123 send_to_address_.reset(); 122 send_to_address_.reset();
124 123
125 bool ok = read_socket_watcher_.StopWatchingFileDescriptor(); 124 bool ok = read_socket_watcher_.StopWatchingFileDescriptor();
126 DCHECK(ok); 125 DCHECK(ok);
127 ok = write_socket_watcher_.StopWatchingFileDescriptor(); 126 ok = write_socket_watcher_.StopWatchingFileDescriptor();
128 DCHECK(ok); 127 DCHECK(ok);
129 128
130 if (IGNORE_EINTR(close(socket_)) < 0) 129 PCHECK(0 == IGNORE_EINTR(close(socket_)));
131 PLOG(ERROR) << "close";
132 130
133 socket_ = kInvalidSocket; 131 socket_ = kInvalidSocket;
134 addr_family_ = 0; 132 addr_family_ = 0;
135 is_connected_ = false; 133 is_connected_ = false;
136 } 134 }
137 135
138 int UDPSocketLibevent::GetPeerAddress(IPEndPoint* address) const { 136 int UDPSocketLibevent::GetPeerAddress(IPEndPoint* address) const {
139 DCHECK(CalledOnValidThread()); 137 DCHECK(CalledOnValidThread());
140 DCHECK(address); 138 DCHECK(address);
141 if (!is_connected()) 139 if (!is_connected())
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 419
422 IPEndPoint address; 420 IPEndPoint address;
423 bool is_address_valid = address.FromSockAddr(addr, addr_len); 421 bool is_address_valid = address.FromSockAddr(addr, addr_len);
424 net_log_.AddEvent( 422 net_log_.AddEvent(
425 NetLog::TYPE_UDP_BYTES_RECEIVED, 423 NetLog::TYPE_UDP_BYTES_RECEIVED,
426 CreateNetLogUDPDataTranferCallback( 424 CreateNetLogUDPDataTranferCallback(
427 result, bytes, 425 result, bytes,
428 is_address_valid ? &address : NULL)); 426 is_address_valid ? &address : NULL));
429 } 427 }
430 428
431 base::StatsCounter read_bytes("udp.read_bytes");
432 read_bytes.Add(result);
433 NetworkActivityMonitor::GetInstance()->IncrementBytesReceived(result); 429 NetworkActivityMonitor::GetInstance()->IncrementBytesReceived(result);
434 } 430 }
435 431
436 void UDPSocketLibevent::DidCompleteWrite() { 432 void UDPSocketLibevent::DidCompleteWrite() {
437 int result = 433 int result =
438 InternalSendTo(write_buf_.get(), write_buf_len_, send_to_address_.get()); 434 InternalSendTo(write_buf_.get(), write_buf_len_, send_to_address_.get());
439 435
440 if (result != ERR_IO_PENDING) { 436 if (result != ERR_IO_PENDING) {
441 write_buf_ = NULL; 437 write_buf_ = NULL;
442 write_buf_len_ = 0; 438 write_buf_len_ = 0;
(...skipping 10 matching lines...) Expand all
453 net_log_.AddEventWithNetErrorCode(NetLog::TYPE_UDP_SEND_ERROR, result); 449 net_log_.AddEventWithNetErrorCode(NetLog::TYPE_UDP_SEND_ERROR, result);
454 return; 450 return;
455 } 451 }
456 452
457 if (net_log_.IsLogging()) { 453 if (net_log_.IsLogging()) {
458 net_log_.AddEvent( 454 net_log_.AddEvent(
459 NetLog::TYPE_UDP_BYTES_SENT, 455 NetLog::TYPE_UDP_BYTES_SENT,
460 CreateNetLogUDPDataTranferCallback(result, bytes, address)); 456 CreateNetLogUDPDataTranferCallback(result, bytes, address));
461 } 457 }
462 458
463 base::StatsCounter write_bytes("udp.write_bytes");
464 write_bytes.Add(result);
465 NetworkActivityMonitor::GetInstance()->IncrementBytesSent(result); 459 NetworkActivityMonitor::GetInstance()->IncrementBytesSent(result);
466 } 460 }
467 461
468 int UDPSocketLibevent::InternalRecvFrom(IOBuffer* buf, int buf_len, 462 int UDPSocketLibevent::InternalRecvFrom(IOBuffer* buf, int buf_len,
469 IPEndPoint* address) { 463 IPEndPoint* address) {
470 int bytes_transferred; 464 int bytes_transferred;
471 int flags = 0; 465 int flags = 0;
472 466
473 SockaddrStorage storage; 467 SockaddrStorage storage;
474 468
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 return MapSystemError(errno); 743 return MapSystemError(errno);
750 744
751 return OK; 745 return OK;
752 } 746 }
753 747
754 void UDPSocketLibevent::DetachFromThread() { 748 void UDPSocketLibevent::DetachFromThread() {
755 base::NonThreadSafe::DetachFromThread(); 749 base::NonThreadSafe::DetachFromThread();
756 } 750 }
757 751
758 } // namespace net 752 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/tld_cleanup/tld_cleanup.gyp ('k') | net/udp/udp_socket_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698