Chromium Code Reviews| Index: net/udp/udp_socket_libevent.h |
| diff --git a/net/udp/udp_socket_libevent.h b/net/udp/udp_socket_libevent.h |
| index 2ac564debc533752d038b81a9b76312ecf0cc920..472487af61b58bc3f7e1a8452b8d841bbee9e1b8 100644 |
| --- a/net/udp/udp_socket_libevent.h |
| +++ b/net/udp/udp_socket_libevent.h |
| @@ -9,6 +9,7 @@ |
| #include "base/memory/scoped_ptr.h" |
| #include "base/message_loop/message_loop.h" |
| #include "base/threading/non_thread_safe.h" |
| +#include "net/base/address_family.h" |
| #include "net/base/completion_callback.h" |
| #include "net/base/io_buffer.h" |
| #include "net/base/ip_endpoint.h" |
| @@ -28,22 +29,27 @@ class NET_EXPORT UDPSocketLibevent : public base::NonThreadSafe { |
| const net::NetLog::Source& source); |
| virtual ~UDPSocketLibevent(); |
| + // Opens the socket. |
| + // Returns a net error code. |
| + int Open(AddressFamily address_family); |
| + |
| // Connect the socket to connect with a certain |address|. |
| + // Should be called after Open(). |
| // Returns a net error code. |
| int Connect(const IPEndPoint& address); |
| // Bind the address/port for this socket to |address|. This is generally |
| - // only used on a server. |
| + // only used on a server. Should be called after Open(). |
| // Returns a net error code. |
| int Bind(const IPEndPoint& address); |
| // Close the socket. |
| void Close(); |
| - // Copy the remote udp address into |address| and return a network error code. |
| + // Copy the remote udp address into |address| and return a net error code. |
| int GetPeerAddress(IPEndPoint* address) const; |
| - // Copy the local udp address into |address| and return a network error code. |
| + // Copy the local udp address into |address| and return a net error code. |
| // (similar to getsockname) |
| int GetLocalAddress(IPEndPoint* address) const; |
| @@ -94,30 +100,32 @@ class NET_EXPORT UDPSocketLibevent : public base::NonThreadSafe { |
| const CompletionCallback& callback); |
| // Set the receive buffer size (in bytes) for the socket. |
| + // Returns a net error code. |
| int SetReceiveBufferSize(int32 size); |
| // Set the send buffer size (in bytes) for the socket. |
| + // Returns a net error code. |
| int SetSendBufferSize(int32 size); |
| // Returns true if the socket is already connected or bound. |
| - bool is_connected() const { return socket_ != kInvalidSocket; } |
| + bool is_connected() const { return is_connected_; } |
| const BoundNetLog& NetLog() const { return net_log_; } |
| // Sets corresponding flags in |socket_options_| to allow the socket |
| // to share the local address to which the socket will be bound with |
| // other processes. Should be called before Bind(). |
|
rvargas (doing something else)
2014/12/03 21:00:16
nit: returns a ...
hidehiko
2014/12/04 04:03:36
Done. Walked though the udp_socket_libevent.h and
rvargas (doing something else)
2014/12/04 19:51:37
I'm sorry I was not clear with this one. Now there
hidehiko
2014/12/08 05:07:40
Oops, I misunderstood your comments. Fixed the com
|
| - void AllowAddressReuse(); |
| + int AllowAddressReuse(); |
| - // Sets corresponding flags in |socket_options_| to allow sending |
| - // and receiving packets to and from broadcast addresses. Should be |
| - // called before Bind(). |
| - void AllowBroadcast(); |
| + // Sets corresponding flags in |socket_options_| to allow or disallow sending |
| + // and receiving packets to and from broadcast addresses. |
| + // Returns a net error code. |
| + int SetBroadcast(bool broadcast); |
| // Join the multicast group. |
| // |group_address| is the group address to join, could be either |
| // an IPv4 or IPv6 address. |
| - // Return a network error code. |
| + // Return a net error code. |
|
rvargas (doing something else)
2014/12/03 21:00:16
nit: return -> returns
hidehiko
2014/12/04 04:03:36
Done.
|
| int JoinGroup(const IPAddressNumber& group_address) const; |
| // Leave the multicast group. |
| @@ -126,27 +134,27 @@ class NET_EXPORT UDPSocketLibevent : public base::NonThreadSafe { |
| // it will be ignored. |
| // It's optional to leave the multicast group before destroying |
| // the socket. It will be done by the OS. |
| - // Return a network error code. |
| + // Return a net error code. |
|
rvargas (doing something else)
2014/12/03 21:00:16
etc
hidehiko
2014/12/04 04:03:36
Done.
|
| int LeaveGroup(const IPAddressNumber& group_address) const; |
| // Set interface to use for multicast. If |interface_index| set to 0, default |
| // interface is used. |
| // Should be called before Bind(). |
| - // Returns a network error code. |
| + // Returns a net error code. |
| int SetMulticastInterface(uint32 interface_index); |
| // Set the time-to-live option for UDP packets sent to the multicast |
| // group address. The default value of this option is 1. |
| // Cannot be negative or more than 255. |
| // Should be called before Bind(). |
| - // Return a network error code. |
| + // Return a net error code. |
| int SetMulticastTimeToLive(int time_to_live); |
| // Set the loopback flag for UDP socket. If this flag is true, the host |
| // will receive packets sent to the joined group from itself. |
| // The default value of this option is true. |
| // Should be called before Bind(). |
| - // Return a network error code. |
| + // Return a net error code. |
| // |
| // Note: the behavior of |SetMulticastLoopbackMode| is slightly |
| // different between Windows and Unix-like systems. The inconsistency only |
| @@ -160,7 +168,7 @@ class NET_EXPORT UDPSocketLibevent : public base::NonThreadSafe { |
| // Set the differentiated services flags on outgoing packets. May not |
| // do anything on some platforms. |
| - // Return a network error code. |
| + // Return a net error code. |
| int SetDiffServCodePoint(DiffServCodePoint dscp); |
| // Resets the thread to be used for thread-safety checks. |
| @@ -169,8 +177,7 @@ class NET_EXPORT UDPSocketLibevent : public base::NonThreadSafe { |
| private: |
| enum SocketOptions { |
| SOCKET_OPTION_REUSE_ADDRESS = 1 << 0, |
|
rvargas (doing something else)
2014/12/03 21:00:16
should not need this
hidehiko
2014/12/04 04:03:36
Oops, overlooked. Removed.
|
| - SOCKET_OPTION_BROADCAST = 1 << 1, |
| - SOCKET_OPTION_MULTICAST_LOOP = 1 << 2 |
| + SOCKET_OPTION_MULTICAST_LOOP = 1 << 1 |
| }; |
| class ReadWatcher : public base::MessageLoopForIO::Watcher { |
| @@ -218,9 +225,6 @@ class NET_EXPORT UDPSocketLibevent : public base::NonThreadSafe { |
| const sockaddr* addr) const; |
| void LogWrite(int result, const char* bytes, const IPEndPoint* address) const; |
| - // Returns the OS error code (or 0 on success). |
| - int CreateSocket(int addr_family); |
| - |
| // Same as SendTo(), except that address is passed by pointer |
| // instead of by reference. It is called from Write() with |address| |
| // set to NULL. |
| @@ -235,13 +239,14 @@ class NET_EXPORT UDPSocketLibevent : public base::NonThreadSafe { |
| // Applies |socket_options_| to |socket_|. Should be called before |
| // Bind(). |
| - int SetSocketOptions(); |
| + int SetMulticastOptions(); |
| int DoBind(const IPEndPoint& address); |
| // Binds to a random port on |address|. |
| int RandomBind(const IPAddressNumber& address); |
| int socket_; |
| int addr_family_; |
| + bool is_connected_; |
| // Bitwise-or'd combination of SocketOptions. Specifies the set of |
| // options that should be applied to |socket_| before Bind(). |
| @@ -250,7 +255,7 @@ class NET_EXPORT UDPSocketLibevent : public base::NonThreadSafe { |
| // Multicast interface. |
| uint32 multicast_interface_; |
| - // Multicast socket options cached for SetSocketOption. |
| + // Multicast socket options cached for SetMulticastOption. |
| // Cannot be used after Bind(). |
| int multicast_time_to_live_; |