| 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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  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 the 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 to and from broadcast addresses. Should be |  112   // and receiving packets to and from broadcast addresses. Should be | 
|  113   // called before Bind(). |  113   // called before Bind(). | 
|  114   void AllowBroadcast(); |  114   void AllowBroadcast(); | 
|  115  |  115  | 
 |  116   // Join the multicast group. | 
 |  117   // |group_address| is the group address to join, could be either | 
 |  118   // an IPv4 or IPv6 address. | 
 |  119   // Return a network error code. | 
 |  120   int JoinGroup(const IPAddressNumber& group_address) const; | 
 |  121  | 
 |  122   // Leave the multicast group. | 
 |  123   // |group_address| is the group address to leave, could be either | 
 |  124   // an 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   // Return a network error code. | 
 |  129   int LeaveGroup(const IPAddressNumber& group_address) const; | 
 |  130  | 
 |  131   // Set the time-to-live option for UDP packets sent to the multicast | 
 |  132   // group address. The default value of this option is 1. | 
 |  133   // Cannot be negative or more than 255. | 
 |  134   // Should be called before Bind(). | 
 |  135   // Return a network error code. | 
 |  136   int SetMulticastTimeToLive(int time_to_live); | 
 |  137  | 
 |  138   // Set the loopback flag for UDP socket. If this flag is true, the host | 
 |  139   // will receive packets sent to the joined group from itself. | 
 |  140   // The default value of this option is true. | 
 |  141   // Should be called before Bind(). | 
 |  142   // Return a network error code. | 
 |  143   // | 
 |  144   // Note: the behavior of |SetMulticastLoopbackMode| is slightly | 
 |  145   // different between Windows and Unix-like systems. The inconsistency only | 
 |  146   // happens when there are more than one applications on the same host | 
 |  147   // joined to the same multicast group while having different settings on | 
 |  148   // multicast loopback mode. On Windows, the applications with loopback off | 
 |  149   // will not RECEIVE the loopback packets; while on Unix-like systems, the | 
 |  150   // applications with loopback off will not SEND the loopback packets to | 
 |  151   // other applications on the same host. See MSDN: http://goo.gl/6vqbj | 
 |  152   int SetMulticastLoopbackMode(bool loopback); | 
 |  153  | 
|  116  private: |  154  private: | 
|  117   static const int kInvalidSocket = -1; |  155   static const int kInvalidSocket = -1; | 
|  118  |  156  | 
|  119   enum SocketOptions { |  157   enum SocketOptions { | 
|  120     SOCKET_OPTION_REUSE_ADDRESS = 1 << 0, |  158     SOCKET_OPTION_REUSE_ADDRESS  = 1 << 0, | 
|  121     SOCKET_OPTION_BROADCAST     = 1 << 1 |  159     SOCKET_OPTION_BROADCAST      = 1 << 1, | 
 |  160     SOCKET_OPTION_MULTICAST_LOOP = 1 << 2 | 
|  122   }; |  161   }; | 
|  123  |  162  | 
|  124   class ReadWatcher : public MessageLoopForIO::Watcher { |  163   class ReadWatcher : public MessageLoopForIO::Watcher { | 
|  125    public: |  164    public: | 
|  126     explicit ReadWatcher(UDPSocketLibevent* socket) : socket_(socket) {} |  165     explicit ReadWatcher(UDPSocketLibevent* socket) : socket_(socket) {} | 
|  127  |  166  | 
|  128     // MessageLoopForIO::Watcher methods |  167     // MessageLoopForIO::Watcher methods | 
|  129  |  168  | 
|  130     virtual void OnFileCanReadWithoutBlocking(int /* fd */) OVERRIDE; |  169     virtual void OnFileCanReadWithoutBlocking(int /* fd */) OVERRIDE; | 
|  131  |  170  | 
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  181   int InternalRecvFrom(IOBuffer* buf, int buf_len, IPEndPoint* address); |  220   int InternalRecvFrom(IOBuffer* buf, int buf_len, IPEndPoint* address); | 
|  182   int InternalSendTo(IOBuffer* buf, int buf_len, const IPEndPoint* address); |  221   int InternalSendTo(IOBuffer* buf, int buf_len, const IPEndPoint* address); | 
|  183  |  222  | 
|  184   // Applies |socket_options_| to |socket_|. Should be called before |  223   // Applies |socket_options_| to |socket_|. Should be called before | 
|  185   // Bind(). |  224   // Bind(). | 
|  186   int SetSocketOptions(); |  225   int SetSocketOptions(); | 
|  187   int DoBind(const IPEndPoint& address); |  226   int DoBind(const IPEndPoint& address); | 
|  188   int RandomBind(const IPEndPoint& address); |  227   int RandomBind(const IPEndPoint& address); | 
|  189  |  228  | 
|  190   int socket_; |  229   int socket_; | 
 |  230   int addr_family_; | 
|  191  |  231  | 
|  192   // Bitwise-or'd combination of SocketOptions. Specifies the set of |  232   // Bitwise-or'd combination of SocketOptions. Specifies the set of | 
|  193   // options that should be applied to |socket_| before Bind(). |  233   // options that should be applied to |socket_| before Bind(). | 
|  194   int socket_options_; |  234   int socket_options_; | 
|  195  |  235  | 
 |  236   // Multicast socket options cached for SetSocketOption. | 
 |  237   // Cannot be used after Bind(). | 
 |  238   int multicast_time_to_live_; | 
 |  239  | 
|  196   // How to do source port binding, used only when UDPSocket is part of |  240   // How to do source port binding, used only when UDPSocket is part of | 
|  197   // UDPClientSocket, since UDPServerSocket provides Bind. |  241   // UDPClientSocket, since UDPServerSocket provides Bind. | 
|  198   DatagramSocket::BindType bind_type_; |  242   DatagramSocket::BindType bind_type_; | 
|  199  |  243  | 
|  200   // PRNG function for generating port numbers. |  244   // PRNG function for generating port numbers. | 
|  201   RandIntCallback rand_int_cb_; |  245   RandIntCallback rand_int_cb_; | 
|  202  |  246  | 
|  203   // These are mutable since they're just cached copies to make |  247   // These are mutable since they're just cached copies to make | 
|  204   // GetPeerAddress/GetLocalAddress smarter. |  248   // GetPeerAddress/GetLocalAddress smarter. | 
|  205   mutable scoped_ptr<IPEndPoint> local_address_; |  249   mutable scoped_ptr<IPEndPoint> local_address_; | 
| (...skipping 24 matching lines...) Expand all  Loading... | 
|  230   CompletionCallback write_callback_; |  274   CompletionCallback write_callback_; | 
|  231  |  275  | 
|  232   BoundNetLog net_log_; |  276   BoundNetLog net_log_; | 
|  233  |  277  | 
|  234   DISALLOW_COPY_AND_ASSIGN(UDPSocketLibevent); |  278   DISALLOW_COPY_AND_ASSIGN(UDPSocketLibevent); | 
|  235 }; |  279 }; | 
|  236  |  280  | 
|  237 }  // namespace net |  281 }  // namespace net | 
|  238  |  282  | 
|  239 #endif  // NET_UDP_UDP_SOCKET_LIBEVENT_H_ |  283 #endif  // NET_UDP_UDP_SOCKET_LIBEVENT_H_ | 
| OLD | NEW |