| 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 void AllowAddressReuse(); |
| 109 |
| 110 void AllowBroadcast(); |
| 111 |
| 108 private: | 112 private: |
| 113 enum SocketOptions { |
| 114 SOCKET_OPTION_REUSE_ADDRESS = 1 << 0, |
| 115 SOCKET_OPTION_BROADCAST = 1 << 1 |
| 116 }; |
| 117 |
| 109 class ReadDelegate : public base::win::ObjectWatcher::Delegate { | 118 class ReadDelegate : public base::win::ObjectWatcher::Delegate { |
| 110 public: | 119 public: |
| 111 explicit ReadDelegate(UDPSocketWin* socket) : socket_(socket) {} | 120 explicit ReadDelegate(UDPSocketWin* socket) : socket_(socket) {} |
| 112 virtual ~ReadDelegate() {} | 121 virtual ~ReadDelegate() {} |
| 113 | 122 |
| 114 // base::ObjectWatcher::Delegate methods: | 123 // base::ObjectWatcher::Delegate methods: |
| 115 virtual void OnObjectSignaled(HANDLE object); | 124 virtual void OnObjectSignaled(HANDLE object); |
| 116 | 125 |
| 117 private: | 126 private: |
| 118 UDPSocketWin* const socket_; | 127 UDPSocketWin* const socket_; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 149 // set to NULL. | 158 // set to NULL. |
| 150 int SendToOrWrite(IOBuffer* buf, | 159 int SendToOrWrite(IOBuffer* buf, |
| 151 int buf_len, | 160 int buf_len, |
| 152 const IPEndPoint* address, | 161 const IPEndPoint* address, |
| 153 const CompletionCallback& callback); | 162 const CompletionCallback& callback); |
| 154 | 163 |
| 155 int InternalConnect(const IPEndPoint& address); | 164 int InternalConnect(const IPEndPoint& address); |
| 156 int InternalRecvFrom(IOBuffer* buf, int buf_len, IPEndPoint* address); | 165 int InternalRecvFrom(IOBuffer* buf, int buf_len, IPEndPoint* address); |
| 157 int InternalSendTo(IOBuffer* buf, int buf_len, const IPEndPoint* address); | 166 int InternalSendTo(IOBuffer* buf, int buf_len, const IPEndPoint* address); |
| 158 | 167 |
| 168 int SetSocketOptions(); |
| 159 int DoBind(const IPEndPoint& address); | 169 int DoBind(const IPEndPoint& address); |
| 160 int RandomBind(const IPEndPoint& address); | 170 int RandomBind(const IPEndPoint& address); |
| 161 | 171 |
| 162 // Attempts to convert the data in |recv_addr_storage_| and |recv_addr_len_| | 172 // 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. | 173 // to an IPEndPoint and writes it to |address|. Returns true on success. |
| 164 bool ReceiveAddressToIPEndpoint(IPEndPoint* address) const; | 174 bool ReceiveAddressToIPEndpoint(IPEndPoint* address) const; |
| 165 | 175 |
| 166 SOCKET socket_; | 176 SOCKET socket_; |
| 177 int socket_options_; |
| 167 | 178 |
| 168 // How to do source port binding, used only when UDPSocket is part of | 179 // How to do source port binding, used only when UDPSocket is part of |
| 169 // UDPClientSocket, since UDPServerSocket provides Bind. | 180 // UDPClientSocket, since UDPServerSocket provides Bind. |
| 170 DatagramSocket::BindType bind_type_; | 181 DatagramSocket::BindType bind_type_; |
| 171 | 182 |
| 172 // PRNG function for generating port numbers. | 183 // PRNG function for generating port numbers. |
| 173 RandIntCallback rand_int_cb_; | 184 RandIntCallback rand_int_cb_; |
| 174 | 185 |
| 175 // These are mutable since they're just cached copies to make | 186 // These are mutable since they're just cached copies to make |
| 176 // GetPeerAddress/GetLocalAddress smarter. | 187 // GetPeerAddress/GetLocalAddress smarter. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 CompletionCallback write_callback_; | 220 CompletionCallback write_callback_; |
| 210 | 221 |
| 211 BoundNetLog net_log_; | 222 BoundNetLog net_log_; |
| 212 | 223 |
| 213 DISALLOW_COPY_AND_ASSIGN(UDPSocketWin); | 224 DISALLOW_COPY_AND_ASSIGN(UDPSocketWin); |
| 214 }; | 225 }; |
| 215 | 226 |
| 216 } // namespace net | 227 } // namespace net |
| 217 | 228 |
| 218 #endif // NET_UDP_UDP_SOCKET_WIN_H_ | 229 #endif // NET_UDP_UDP_SOCKET_WIN_H_ |
| OLD | NEW |