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_LIBEVENT_H_ | 5 #ifndef NET_UDP_UDP_SOCKET_LIBEVENT_H_ |
6 #define NET_UDP_UDP_SOCKET_LIBEVENT_H_ | 6 #define NET_UDP_UDP_SOCKET_LIBEVENT_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 bool SetReceiveBufferSize(int32 size); | 97 bool SetReceiveBufferSize(int32 size); |
98 | 98 |
99 // Set the send buffer size (in bytes) for the socket. | 99 // Set the send buffer size (in bytes) for the socket. |
100 bool SetSendBufferSize(int32 size); | 100 bool SetSendBufferSize(int32 size); |
101 | 101 |
102 // Returns true if the socket is already connected or bound. | 102 // Returns true if the socket is already connected or bound. |
103 bool is_connected() const { return socket_ != kInvalidSocket; } | 103 bool is_connected() const { return socket_ != kInvalidSocket; } |
104 | 104 |
105 const BoundNetLog& NetLog() const { return net_log_; } | 105 const BoundNetLog& NetLog() const { return net_log_; } |
106 | 106 |
| 107 void AllowBroadcast(); |
| 108 |
107 private: | 109 private: |
108 static const int kInvalidSocket = -1; | 110 static const int kInvalidSocket = -1; |
109 | 111 |
110 class ReadWatcher : public MessageLoopForIO::Watcher { | 112 class ReadWatcher : public MessageLoopForIO::Watcher { |
111 public: | 113 public: |
112 explicit ReadWatcher(UDPSocketLibevent* socket) : socket_(socket) {} | 114 explicit ReadWatcher(UDPSocketLibevent* socket) : socket_(socket) {} |
113 | 115 |
114 // MessageLoopForIO::Watcher methods | 116 // MessageLoopForIO::Watcher methods |
115 | 117 |
116 virtual void OnFileCanReadWithoutBlocking(int /* fd */) OVERRIDE { | 118 virtual void OnFileCanReadWithoutBlocking(int /* fd */) OVERRIDE { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 // set to NULL. | 168 // set to NULL. |
167 int SendToOrWrite(IOBuffer* buf, | 169 int SendToOrWrite(IOBuffer* buf, |
168 int buf_len, | 170 int buf_len, |
169 const IPEndPoint* address, | 171 const IPEndPoint* address, |
170 const CompletionCallback& callback); | 172 const CompletionCallback& callback); |
171 | 173 |
172 int InternalConnect(const IPEndPoint& address); | 174 int InternalConnect(const IPEndPoint& address); |
173 int InternalRecvFrom(IOBuffer* buf, int buf_len, IPEndPoint* address); | 175 int InternalRecvFrom(IOBuffer* buf, int buf_len, IPEndPoint* address); |
174 int InternalSendTo(IOBuffer* buf, int buf_len, const IPEndPoint* address); | 176 int InternalSendTo(IOBuffer* buf, int buf_len, const IPEndPoint* address); |
175 | 177 |
| 178 int DoBroadcast(); |
176 int DoBind(const IPEndPoint& address); | 179 int DoBind(const IPEndPoint& address); |
177 int RandomBind(const IPEndPoint& address); | 180 int RandomBind(const IPEndPoint& address); |
178 | 181 |
179 int socket_; | 182 int socket_; |
| 183 bool allow_broadcast_; |
180 | 184 |
181 // How to do source port binding, used only when UDPSocket is part of | 185 // How to do source port binding, used only when UDPSocket is part of |
182 // UDPClientSocket, since UDPServerSocket provides Bind. | 186 // UDPClientSocket, since UDPServerSocket provides Bind. |
183 DatagramSocket::BindType bind_type_; | 187 DatagramSocket::BindType bind_type_; |
184 | 188 |
185 // PRNG function for generating port numbers. | 189 // PRNG function for generating port numbers. |
186 RandIntCallback rand_int_cb_; | 190 RandIntCallback rand_int_cb_; |
187 | 191 |
188 // These are mutable since they're just cached copies to make | 192 // These are mutable since they're just cached copies to make |
189 // GetPeerAddress/GetLocalAddress smarter. | 193 // GetPeerAddress/GetLocalAddress smarter. |
(...skipping 25 matching lines...) Expand all Loading... |
215 CompletionCallback write_callback_; | 219 CompletionCallback write_callback_; |
216 | 220 |
217 BoundNetLog net_log_; | 221 BoundNetLog net_log_; |
218 | 222 |
219 DISALLOW_COPY_AND_ASSIGN(UDPSocketLibevent); | 223 DISALLOW_COPY_AND_ASSIGN(UDPSocketLibevent); |
220 }; | 224 }; |
221 | 225 |
222 } // namespace net | 226 } // namespace net |
223 | 227 |
224 #endif // NET_UDP_UDP_SOCKET_LIBEVENT_H_ | 228 #endif // NET_UDP_UDP_SOCKET_LIBEVENT_H_ |
OLD | NEW |