OLD | NEW |
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 #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 | 7 |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 | 97 |
98 // Set the send buffer size (in bytes) for the socket. | 98 // Set the send buffer size (in bytes) for the socket. |
99 bool SetSendBufferSize(int32 size); | 99 bool SetSendBufferSize(int32 size); |
100 | 100 |
101 // Returns true if the socket is already connected or bound. | 101 // Returns true if the socket is already connected or bound. |
102 bool is_connected() const { return socket_ != kInvalidSocket; } | 102 bool is_connected() const { return socket_ != kInvalidSocket; } |
103 | 103 |
104 const BoundNetLog& NetLog() const { return net_log_; } | 104 const BoundNetLog& NetLog() const { return net_log_; } |
105 | 105 |
106 // Sets corresponding flags in |socket_options_| to allow the socket | 106 // Sets corresponding flags in |socket_options_| to allow the socket |
107 // to share the local address to which socket will be bound with | 107 // to share the local address to which the socket will be bound with |
108 // other processes. Should be called before Bind(). | 108 // other processes. Should be called before Bind(). |
109 void AllowAddressReuse(); | 109 void AllowAddressReuse(); |
110 | 110 |
111 // Sets corresponding flags in |socket_options_| to allow sending | 111 // Sets corresponding flags in |socket_options_| to allow sending |
112 // and receiving packets sent to and from broadcast | 112 // and receiving packets to and from broadcast addresses. Should be |
113 // addresses. Should be called before Bind(). | 113 // called before Bind(). |
114 void AllowBroadcast(); | 114 void AllowBroadcast(); |
115 | 115 |
116 private: | 116 private: |
117 static const int kInvalidSocket = -1; | 117 static const int kInvalidSocket = -1; |
118 | 118 |
119 enum SocketOptions { | 119 enum SocketOptions { |
120 SOCKET_OPTION_REUSE_ADDRESS = 1 << 0, | 120 SOCKET_OPTION_REUSE_ADDRESS = 1 << 0, |
121 SOCKET_OPTION_BROADCAST = 1 << 1 | 121 SOCKET_OPTION_BROADCAST = 1 << 1 |
122 }; | 122 }; |
123 | 123 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 int InternalSendTo(IOBuffer* buf, int buf_len, const IPEndPoint* address); | 188 int InternalSendTo(IOBuffer* buf, int buf_len, const IPEndPoint* address); |
189 | 189 |
190 // Applies |socket_options_| to |socket_|. Should be called before | 190 // Applies |socket_options_| to |socket_|. Should be called before |
191 // Bind(). | 191 // Bind(). |
192 int SetSocketOptions(); | 192 int SetSocketOptions(); |
193 int DoBind(const IPEndPoint& address); | 193 int DoBind(const IPEndPoint& address); |
194 int RandomBind(const IPEndPoint& address); | 194 int RandomBind(const IPEndPoint& address); |
195 | 195 |
196 int socket_; | 196 int socket_; |
197 | 197 |
198 // Bitwise-or'd combination of SocketOptions. Specifies set of | 198 // Bitwise-or'd combination of SocketOptions. Specifies the set of |
199 // options that should be applied to |socket_| before bind. | 199 // options that should be applied to |socket_| before Bind(). |
200 int socket_options_; | 200 int socket_options_; |
201 | 201 |
202 // How to do source port binding, used only when UDPSocket is part of | 202 // How to do source port binding, used only when UDPSocket is part of |
203 // UDPClientSocket, since UDPServerSocket provides Bind. | 203 // UDPClientSocket, since UDPServerSocket provides Bind. |
204 DatagramSocket::BindType bind_type_; | 204 DatagramSocket::BindType bind_type_; |
205 | 205 |
206 // PRNG function for generating port numbers. | 206 // PRNG function for generating port numbers. |
207 RandIntCallback rand_int_cb_; | 207 RandIntCallback rand_int_cb_; |
208 | 208 |
209 // These are mutable since they're just cached copies to make | 209 // These are mutable since they're just cached copies to make |
(...skipping 26 matching lines...) Expand all Loading... |
236 CompletionCallback write_callback_; | 236 CompletionCallback write_callback_; |
237 | 237 |
238 BoundNetLog net_log_; | 238 BoundNetLog net_log_; |
239 | 239 |
240 DISALLOW_COPY_AND_ASSIGN(UDPSocketLibevent); | 240 DISALLOW_COPY_AND_ASSIGN(UDPSocketLibevent); |
241 }; | 241 }; |
242 | 242 |
243 } // namespace net | 243 } // namespace net |
244 | 244 |
245 #endif // NET_UDP_UDP_SOCKET_LIBEVENT_H_ | 245 #endif // NET_UDP_UDP_SOCKET_LIBEVENT_H_ |
OLD | NEW |