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

Side by Side Diff: net/udp/udp_socket_libevent.h

Issue 10739002: Added broadcasting feature to UDP server sockets. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixed Win code. Created 8 years, 5 months 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 unified diff | Download patch
OLDNEW
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 7
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 bool SetReceiveBufferSize(int32 size); 96 bool SetReceiveBufferSize(int32 size);
97 97
98 // Set the send buffer size (in bytes) for the socket. 98 // Set the send buffer size (in bytes) for the socket.
99 bool SetSendBufferSize(int32 size); 99 bool SetSendBufferSize(int32 size);
100 100
101 // Returns true if the socket is already connected or bound. 101 // Returns true if the socket is already connected or bound.
102 bool is_connected() const { return socket_ != kInvalidSocket; } 102 bool is_connected() const { return socket_ != kInvalidSocket; }
103 103
104 const BoundNetLog& NetLog() const { return net_log_; } 104 const BoundNetLog& NetLog() const { return net_log_; }
105 105
106 void AllowAddressReuse();
107
108 void AllowBroadcast();
wtc 2012/07/12 23:49:47 NOTE: all the changes I suggest for this file also
ygorshenin1 2012/07/16 10:29:44 Done.
109
106 private: 110 private:
107 static const int kInvalidSocket = -1; 111 static const int kInvalidSocket = -1;
108 112
113 enum SocketOptions {
114 SOCKET_OPTION_REUSE_ADDRESS = 1 << 0,
115 SOCKET_OPTION_BROADCAST = 1 << 1
116 };
117
109 class ReadWatcher : public MessageLoopForIO::Watcher { 118 class ReadWatcher : public MessageLoopForIO::Watcher {
110 public: 119 public:
111 explicit ReadWatcher(UDPSocketLibevent* socket) : socket_(socket) {} 120 explicit ReadWatcher(UDPSocketLibevent* socket) : socket_(socket) {}
112 121
113 // MessageLoopForIO::Watcher methods 122 // MessageLoopForIO::Watcher methods
114 123
115 virtual void OnFileCanReadWithoutBlocking(int /* fd */) OVERRIDE { 124 virtual void OnFileCanReadWithoutBlocking(int /* fd */) OVERRIDE {
116 if (!socket_->read_callback_.is_null()) 125 if (!socket_->read_callback_.is_null())
117 socket_->DidCompleteRead(); 126 socket_->DidCompleteRead();
118 } 127 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 // set to NULL. 174 // set to NULL.
166 int SendToOrWrite(IOBuffer* buf, 175 int SendToOrWrite(IOBuffer* buf,
167 int buf_len, 176 int buf_len,
168 const IPEndPoint* address, 177 const IPEndPoint* address,
169 const CompletionCallback& callback); 178 const CompletionCallback& callback);
170 179
171 int InternalConnect(const IPEndPoint& address); 180 int InternalConnect(const IPEndPoint& address);
172 int InternalRecvFrom(IOBuffer* buf, int buf_len, IPEndPoint* address); 181 int InternalRecvFrom(IOBuffer* buf, int buf_len, IPEndPoint* address);
173 int InternalSendTo(IOBuffer* buf, int buf_len, const IPEndPoint* address); 182 int InternalSendTo(IOBuffer* buf, int buf_len, const IPEndPoint* address);
174 183
184 int SetSocketOptions();
175 int DoBind(const IPEndPoint& address); 185 int DoBind(const IPEndPoint& address);
176 int RandomBind(const IPEndPoint& address); 186 int RandomBind(const IPEndPoint& address);
177 187
178 int socket_; 188 int socket_;
189 int socket_options_;
wtc 2012/07/12 23:49:47 Nit: document these members.
ygorshenin1 2012/07/16 10:29:44 Done.
179 190
180 // How to do source port binding, used only when UDPSocket is part of 191 // How to do source port binding, used only when UDPSocket is part of
181 // UDPClientSocket, since UDPServerSocket provides Bind. 192 // UDPClientSocket, since UDPServerSocket provides Bind.
182 DatagramSocket::BindType bind_type_; 193 DatagramSocket::BindType bind_type_;
183 194
184 // PRNG function for generating port numbers. 195 // PRNG function for generating port numbers.
185 RandIntCallback rand_int_cb_; 196 RandIntCallback rand_int_cb_;
186 197
187 // These are mutable since they're just cached copies to make 198 // These are mutable since they're just cached copies to make
188 // GetPeerAddress/GetLocalAddress smarter. 199 // GetPeerAddress/GetLocalAddress smarter.
(...skipping 25 matching lines...) Expand all
214 CompletionCallback write_callback_; 225 CompletionCallback write_callback_;
215 226
216 BoundNetLog net_log_; 227 BoundNetLog net_log_;
217 228
218 DISALLOW_COPY_AND_ASSIGN(UDPSocketLibevent); 229 DISALLOW_COPY_AND_ASSIGN(UDPSocketLibevent);
219 }; 230 };
220 231
221 } // namespace net 232 } // namespace net
222 233
223 #endif // NET_UDP_UDP_SOCKET_LIBEVENT_H_ 234 #endif // NET_UDP_UDP_SOCKET_LIBEVENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698