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

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

Issue 8200011: Add NetLog support to UDP sockets. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #ifndef NET_UDP_UDP_SOCKET_LIBEVENT_H_ 5 #ifndef NET_UDP_UDP_SOCKET_LIBEVENT_H_
6 #define NET_UDP_UDP_SOCKET_LIBEVENT_H_ 6 #define NET_UDP_UDP_SOCKET_LIBEVENT_H_
7 #pragma once 7 #pragma once
8 8
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/threading/non_thread_safe.h" 12 #include "base/threading/non_thread_safe.h"
13 #include "net/base/address_list_net_log_param.h"
13 #include "net/base/completion_callback.h" 14 #include "net/base/completion_callback.h"
14 #include "net/base/rand_callback.h" 15 #include "net/base/rand_callback.h"
15 #include "net/base/io_buffer.h" 16 #include "net/base/io_buffer.h"
16 #include "net/base/ip_endpoint.h" 17 #include "net/base/ip_endpoint.h"
17 #include "net/base/net_log.h" 18 #include "net/base/net_log.h"
18 #include "net/udp/datagram_socket.h" 19 #include "net/udp/datagram_socket.h"
19 20
20 namespace net { 21 namespace net {
21 22
22 class BoundNetLog;
23
24 class UDPSocketLibevent : public base::NonThreadSafe { 23 class UDPSocketLibevent : public base::NonThreadSafe {
25 public: 24 public:
26 UDPSocketLibevent(DatagramSocket::BindType bind_type, 25 UDPSocketLibevent(DatagramSocket::BindType bind_type,
27 const RandIntCallback& rand_int_cb, 26 const RandIntCallback& rand_int_cb,
28 net::NetLog* net_log, 27 net::NetLog* net_log,
29 const net::NetLog::Source& source); 28 const net::NetLog::Source& source);
30 virtual ~UDPSocketLibevent(); 29 virtual ~UDPSocketLibevent();
31 30
32 // Connect the socket to connect with a certain |address|. 31 // Connect the socket to connect with a certain |address|.
33 // Returns a net error code. 32 // Returns a net error code.
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 UDPSocketLibevent* const socket_; 137 UDPSocketLibevent* const socket_;
139 138
140 DISALLOW_COPY_AND_ASSIGN(WriteWatcher); 139 DISALLOW_COPY_AND_ASSIGN(WriteWatcher);
141 }; 140 };
142 141
143 void DoReadCallback(int rv); 142 void DoReadCallback(int rv);
144 void DoWriteCallback(int rv); 143 void DoWriteCallback(int rv);
145 void DidCompleteRead(); 144 void DidCompleteRead();
146 void DidCompleteWrite(); 145 void DidCompleteWrite();
147 146
147 // Handles stats and logging. |result| is the number of bytes transferred, on
148 // success, or the net error code on failure. Returns |result|.
149 // On success, LogRead takes in a sockaddr and its length, which are
150 // mandatory, while LogWrite takes in an optional IPEndPoint.
151 int LogRead(int result, const char* bytes, socklen_t addr_len,
152 const sockaddr* addr) const;
153 int LogWrite(int result, const char* bytes, const IPEndPoint* address) const;
154
148 // Returns the OS error code (or 0 on success). 155 // Returns the OS error code (or 0 on success).
149 int CreateSocket(const IPEndPoint& address); 156 int CreateSocket(const IPEndPoint& address);
150 157
151 // Same as SendTo(), except that address is passed by pointer 158 // Same as SendTo(), except that address is passed by pointer
152 // instead of by reference. It is called from Write() with |address| 159 // instead of by reference. It is called from Write() with |address|
153 // set to NULL. 160 // set to NULL.
154 int SendToOrWrite(IOBuffer* buf, 161 int SendToOrWrite(IOBuffer* buf,
155 int buf_len, 162 int buf_len,
156 const IPEndPoint* address, 163 const IPEndPoint* address,
157 OldCompletionCallback* callback); 164 OldCompletionCallback* callback);
158 165
166 int InternalConnect(const IPEndPoint& address);
159 int InternalRecvFrom(IOBuffer* buf, int buf_len, IPEndPoint* address); 167 int InternalRecvFrom(IOBuffer* buf, int buf_len, IPEndPoint* address);
160 int InternalSendTo(IOBuffer* buf, int buf_len, const IPEndPoint* address); 168 int InternalSendTo(IOBuffer* buf, int buf_len, const IPEndPoint* address);
161 169
162 int DoBind(const IPEndPoint& address); 170 int DoBind(const IPEndPoint& address);
163 int RandomBind(const IPEndPoint& address); 171 int RandomBind(const IPEndPoint& address);
164 172
165 int socket_; 173 int socket_;
166 174
167 // How to do source port binding, used only when UDPSocket is part of 175 // How to do source port binding, used only when UDPSocket is part of
168 // UDPClientSocket, since UDPServerSocket provides Bind. 176 // UDPClientSocket, since UDPServerSocket provides Bind.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 OldCompletionCallback* write_callback_; 209 OldCompletionCallback* write_callback_;
202 210
203 BoundNetLog net_log_; 211 BoundNetLog net_log_;
204 212
205 DISALLOW_COPY_AND_ASSIGN(UDPSocketLibevent); 213 DISALLOW_COPY_AND_ASSIGN(UDPSocketLibevent);
206 }; 214 };
207 215
208 } // namespace net 216 } // namespace net
209 217
210 #endif // NET_UDP_UDP_SOCKET_LIBEVENT_H_ 218 #endif // NET_UDP_UDP_SOCKET_LIBEVENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698