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/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/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 // |callback| is the user callback function to call on complete. | 87 // |callback| is the user callback function to call on complete. |
| 88 // Returns a net error code, or ERR_IO_PENDING if the IO is in progress. | 88 // Returns a net error code, or ERR_IO_PENDING if the IO is in progress. |
| 89 // If ERR_IO_PENDING is returned, the caller must keep |buf| and |address| | 89 // If ERR_IO_PENDING is returned, the caller must keep |buf| and |address| |
| 90 // alive until the callback is called. | 90 // alive until the callback is called. |
| 91 int SendTo(IOBuffer* buf, | 91 int SendTo(IOBuffer* buf, |
| 92 int buf_len, | 92 int buf_len, |
| 93 const IPEndPoint& address, | 93 const IPEndPoint& address, |
| 94 const CompletionCallback& callback); | 94 const CompletionCallback& callback); |
| 95 | 95 |
| 96 // Set the receive buffer size (in bytes) for the socket. | 96 // Set the receive buffer size (in bytes) for the socket. |
| 97 // Returns a net error code. | |
| 97 int SetReceiveBufferSize(int32 size); | 98 int SetReceiveBufferSize(int32 size); |
| 98 | 99 |
| 99 // Set the send buffer size (in bytes) for the socket. | 100 // Set the send buffer size (in bytes) for the socket. |
| 101 // Returns a net error code. | |
| 100 int SetSendBufferSize(int32 size); | 102 int SetSendBufferSize(int32 size); |
| 101 | 103 |
| 102 // Returns true if the socket is already connected or bound. | 104 // Returns true if the socket is already connected or bound. |
| 103 bool is_connected() const { return socket_ != kInvalidSocket; } | 105 bool is_connected() const { return socket_ != kInvalidSocket; } |
| 104 | 106 |
| 105 const BoundNetLog& NetLog() const { return net_log_; } | 107 const BoundNetLog& NetLog() const { return net_log_; } |
| 106 | 108 |
| 107 // Sets corresponding flags in |socket_options_| to allow the socket | 109 // Allows the socket to share the local address to which the socket will be |
| 108 // to share the local address to which the socket will be bound with | 110 // bound with other processes. |
| 109 // other processes. Should be called before Bind(). | 111 // Returns a net error code. |
| 110 void AllowAddressReuse(); | 112 int AllowAddressReuse(); |
| 111 | 113 |
| 112 // Sets corresponding flags in |socket_options_| to allow sending | 114 // Disallows the socket to share the local address to which the socket will |
| 113 // and receiving packets to and from broadcast addresses. Should be | 115 // be bound with other processes. |
| 114 // called before Bind(). | 116 // Returns a net error code. |
| 115 void AllowBroadcast(); | 117 int DisallowAddressReuse(); |
| 118 | |
| 119 // Allows sending and receiving packets to and from broadcast addresses. | |
| 120 // Returns a net error code. | |
| 121 int AllowBroadcast(); | |
| 122 | |
| 123 // Disallows sending and receiving packets to and from broadcast addresses. | |
| 124 // Returns a net error code. | |
| 125 int DisallowBroadcast(); | |
| 116 | 126 |
| 117 // Join the multicast group. | 127 // Join the multicast group. |
| 118 // |group_address| is the group address to join, could be either | 128 // |group_address| is the group address to join, could be either |
| 119 // an IPv4 or IPv6 address. | 129 // an IPv4 or IPv6 address. |
| 120 // Return a network error code. | 130 // Return a network error code. |
| 121 int JoinGroup(const IPAddressNumber& group_address) const; | 131 int JoinGroup(const IPAddressNumber& group_address) const; |
| 122 | 132 |
| 123 // Leave the multicast group. | 133 // Leave the multicast group. |
| 124 // |group_address| is the group address to leave, could be either | 134 // |group_address| is the group address to leave, could be either |
| 125 // an IPv4 or IPv6 address. If the socket hasn't joined the group, | 135 // an IPv4 or IPv6 address. If the socket hasn't joined the group, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 163 // Return a network error code. | 173 // Return a network error code. |
| 164 int SetDiffServCodePoint(DiffServCodePoint dscp); | 174 int SetDiffServCodePoint(DiffServCodePoint dscp); |
| 165 | 175 |
| 166 // Resets the thread to be used for thread-safety checks. | 176 // Resets the thread to be used for thread-safety checks. |
| 167 void DetachFromThread(); | 177 void DetachFromThread(); |
| 168 | 178 |
| 169 private: | 179 private: |
| 170 enum SocketOptions { | 180 enum SocketOptions { |
| 171 SOCKET_OPTION_REUSE_ADDRESS = 1 << 0, | 181 SOCKET_OPTION_REUSE_ADDRESS = 1 << 0, |
| 172 SOCKET_OPTION_BROADCAST = 1 << 1, | 182 SOCKET_OPTION_BROADCAST = 1 << 1, |
| 173 SOCKET_OPTION_MULTICAST_LOOP = 1 << 2 | 183 SOCKET_OPTION_MULTICAST_LOOP = 1 << 2, |
| 184 SOCKET_OPTION_RCVBUF_SIZE = 1 << 3, | |
| 185 SOCKET_OPTION_SNDBUF_SIZE = 1 << 4 | |
| 174 }; | 186 }; |
| 175 | 187 |
| 176 class ReadWatcher : public base::MessageLoopForIO::Watcher { | 188 class ReadWatcher : public base::MessageLoopForIO::Watcher { |
| 177 public: | 189 public: |
| 178 explicit ReadWatcher(UDPSocketLibevent* socket) : socket_(socket) {} | 190 explicit ReadWatcher(UDPSocketLibevent* socket) : socket_(socket) {} |
| 179 | 191 |
| 180 // MessageLoopForIO::Watcher methods | 192 // MessageLoopForIO::Watcher methods |
| 181 | 193 |
| 182 void OnFileCanReadWithoutBlocking(int /* fd */) override; | 194 void OnFileCanReadWithoutBlocking(int /* fd */) override; |
| 183 | 195 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 229 const IPEndPoint* address, | 241 const IPEndPoint* address, |
| 230 const CompletionCallback& callback); | 242 const CompletionCallback& callback); |
| 231 | 243 |
| 232 int InternalConnect(const IPEndPoint& address); | 244 int InternalConnect(const IPEndPoint& address); |
| 233 int InternalRecvFrom(IOBuffer* buf, int buf_len, IPEndPoint* address); | 245 int InternalRecvFrom(IOBuffer* buf, int buf_len, IPEndPoint* address); |
| 234 int InternalSendTo(IOBuffer* buf, int buf_len, const IPEndPoint* address); | 246 int InternalSendTo(IOBuffer* buf, int buf_len, const IPEndPoint* address); |
| 235 | 247 |
| 236 // Applies |socket_options_| to |socket_|. Should be called before | 248 // Applies |socket_options_| to |socket_|. Should be called before |
| 237 // Bind(). | 249 // Bind(). |
| 238 int SetSocketOptions(); | 250 int SetSocketOptions(); |
| 251 int SetAddressReuseInternal(bool value); | |
|
jar (doing other things)
2014/11/04 22:51:09
nit: use better variable name than |value|.
Perha
hidehiko
2014/11/05 12:48:30
Done.
| |
| 252 int SetBroadcastInternal(bool value); | |
| 253 int SetReceiveBufferSizeInternal(int32 size); | |
| 254 int SetSendBufferSizeInternal(int32 size); | |
| 255 | |
| 239 int DoBind(const IPEndPoint& address); | 256 int DoBind(const IPEndPoint& address); |
| 240 // Binds to a random port on |address|. | 257 // Binds to a random port on |address|. |
| 241 int RandomBind(const IPAddressNumber& address); | 258 int RandomBind(const IPAddressNumber& address); |
| 242 | 259 |
| 243 int socket_; | 260 int socket_; |
| 244 int addr_family_; | 261 int addr_family_; |
| 245 | 262 |
| 246 // Bitwise-or'd combination of SocketOptions. Specifies the set of | 263 // Bitwise-or'd combination of SocketOptions. Specifies the set of |
| 247 // options that should be applied to |socket_| before Bind(). | 264 // options that should be applied to |socket_| before Bind(). |
| 248 int socket_options_; | 265 int socket_options_; |
| 249 | 266 |
| 267 // Buffer size set before Bind(). This should be applied | |
| 268 // in SetSocketOptions(). | |
| 269 int32 rcvbuf_size_; | |
| 270 int32 sndbuf_size_; | |
| 271 | |
| 250 // Multicast interface. | 272 // Multicast interface. |
| 251 uint32 multicast_interface_; | 273 uint32 multicast_interface_; |
| 252 | 274 |
| 253 // Multicast socket options cached for SetSocketOption. | 275 // Multicast socket options cached for SetSocketOption. |
| 254 // Cannot be used after Bind(). | 276 // Cannot be used after Bind(). |
| 255 int multicast_time_to_live_; | 277 int multicast_time_to_live_; |
| 256 | 278 |
| 257 // How to do source port binding, used only when UDPSocket is part of | 279 // How to do source port binding, used only when UDPSocket is part of |
| 258 // UDPClientSocket, since UDPServerSocket provides Bind. | 280 // UDPClientSocket, since UDPServerSocket provides Bind. |
| 259 DatagramSocket::BindType bind_type_; | 281 DatagramSocket::BindType bind_type_; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 291 CompletionCallback write_callback_; | 313 CompletionCallback write_callback_; |
| 292 | 314 |
| 293 BoundNetLog net_log_; | 315 BoundNetLog net_log_; |
| 294 | 316 |
| 295 DISALLOW_COPY_AND_ASSIGN(UDPSocketLibevent); | 317 DISALLOW_COPY_AND_ASSIGN(UDPSocketLibevent); |
| 296 }; | 318 }; |
| 297 | 319 |
| 298 } // namespace net | 320 } // namespace net |
| 299 | 321 |
| 300 #endif // NET_UDP_UDP_SOCKET_LIBEVENT_H_ | 322 #endif // NET_UDP_UDP_SOCKET_LIBEVENT_H_ |
| OLD | NEW |