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

Unified Diff: net/udp/udp_socket_libevent.cc

Issue 8200011: Add NetLog support to UDP sockets. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Update year Created 9 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: net/udp/udp_socket_libevent.cc
===================================================================
--- net/udp/udp_socket_libevent.cc (revision 104713)
+++ net/udp/udp_socket_libevent.cc (working copy)
@@ -19,6 +19,7 @@
#include "net/base/net_errors.h"
#include "net/base/net_log.h"
#include "net/base/net_util.h"
+#include "net/udp/udp_data_transfer_param.h"
#if defined(OS_POSIX)
#include <netinet/in.h>
#endif
@@ -48,7 +49,7 @@
write_buf_len_(0),
read_callback_(NULL),
write_callback_(NULL),
- net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SOCKET)) {
+ net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_UDP_SOCKET)) {
scoped_refptr<NetLog::EventParameters> params;
if (source.is_valid())
params = new NetLogSourceParameter("source_dependency", source);
@@ -151,14 +152,21 @@
DCHECK_GT(buf_len, 0);
int nread = InternalRecvFrom(buf, buf_len, address);
- if (nread != ERR_IO_PENDING)
+ if (nread != ERR_IO_PENDING) {
+ if (nread < 0) {
+ net_log_.AddEventWithNetErrorCode(NetLog::TYPE_UDP_RECEIVE_ERROR, nread);
+ }
return nread;
+ }
if (!MessageLoopForIO::current()->WatchFileDescriptor(
socket_, true, MessageLoopForIO::WATCH_READ,
&read_socket_watcher_, &read_watcher_)) {
PLOG(ERROR) << "WatchFileDescriptor failed on read";
- return MapSystemError(errno);
+ int net_error = MapSystemError(errno);
+ net_log_.AddEventWithNetErrorCode(NetLog::TYPE_UDP_RECEIVE_ERROR,
+ net_error);
+ return net_error;
}
read_buf_ = buf;
@@ -193,18 +201,24 @@
int nwrite = InternalSendTo(buf, buf_len, address);
if (nwrite >= 0) {
- base::StatsCounter write_bytes("udp.write_bytes");
- write_bytes.Add(nwrite);
+ ProcessSuccessfulWrite(nwrite, buf->data(), address);
return nwrite;
}
- if (errno != EAGAIN && errno != EWOULDBLOCK)
- return MapSystemError(errno);
+ if (errno != EAGAIN && errno != EWOULDBLOCK) {
+ int net_error = MapSystemError(errno);
+ net_log_.AddEventWithNetErrorCode(NetLog::TYPE_UDP_SEND_ERROR,
+ net_error);
+ return net_error;
+ }
if (!MessageLoopForIO::current()->WatchFileDescriptor(
socket_, true, MessageLoopForIO::WATCH_WRITE,
&write_socket_watcher_, &write_watcher_)) {
DVLOG(1) << "WatchFileDescriptor failed on write, errno " << errno;
- return MapSystemError(errno);
+ int net_error = MapSystemError(errno);
+ net_log_.AddEventWithNetErrorCode(NetLog::TYPE_UDP_SEND_ERROR,
+ net_error);
+ return net_error;
}
write_buf_ = buf;
@@ -218,6 +232,16 @@
}
int UDPSocketLibevent::Connect(const IPEndPoint& address) {
+ net_log_.BeginEvent(
+ NetLog::TYPE_UDP_CONNECT,
+ make_scoped_refptr(new NetLogStringParameter("address",
+ address.ToString())));
+ int rv = InternalConnect(address);
+ net_log_.EndEventWithNetErrorCode(NetLog::TYPE_UDP_CONNECT, rv);
+ return rv;
+}
+
+int UDPSocketLibevent::InternalConnect(const IPEndPoint& address) {
DCHECK(!is_connected());
DCHECK(!remote_address_.get());
int rv = CreateSocket(address);
@@ -289,6 +313,20 @@
}
}
+void UDPSocketLibevent::ProcessSuccessfulRead(int num_bytes,
+ const char* bytes,
+ const IPEndPoint* address) const {
+ base::StatsCounter read_bytes("udp.read_bytes");
+ read_bytes.Add(num_bytes);
+
+ net_log_.AddEvent(
Sergey Ulanov 2011/10/13 04:01:54 I think we should log this event only when log lev
mmenke 2011/10/13 14:37:23 Sounds reasonable to me. This was actually modell
+ NetLog::TYPE_UDP_BYTES_RECEIVED,
+ make_scoped_refptr(
+ new UDPDataTransferNetLogParam(num_bytes, bytes,
+ net_log_.IsLoggingBytes(),
+ address)));
+}
+
int UDPSocketLibevent::CreateSocket(const IPEndPoint& address) {
socket_ = socket(address.GetFamily(), SOCK_DGRAM, 0);
if (socket_ == kInvalidSocket)
@@ -305,10 +343,11 @@
int result = InternalSendTo(write_buf_, write_buf_len_,
send_to_address_.get());
if (result >= 0) {
- base::StatsCounter write_bytes("udp.write_bytes");
- write_bytes.Add(result);
+ ProcessSuccessfulWrite(result, write_buf_->data(), send_to_address_.get());
} else {
result = MapSystemError(errno);
+ if (result != ERR_IO_PENDING)
+ net_log_.AddEventWithNetErrorCode(NetLog::TYPE_UDP_SEND_ERROR, result);
}
if (result != ERR_IO_PENDING) {
@@ -320,6 +359,20 @@
}
}
+void UDPSocketLibevent::ProcessSuccessfulWrite(
+ int num_bytes,
+ const char* bytes,
+ const IPEndPoint* address) const {
+ base::StatsCounter write_bytes("udp.write_bytes");
+ write_bytes.Add(num_bytes);
+ net_log_.AddEvent(
Sergey Ulanov 2011/10/13 04:01:54 same here.
mmenke 2011/10/13 14:37:23 Done.
+ NetLog::TYPE_UDP_BYTES_SENT,
+ make_scoped_refptr(
+ new UDPDataTransferNetLogParam(num_bytes, bytes,
+ net_log_.IsLoggingBytes(),
+ address)));
+}
+
int UDPSocketLibevent::InternalRecvFrom(IOBuffer* buf, int buf_len,
IPEndPoint* address) {
int bytes_transferred;
@@ -339,8 +392,7 @@
int result;
if (bytes_transferred >= 0) {
result = bytes_transferred;
- base::StatsCounter read_bytes("udp.read_bytes");
- read_bytes.Add(bytes_transferred);
+ ProcessSuccessfulRead(bytes_transferred, buf->data(), address);
if (address) {
if (!address->FromSockAddr(addr, addr_len))
result = ERR_FAILED;

Powered by Google App Engine
This is Rietveld 408576698