OLD | NEW |
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 Loading... |
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 // Handle stats and logging. |
| 148 void ProcessSuccessfulRead(int num_bytes, const char* bytes, |
| 149 const IPEndPoint* address) const; |
| 150 void ProcessSuccessfulWrite(int num_bytes, const char* bytes, |
| 151 const IPEndPoint* address) const; |
| 152 |
148 // Returns the OS error code (or 0 on success). | 153 // Returns the OS error code (or 0 on success). |
149 int CreateSocket(const IPEndPoint& address); | 154 int CreateSocket(const IPEndPoint& address); |
150 | 155 |
151 // Same as SendTo(), except that address is passed by pointer | 156 // Same as SendTo(), except that address is passed by pointer |
152 // instead of by reference. It is called from Write() with |address| | 157 // instead of by reference. It is called from Write() with |address| |
153 // set to NULL. | 158 // set to NULL. |
154 int SendToOrWrite(IOBuffer* buf, | 159 int SendToOrWrite(IOBuffer* buf, |
155 int buf_len, | 160 int buf_len, |
156 const IPEndPoint* address, | 161 const IPEndPoint* address, |
157 OldCompletionCallback* callback); | 162 OldCompletionCallback* callback); |
158 | 163 |
| 164 int InternalConnect(const IPEndPoint& address); |
159 int InternalRecvFrom(IOBuffer* buf, int buf_len, IPEndPoint* address); | 165 int InternalRecvFrom(IOBuffer* buf, int buf_len, IPEndPoint* address); |
160 int InternalSendTo(IOBuffer* buf, int buf_len, const IPEndPoint* address); | 166 int InternalSendTo(IOBuffer* buf, int buf_len, const IPEndPoint* address); |
161 | 167 |
162 int DoBind(const IPEndPoint& address); | 168 int DoBind(const IPEndPoint& address); |
163 int RandomBind(const IPEndPoint& address); | 169 int RandomBind(const IPEndPoint& address); |
164 | 170 |
165 int socket_; | 171 int socket_; |
166 | 172 |
167 // How to do source port binding, used only when UDPSocket is part of | 173 // How to do source port binding, used only when UDPSocket is part of |
168 // UDPClientSocket, since UDPServerSocket provides Bind. | 174 // UDPClientSocket, since UDPServerSocket provides Bind. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 OldCompletionCallback* write_callback_; | 207 OldCompletionCallback* write_callback_; |
202 | 208 |
203 BoundNetLog net_log_; | 209 BoundNetLog net_log_; |
204 | 210 |
205 DISALLOW_COPY_AND_ASSIGN(UDPSocketLibevent); | 211 DISALLOW_COPY_AND_ASSIGN(UDPSocketLibevent); |
206 }; | 212 }; |
207 | 213 |
208 } // namespace net | 214 } // namespace net |
209 | 215 |
210 #endif // NET_UDP_UDP_SOCKET_LIBEVENT_H_ | 216 #endif // NET_UDP_UDP_SOCKET_LIBEVENT_H_ |
OLD | NEW |