Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(874)

Unified Diff: net/udp/udp_socket_win.h

Issue 721273002: Remove timing limitation to set Broadcast, ReceiveBuffer, and SendBuffer options from UDPSocket. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/udp/udp_socket_win.h
diff --git a/net/udp/udp_socket_win.h b/net/udp/udp_socket_win.h
index bc97d5683655a0fc773d36eadbd535e18c096706..0fe068118b74331de0d0f4cb9b30c0fd78c1faed 100644
--- a/net/udp/udp_socket_win.h
+++ b/net/udp/udp_socket_win.h
@@ -12,6 +12,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/threading/non_thread_safe.h"
#include "base/win/object_watcher.h"
+#include "net/base/address_family.h"
#include "net/base/completion_callback.h"
#include "net/base/net_export.h"
#include "net/base/rand_callback.h"
@@ -30,22 +31,27 @@ class NET_EXPORT UDPSocketWin : NON_EXPORTED_BASE(public base::NonThreadSafe) {
const net::NetLog::Source& source);
virtual ~UDPSocketWin();
+ // 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;
@@ -104,24 +110,23 @@ class NET_EXPORT UDPSocketWin : NON_EXPORTED_BASE(public base::NonThreadSafe) {
int SetSendBufferSize(int32 size);
// Returns true if the socket is already connected or bound.
- bool is_connected() const { return socket_ != INVALID_SOCKET; }
+ 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().
- 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();
+ // and receiving packets to and from broadcast addresses.
+ 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.
int JoinGroup(const IPAddressNumber& group_address) const;
// Leave the multicast group.
@@ -130,13 +135,13 @@ class NET_EXPORT UDPSocketWin : NON_EXPORTED_BASE(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.
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
@@ -169,9 +174,7 @@ class NET_EXPORT UDPSocketWin : NON_EXPORTED_BASE(public base::NonThreadSafe) {
private:
enum SocketOptions {
- SOCKET_OPTION_REUSE_ADDRESS = 1 << 0,
- SOCKET_OPTION_BROADCAST = 1 << 1,
- SOCKET_OPTION_MULTICAST_LOOP = 1 << 2
+ SOCKET_OPTION_MULTICAST_LOOP = 1 << 0
};
class Core;
@@ -187,9 +190,6 @@ class NET_EXPORT UDPSocketWin : NON_EXPORTED_BASE(public base::NonThreadSafe) {
void LogRead(int result, const char* bytes) 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.
@@ -204,7 +204,7 @@ class NET_EXPORT UDPSocketWin : NON_EXPORTED_BASE(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);
@@ -215,6 +215,7 @@ class NET_EXPORT UDPSocketWin : NON_EXPORTED_BASE(public base::NonThreadSafe) {
SOCKET 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().
@@ -223,7 +224,7 @@ class NET_EXPORT UDPSocketWin : NON_EXPORTED_BASE(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_;

Powered by Google App Engine
This is Rietveld 408576698