Chromium Code Reviews| 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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 | 106 |
| 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 |
|
scheib
2013/04/02 18:25:17
We should have tests in the /net/ directory. Proba
| |
| 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 // Join the multicast group. | |
|
scheib
2013/04/02 18:25:17
Leave ...
Bei Zhang
2013/04/05 00:38:59
Done.
| |
| 123 // |group_address| is the group address to join, 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 | |
|
scheib
2013/04/02 18:25:17
What unit is this int? seconds? ms?
Bei Zhang
2013/04/05 00:38:59
This is measured by hops. So it's a unitless.
On
| |
| 131 // group address. Initially this value is 1. Cannot be negative or | |
| 132 // more than 255. | |
| 133 int SetMulticastTimeToLive(int timeToLive); | |
| 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 |
| 196 // How to do source port binding, used only when UDPSocket is part of | 221 // How to do source port binding, used only when UDPSocket is part of |
| 197 // UDPClientSocket, since UDPServerSocket provides Bind. | 222 // UDPClientSocket, since UDPServerSocket provides Bind. |
| 198 DatagramSocket::BindType bind_type_; | 223 DatagramSocket::BindType bind_type_; |
| 199 | 224 |
| 200 // PRNG function for generating port numbers. | 225 // PRNG function for generating port numbers. |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 230 CompletionCallback write_callback_; | 255 CompletionCallback write_callback_; |
| 231 | 256 |
| 232 BoundNetLog net_log_; | 257 BoundNetLog net_log_; |
| 233 | 258 |
| 234 DISALLOW_COPY_AND_ASSIGN(UDPSocketLibevent); | 259 DISALLOW_COPY_AND_ASSIGN(UDPSocketLibevent); |
| 235 }; | 260 }; |
| 236 | 261 |
| 237 } // namespace net | 262 } // namespace net |
| 238 | 263 |
| 239 #endif // NET_UDP_UDP_SOCKET_LIBEVENT_H_ | 264 #endif // NET_UDP_UDP_SOCKET_LIBEVENT_H_ |
| OLD | NEW |