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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <winsock2.h> | 9 #include <winsock2.h> |
10 | 10 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 bool SetReceiveBufferSize(int32 size); | 99 bool SetReceiveBufferSize(int32 size); |
100 | 100 |
101 // Set the send buffer size (in bytes) for the socket. | 101 // Set the send buffer size (in bytes) for the socket. |
102 bool SetSendBufferSize(int32 size); | 102 bool SetSendBufferSize(int32 size); |
103 | 103 |
104 // Returns true if the socket is already connected or bound. | 104 // Returns true if the socket is already connected or bound. |
105 bool is_connected() const { return socket_ != INVALID_SOCKET; } | 105 bool is_connected() const { return socket_ != INVALID_SOCKET; } |
106 | 106 |
107 const BoundNetLog& NetLog() const { return net_log_; } | 107 const BoundNetLog& NetLog() const { return net_log_; } |
108 | 108 |
| 109 void AllowBroadcast(); |
| 110 |
109 private: | 111 private: |
110 class ReadDelegate : public base::win::ObjectWatcher::Delegate { | 112 class ReadDelegate : public base::win::ObjectWatcher::Delegate { |
111 public: | 113 public: |
112 explicit ReadDelegate(UDPSocketWin* socket) : socket_(socket) {} | 114 explicit ReadDelegate(UDPSocketWin* socket) : socket_(socket) {} |
113 virtual ~ReadDelegate() {} | 115 virtual ~ReadDelegate() {} |
114 | 116 |
115 // base::ObjectWatcher::Delegate methods: | 117 // base::ObjectWatcher::Delegate methods: |
116 virtual void OnObjectSignaled(HANDLE object); | 118 virtual void OnObjectSignaled(HANDLE object); |
117 | 119 |
118 private: | 120 private: |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 // set to NULL. | 152 // set to NULL. |
151 int SendToOrWrite(IOBuffer* buf, | 153 int SendToOrWrite(IOBuffer* buf, |
152 int buf_len, | 154 int buf_len, |
153 const IPEndPoint* address, | 155 const IPEndPoint* address, |
154 const CompletionCallback& callback); | 156 const CompletionCallback& callback); |
155 | 157 |
156 int InternalConnect(const IPEndPoint& address); | 158 int InternalConnect(const IPEndPoint& address); |
157 int InternalRecvFrom(IOBuffer* buf, int buf_len, IPEndPoint* address); | 159 int InternalRecvFrom(IOBuffer* buf, int buf_len, IPEndPoint* address); |
158 int InternalSendTo(IOBuffer* buf, int buf_len, const IPEndPoint* address); | 160 int InternalSendTo(IOBuffer* buf, int buf_len, const IPEndPoint* address); |
159 | 161 |
| 162 int DoBroadcast(); |
160 int DoBind(const IPEndPoint& address); | 163 int DoBind(const IPEndPoint& address); |
161 int RandomBind(const IPEndPoint& address); | 164 int RandomBind(const IPEndPoint& address); |
162 | 165 |
163 // Attempts to convert the data in |recv_addr_storage_| and |recv_addr_len_| | 166 // Attempts to convert the data in |recv_addr_storage_| and |recv_addr_len_| |
164 // to an IPEndPoint and writes it to |address|. Returns true on success. | 167 // to an IPEndPoint and writes it to |address|. Returns true on success. |
165 bool ReceiveAddressToIPEndpoint(IPEndPoint* address) const; | 168 bool ReceiveAddressToIPEndpoint(IPEndPoint* address) const; |
166 | 169 |
167 SOCKET socket_; | 170 SOCKET socket_; |
| 171 bool allow_broadcast_; |
168 | 172 |
169 // How to do source port binding, used only when UDPSocket is part of | 173 // How to do source port binding, used only when UDPSocket is part of |
170 // UDPClientSocket, since UDPServerSocket provides Bind. | 174 // UDPClientSocket, since UDPServerSocket provides Bind. |
171 DatagramSocket::BindType bind_type_; | 175 DatagramSocket::BindType bind_type_; |
172 | 176 |
173 // PRNG function for generating port numbers. | 177 // PRNG function for generating port numbers. |
174 RandIntCallback rand_int_cb_; | 178 RandIntCallback rand_int_cb_; |
175 | 179 |
176 // These are mutable since they're just cached copies to make | 180 // These are mutable since they're just cached copies to make |
177 // GetPeerAddress/GetLocalAddress smarter. | 181 // GetPeerAddress/GetLocalAddress smarter. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 CompletionCallback write_callback_; | 214 CompletionCallback write_callback_; |
211 | 215 |
212 BoundNetLog net_log_; | 216 BoundNetLog net_log_; |
213 | 217 |
214 DISALLOW_COPY_AND_ASSIGN(UDPSocketWin); | 218 DISALLOW_COPY_AND_ASSIGN(UDPSocketWin); |
215 }; | 219 }; |
216 | 220 |
217 } // namespace net | 221 } // namespace net |
218 | 222 |
219 #endif // NET_UDP_UDP_SOCKET_WIN_H_ | 223 #endif // NET_UDP_UDP_SOCKET_WIN_H_ |
OLD | NEW |