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/hash_tables.h" | |
8 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
11 #include "base/threading/non_thread_safe.h" | 12 #include "base/threading/non_thread_safe.h" |
12 #include "net/base/completion_callback.h" | 13 #include "net/base/completion_callback.h" |
13 #include "net/base/net_export.h" | 14 #include "net/base/net_export.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" |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
106 // Sets corresponding flags in |socket_options_| to allow the socket | 107 // Sets corresponding flags in |socket_options_| to allow the socket |
107 // to share the local address to which the socket will be bound with | 108 // to share the local address to which the socket will be bound with |
108 // other processes. Should be called before Bind(). | 109 // other processes. Should be called before Bind(). |
109 void AllowAddressReuse(); | 110 void AllowAddressReuse(); |
110 | 111 |
111 // Sets corresponding flags in |socket_options_| to allow sending | 112 // Sets corresponding flags in |socket_options_| to allow sending |
112 // and receiving packets to and from broadcast addresses. Should be | 113 // and receiving packets to and from broadcast addresses. Should be |
113 // called before Bind(). | 114 // called before Bind(). |
114 void AllowBroadcast(); | 115 void AllowBroadcast(); |
115 | 116 |
117 // Join the multicast group. | |
118 // |group_address| is the group address to join, could be either | |
119 // IPv4 or IPv6 address. | |
120 int JoinGroup(const net::IPAddressNumber& group_address) const; | |
121 | |
122 // Leave the multicast group. | |
123 // |group_address| is the group address to leave, could be either | |
124 // IPv4 or IPv6 address. If the socket hasn't joined the group, | |
125 // it will be ignored. | |
126 // It's optional to leave the multicast group before destroying | |
127 // the socket. It will be done by the OS. | |
128 int LeaveGroup(const net::IPAddressNumber& group_address) const; | |
129 | |
130 // Set the time-to-live option for udp packets sent to the multicast | |
131 // group address. Initially this value is 1. Cannot be negative or | |
132 // more than 255. | |
133 int SetMulticastTimeToLive(int time_to_live); | |
mmenke
2013/04/16 18:09:49
Think it's worth mentioned that this is safe to ca
Bei Zhang
2013/04/17 17:53:03
Please see comments in udp_socket_libevent.cc
On 2
| |
134 | |
135 // Set the loopback flag for udp socket. If this flag is true, the host | |
136 // will receive package sent to the joined group from itself. | |
137 // Initially this value is true. | |
138 int SetMulticastLoopbackMode(bool loopback); | |
139 | |
116 private: | 140 private: |
117 static const int kInvalidSocket = -1; | 141 static const int kInvalidSocket = -1; |
118 | 142 |
119 enum SocketOptions { | 143 enum SocketOptions { |
120 SOCKET_OPTION_REUSE_ADDRESS = 1 << 0, | 144 SOCKET_OPTION_REUSE_ADDRESS = 1 << 0, |
121 SOCKET_OPTION_BROADCAST = 1 << 1 | 145 SOCKET_OPTION_BROADCAST = 1 << 1 |
122 }; | 146 }; |
123 | 147 |
124 class ReadWatcher : public MessageLoopForIO::Watcher { | 148 class ReadWatcher : public MessageLoopForIO::Watcher { |
125 public: | 149 public: |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
181 int InternalRecvFrom(IOBuffer* buf, int buf_len, IPEndPoint* address); | 205 int InternalRecvFrom(IOBuffer* buf, int buf_len, IPEndPoint* address); |
182 int InternalSendTo(IOBuffer* buf, int buf_len, const IPEndPoint* address); | 206 int InternalSendTo(IOBuffer* buf, int buf_len, const IPEndPoint* address); |
183 | 207 |
184 // Applies |socket_options_| to |socket_|. Should be called before | 208 // Applies |socket_options_| to |socket_|. Should be called before |
185 // Bind(). | 209 // Bind(). |
186 int SetSocketOptions(); | 210 int SetSocketOptions(); |
187 int DoBind(const IPEndPoint& address); | 211 int DoBind(const IPEndPoint& address); |
188 int RandomBind(const IPEndPoint& address); | 212 int RandomBind(const IPEndPoint& address); |
189 | 213 |
190 int socket_; | 214 int socket_; |
215 int sock_addr_family_; | |
191 | 216 |
192 // Bitwise-or'd combination of SocketOptions. Specifies the set of | 217 // Bitwise-or'd combination of SocketOptions. Specifies the set of |
193 // options that should be applied to |socket_| before Bind(). | 218 // options that should be applied to |socket_| before Bind(). |
194 int socket_options_; | 219 int socket_options_; |
195 | 220 |
221 // Multicast socket options cached for SetSocketOption. | |
222 // Cannot be used after Bind(). | |
223 int multicast_time_to_live_; | |
224 bool multicast_loopback_mode_; | |
225 | |
196 // How to do source port binding, used only when UDPSocket is part of | 226 // How to do source port binding, used only when UDPSocket is part of |
197 // UDPClientSocket, since UDPServerSocket provides Bind. | 227 // UDPClientSocket, since UDPServerSocket provides Bind. |
198 DatagramSocket::BindType bind_type_; | 228 DatagramSocket::BindType bind_type_; |
199 | 229 |
200 // PRNG function for generating port numbers. | 230 // PRNG function for generating port numbers. |
201 RandIntCallback rand_int_cb_; | 231 RandIntCallback rand_int_cb_; |
202 | 232 |
203 // These are mutable since they're just cached copies to make | 233 // These are mutable since they're just cached copies to make |
204 // GetPeerAddress/GetLocalAddress smarter. | 234 // GetPeerAddress/GetLocalAddress smarter. |
205 mutable scoped_ptr<IPEndPoint> local_address_; | 235 mutable scoped_ptr<IPEndPoint> local_address_; |
(...skipping 24 matching lines...) Expand all Loading... | |
230 CompletionCallback write_callback_; | 260 CompletionCallback write_callback_; |
231 | 261 |
232 BoundNetLog net_log_; | 262 BoundNetLog net_log_; |
233 | 263 |
234 DISALLOW_COPY_AND_ASSIGN(UDPSocketLibevent); | 264 DISALLOW_COPY_AND_ASSIGN(UDPSocketLibevent); |
235 }; | 265 }; |
236 | 266 |
237 } // namespace net | 267 } // namespace net |
238 | 268 |
239 #endif // NET_UDP_UDP_SOCKET_LIBEVENT_H_ | 269 #endif // NET_UDP_UDP_SOCKET_LIBEVENT_H_ |
OLD | NEW |