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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 UDPSocketLibevent* const socket_; | 143 UDPSocketLibevent* const socket_; |
145 | 144 |
146 DISALLOW_COPY_AND_ASSIGN(WriteWatcher); | 145 DISALLOW_COPY_AND_ASSIGN(WriteWatcher); |
147 }; | 146 }; |
148 | 147 |
149 void DoReadCallback(int rv); | 148 void DoReadCallback(int rv); |
150 void DoWriteCallback(int rv); | 149 void DoWriteCallback(int rv); |
151 void DidCompleteRead(); | 150 void DidCompleteRead(); |
152 void DidCompleteWrite(); | 151 void DidCompleteWrite(); |
153 | 152 |
| 153 // Handles stats and logging. |result| is the number of bytes transferred, on |
| 154 // success, or the net error code on failure. On success, LogRead takes in a |
| 155 // sockaddr and its length, which are mandatory, while LogWrite takes in an |
| 156 // optional IPEndPoint. |
| 157 void LogRead(int result, const char* bytes, socklen_t addr_len, |
| 158 const sockaddr* addr) const; |
| 159 void LogWrite(int result, const char* bytes, const IPEndPoint* address) const; |
| 160 |
154 // Returns the OS error code (or 0 on success). | 161 // Returns the OS error code (or 0 on success). |
155 int CreateSocket(const IPEndPoint& address); | 162 int CreateSocket(const IPEndPoint& address); |
156 | 163 |
157 // Same as SendTo(), except that address is passed by pointer | 164 // Same as SendTo(), except that address is passed by pointer |
158 // instead of by reference. It is called from Write() with |address| | 165 // instead of by reference. It is called from Write() with |address| |
159 // set to NULL. | 166 // set to NULL. |
160 int SendToOrWrite(IOBuffer* buf, | 167 int SendToOrWrite(IOBuffer* buf, |
161 int buf_len, | 168 int buf_len, |
162 const IPEndPoint* address, | 169 const IPEndPoint* address, |
163 OldCompletionCallback* callback); | 170 OldCompletionCallback* callback); |
164 | 171 |
| 172 int InternalConnect(const IPEndPoint& address); |
165 int InternalRecvFrom(IOBuffer* buf, int buf_len, IPEndPoint* address); | 173 int InternalRecvFrom(IOBuffer* buf, int buf_len, IPEndPoint* address); |
166 int InternalSendTo(IOBuffer* buf, int buf_len, const IPEndPoint* address); | 174 int InternalSendTo(IOBuffer* buf, int buf_len, const IPEndPoint* address); |
167 | 175 |
168 int DoBind(const IPEndPoint& address); | 176 int DoBind(const IPEndPoint& address); |
169 int RandomBind(const IPEndPoint& address); | 177 int RandomBind(const IPEndPoint& address); |
170 | 178 |
171 int socket_; | 179 int socket_; |
172 | 180 |
173 // How to do source port binding, used only when UDPSocket is part of | 181 // How to do source port binding, used only when UDPSocket is part of |
174 // UDPClientSocket, since UDPServerSocket provides Bind. | 182 // UDPClientSocket, since UDPServerSocket provides Bind. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 OldCompletionCallback* write_callback_; | 215 OldCompletionCallback* write_callback_; |
208 | 216 |
209 BoundNetLog net_log_; | 217 BoundNetLog net_log_; |
210 | 218 |
211 DISALLOW_COPY_AND_ASSIGN(UDPSocketLibevent); | 219 DISALLOW_COPY_AND_ASSIGN(UDPSocketLibevent); |
212 }; | 220 }; |
213 | 221 |
214 } // namespace net | 222 } // namespace net |
215 | 223 |
216 #endif // NET_UDP_UDP_SOCKET_LIBEVENT_H_ | 224 #endif // NET_UDP_UDP_SOCKET_LIBEVENT_H_ |
OLD | NEW |