| 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_WIN_H_ | 5 #ifndef NET_UDP_UDP_SOCKET_WIN_H_ |
| 6 #define NET_UDP_UDP_SOCKET_WIN_H_ | 6 #define NET_UDP_UDP_SOCKET_WIN_H_ |
| 7 | 7 |
| 8 #include <winsock2.h> | 8 #include <winsock2.h> |
| 9 | 9 |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 bool SetReceiveBufferSize(int32 size); | 98 bool SetReceiveBufferSize(int32 size); |
| 99 | 99 |
| 100 // Set the send buffer size (in bytes) for the socket. | 100 // Set the send buffer size (in bytes) for the socket. |
| 101 bool SetSendBufferSize(int32 size); | 101 bool SetSendBufferSize(int32 size); |
| 102 | 102 |
| 103 // Returns true if the socket is already connected or bound. | 103 // Returns true if the socket is already connected or bound. |
| 104 bool is_connected() const { return socket_ != INVALID_SOCKET; } | 104 bool is_connected() const { return socket_ != INVALID_SOCKET; } |
| 105 | 105 |
| 106 const BoundNetLog& NetLog() const { return net_log_; } | 106 const BoundNetLog& NetLog() const { return net_log_; } |
| 107 | 107 |
| 108 // Sets corresponding flags in |socket_options_| to allow the socket |
| 109 // to share the local address to which socket will be bound with |
| 110 // other processes. Should be called before Bind(). |
| 111 void AllowAddressReuse(); |
| 112 |
| 113 // Sets corresponding flags in |socket_options_| to allow sending |
| 114 // and receiving packets sent to and from broadcast |
| 115 // addresses. Should be called before Bind(). |
| 116 void AllowBroadcast(); |
| 117 |
| 108 private: | 118 private: |
| 119 enum SocketOptions { |
| 120 SOCKET_OPTION_REUSE_ADDRESS = 1 << 0, |
| 121 SOCKET_OPTION_BROADCAST = 1 << 1 |
| 122 }; |
| 123 |
| 109 class ReadDelegate : public base::win::ObjectWatcher::Delegate { | 124 class ReadDelegate : public base::win::ObjectWatcher::Delegate { |
| 110 public: | 125 public: |
| 111 explicit ReadDelegate(UDPSocketWin* socket) : socket_(socket) {} | 126 explicit ReadDelegate(UDPSocketWin* socket) : socket_(socket) {} |
| 112 virtual ~ReadDelegate() {} | 127 virtual ~ReadDelegate() {} |
| 113 | 128 |
| 114 // base::ObjectWatcher::Delegate methods: | 129 // base::ObjectWatcher::Delegate methods: |
| 115 virtual void OnObjectSignaled(HANDLE object); | 130 virtual void OnObjectSignaled(HANDLE object); |
| 116 | 131 |
| 117 private: | 132 private: |
| 118 UDPSocketWin* const socket_; | 133 UDPSocketWin* const socket_; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 149 // set to NULL. | 164 // set to NULL. |
| 150 int SendToOrWrite(IOBuffer* buf, | 165 int SendToOrWrite(IOBuffer* buf, |
| 151 int buf_len, | 166 int buf_len, |
| 152 const IPEndPoint* address, | 167 const IPEndPoint* address, |
| 153 const CompletionCallback& callback); | 168 const CompletionCallback& callback); |
| 154 | 169 |
| 155 int InternalConnect(const IPEndPoint& address); | 170 int InternalConnect(const IPEndPoint& address); |
| 156 int InternalRecvFrom(IOBuffer* buf, int buf_len, IPEndPoint* address); | 171 int InternalRecvFrom(IOBuffer* buf, int buf_len, IPEndPoint* address); |
| 157 int InternalSendTo(IOBuffer* buf, int buf_len, const IPEndPoint* address); | 172 int InternalSendTo(IOBuffer* buf, int buf_len, const IPEndPoint* address); |
| 158 | 173 |
| 174 // Applies |socket_options_| to |socket_|. Should be called before |
| 175 // Bind(). |
| 176 int SetSocketOptions(); |
| 159 int DoBind(const IPEndPoint& address); | 177 int DoBind(const IPEndPoint& address); |
| 160 int RandomBind(const IPEndPoint& address); | 178 int RandomBind(const IPEndPoint& address); |
| 161 | 179 |
| 162 // Attempts to convert the data in |recv_addr_storage_| and |recv_addr_len_| | 180 // Attempts to convert the data in |recv_addr_storage_| and |recv_addr_len_| |
| 163 // to an IPEndPoint and writes it to |address|. Returns true on success. | 181 // to an IPEndPoint and writes it to |address|. Returns true on success. |
| 164 bool ReceiveAddressToIPEndpoint(IPEndPoint* address) const; | 182 bool ReceiveAddressToIPEndpoint(IPEndPoint* address) const; |
| 165 | 183 |
| 166 SOCKET socket_; | 184 SOCKET socket_; |
| 167 | 185 |
| 186 // Bitwise-or'd combination of SocketOptions. Specifies set of |
| 187 // options that should be applied to |socket_| before bind. |
| 188 int socket_options_; |
| 189 |
| 168 // How to do source port binding, used only when UDPSocket is part of | 190 // How to do source port binding, used only when UDPSocket is part of |
| 169 // UDPClientSocket, since UDPServerSocket provides Bind. | 191 // UDPClientSocket, since UDPServerSocket provides Bind. |
| 170 DatagramSocket::BindType bind_type_; | 192 DatagramSocket::BindType bind_type_; |
| 171 | 193 |
| 172 // PRNG function for generating port numbers. | 194 // PRNG function for generating port numbers. |
| 173 RandIntCallback rand_int_cb_; | 195 RandIntCallback rand_int_cb_; |
| 174 | 196 |
| 175 // These are mutable since they're just cached copies to make | 197 // These are mutable since they're just cached copies to make |
| 176 // GetPeerAddress/GetLocalAddress smarter. | 198 // GetPeerAddress/GetLocalAddress smarter. |
| 177 mutable scoped_ptr<IPEndPoint> local_address_; | 199 mutable scoped_ptr<IPEndPoint> local_address_; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 CompletionCallback write_callback_; | 231 CompletionCallback write_callback_; |
| 210 | 232 |
| 211 BoundNetLog net_log_; | 233 BoundNetLog net_log_; |
| 212 | 234 |
| 213 DISALLOW_COPY_AND_ASSIGN(UDPSocketWin); | 235 DISALLOW_COPY_AND_ASSIGN(UDPSocketWin); |
| 214 }; | 236 }; |
| 215 | 237 |
| 216 } // namespace net | 238 } // namespace net |
| 217 | 239 |
| 218 #endif // NET_UDP_UDP_SOCKET_WIN_H_ | 240 #endif // NET_UDP_UDP_SOCKET_WIN_H_ |
| OLD | NEW |