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

Side by Side Diff: webrtc/base/virtualsocketserver.h

Issue 1362503003: Use suffixed {uint,int}{8,16,32,64}_t types. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase + revert basictypes.h (to be landed separately just in case of a revert due to unexpected us… Created 5 years, 2 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
« no previous file with comments | « webrtc/base/virtualsocket_unittest.cc ('k') | webrtc/base/virtualsocketserver.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 27 matching lines...) Expand all
38 38
39 SocketServer* socketserver() { return server_; } 39 SocketServer* socketserver() { return server_; }
40 40
41 // The default route indicates which local address to use when a socket is 41 // The default route indicates which local address to use when a socket is
42 // bound to the 'any' address, e.g. 0.0.0.0. 42 // bound to the 'any' address, e.g. 0.0.0.0.
43 IPAddress GetDefaultRoute(int family); 43 IPAddress GetDefaultRoute(int family);
44 void SetDefaultRoute(const IPAddress& from_addr); 44 void SetDefaultRoute(const IPAddress& from_addr);
45 45
46 // Limits the network bandwidth (maximum bytes per second). Zero means that 46 // Limits the network bandwidth (maximum bytes per second). Zero means that
47 // all sends occur instantly. Defaults to 0. 47 // all sends occur instantly. Defaults to 0.
48 uint32 bandwidth() const { return bandwidth_; } 48 uint32_t bandwidth() const { return bandwidth_; }
49 void set_bandwidth(uint32 bandwidth) { bandwidth_ = bandwidth; } 49 void set_bandwidth(uint32_t bandwidth) { bandwidth_ = bandwidth; }
50 50
51 // Limits the amount of data which can be in flight on the network without 51 // Limits the amount of data which can be in flight on the network without
52 // packet loss (on a per sender basis). Defaults to 64 KB. 52 // packet loss (on a per sender basis). Defaults to 64 KB.
53 uint32 network_capacity() const { return network_capacity_; } 53 uint32_t network_capacity() const { return network_capacity_; }
54 void set_network_capacity(uint32 capacity) { 54 void set_network_capacity(uint32_t capacity) { network_capacity_ = capacity; }
55 network_capacity_ = capacity;
56 }
57 55
58 // The amount of data which can be buffered by tcp on the sender's side 56 // The amount of data which can be buffered by tcp on the sender's side
59 uint32 send_buffer_capacity() const { return send_buffer_capacity_; } 57 uint32_t send_buffer_capacity() const { return send_buffer_capacity_; }
60 void set_send_buffer_capacity(uint32 capacity) { 58 void set_send_buffer_capacity(uint32_t capacity) {
61 send_buffer_capacity_ = capacity; 59 send_buffer_capacity_ = capacity;
62 } 60 }
63 61
64 // The amount of data which can be buffered by tcp on the receiver's side 62 // The amount of data which can be buffered by tcp on the receiver's side
65 uint32 recv_buffer_capacity() const { return recv_buffer_capacity_; } 63 uint32_t recv_buffer_capacity() const { return recv_buffer_capacity_; }
66 void set_recv_buffer_capacity(uint32 capacity) { 64 void set_recv_buffer_capacity(uint32_t capacity) {
67 recv_buffer_capacity_ = capacity; 65 recv_buffer_capacity_ = capacity;
68 } 66 }
69 67
70 // Controls the (transit) delay for packets sent in the network. This does 68 // Controls the (transit) delay for packets sent in the network. This does
71 // not inclue the time required to sit in the send queue. Both of these 69 // not inclue the time required to sit in the send queue. Both of these
72 // values are measured in milliseconds. Defaults to no delay. 70 // values are measured in milliseconds. Defaults to no delay.
73 uint32 delay_mean() const { return delay_mean_; } 71 uint32_t delay_mean() const { return delay_mean_; }
74 uint32 delay_stddev() const { return delay_stddev_; } 72 uint32_t delay_stddev() const { return delay_stddev_; }
75 uint32 delay_samples() const { return delay_samples_; } 73 uint32_t delay_samples() const { return delay_samples_; }
76 void set_delay_mean(uint32 delay_mean) { delay_mean_ = delay_mean; } 74 void set_delay_mean(uint32_t delay_mean) { delay_mean_ = delay_mean; }
77 void set_delay_stddev(uint32 delay_stddev) { 75 void set_delay_stddev(uint32_t delay_stddev) { delay_stddev_ = delay_stddev; }
78 delay_stddev_ = delay_stddev; 76 void set_delay_samples(uint32_t delay_samples) {
79 }
80 void set_delay_samples(uint32 delay_samples) {
81 delay_samples_ = delay_samples; 77 delay_samples_ = delay_samples;
82 } 78 }
83 79
84 // If the (transit) delay parameters are modified, this method should be 80 // If the (transit) delay parameters are modified, this method should be
85 // called to recompute the new distribution. 81 // called to recompute the new distribution.
86 void UpdateDelayDistribution(); 82 void UpdateDelayDistribution();
87 83
88 // Controls the (uniform) probability that any sent packet is dropped. This 84 // Controls the (uniform) probability that any sent packet is dropped. This
89 // is separate from calculations to drop based on queue size. 85 // is separate from calculations to drop based on queue size.
90 double drop_probability() { return drop_prob_; } 86 double drop_probability() { return drop_prob_; }
(...skipping 10 matching lines...) Expand all
101 AsyncSocket* CreateAsyncSocket(int family, int type) override; 97 AsyncSocket* CreateAsyncSocket(int family, int type) override;
102 98
103 // SocketServer: 99 // SocketServer:
104 void SetMessageQueue(MessageQueue* queue) override; 100 void SetMessageQueue(MessageQueue* queue) override;
105 bool Wait(int cms, bool process_io) override; 101 bool Wait(int cms, bool process_io) override;
106 void WakeUp() override; 102 void WakeUp() override;
107 103
108 typedef std::pair<double, double> Point; 104 typedef std::pair<double, double> Point;
109 typedef std::vector<Point> Function; 105 typedef std::vector<Point> Function;
110 106
111 static Function* CreateDistribution(uint32 mean, uint32 stddev, 107 static Function* CreateDistribution(uint32_t mean,
112 uint32 samples); 108 uint32_t stddev,
109 uint32_t samples);
113 110
114 // Similar to Thread::ProcessMessages, but it only processes messages until 111 // Similar to Thread::ProcessMessages, but it only processes messages until
115 // there are no immediate messages or pending network traffic. Returns false 112 // there are no immediate messages or pending network traffic. Returns false
116 // if Thread::Stop() was called. 113 // if Thread::Stop() was called.
117 bool ProcessMessagesUntilIdle(); 114 bool ProcessMessagesUntilIdle();
118 115
119 // Sets the next port number to use for testing. 116 // Sets the next port number to use for testing.
120 void SetNextPortForTesting(uint16 port); 117 void SetNextPortForTesting(uint16_t port);
121 118
122 // Close a pair of Tcp connections by addresses. Both connections will have 119 // Close a pair of Tcp connections by addresses. Both connections will have
123 // its own OnClose invoked. 120 // its own OnClose invoked.
124 bool CloseTcpConnections(const SocketAddress& addr_local, 121 bool CloseTcpConnections(const SocketAddress& addr_local,
125 const SocketAddress& addr_remote); 122 const SocketAddress& addr_remote);
126 123
127 protected: 124 protected:
128 // Returns a new IP not used before in this network. 125 // Returns a new IP not used before in this network.
129 IPAddress GetNextIP(int family); 126 IPAddress GetNextIP(int family);
130 uint16 GetNextPort(); 127 uint16_t GetNextPort();
131 128
132 VirtualSocket* CreateSocketInternal(int family, int type); 129 VirtualSocket* CreateSocketInternal(int family, int type);
133 130
134 // Binds the given socket to addr, assigning and IP and Port if necessary 131 // Binds the given socket to addr, assigning and IP and Port if necessary
135 int Bind(VirtualSocket* socket, SocketAddress* addr); 132 int Bind(VirtualSocket* socket, SocketAddress* addr);
136 133
137 // Binds the given socket to the given (fully-defined) address. 134 // Binds the given socket to the given (fully-defined) address.
138 int Bind(VirtualSocket* socket, const SocketAddress& addr); 135 int Bind(VirtualSocket* socket, const SocketAddress& addr);
139 136
140 // Find the socket bound to the given address 137 // Find the socket bound to the given address
(...skipping 21 matching lines...) Expand all
162 bool Disconnect(VirtualSocket* socket); 159 bool Disconnect(VirtualSocket* socket);
163 160
164 // Sends the given packet to the socket at the given address (if one exists). 161 // Sends the given packet to the socket at the given address (if one exists).
165 int SendUdp(VirtualSocket* socket, const char* data, size_t data_size, 162 int SendUdp(VirtualSocket* socket, const char* data, size_t data_size,
166 const SocketAddress& remote_addr); 163 const SocketAddress& remote_addr);
167 164
168 // Moves as much data as possible from the sender's buffer to the network 165 // Moves as much data as possible from the sender's buffer to the network
169 void SendTcp(VirtualSocket* socket); 166 void SendTcp(VirtualSocket* socket);
170 167
171 // Places a packet on the network. 168 // Places a packet on the network.
172 void AddPacketToNetwork(VirtualSocket* socket, VirtualSocket* recipient, 169 void AddPacketToNetwork(VirtualSocket* socket,
173 uint32 cur_time, const char* data, size_t data_size, 170 VirtualSocket* recipient,
174 size_t header_size, bool ordered); 171 uint32_t cur_time,
172 const char* data,
173 size_t data_size,
174 size_t header_size,
175 bool ordered);
175 176
176 // Removes stale packets from the network 177 // Removes stale packets from the network
177 void PurgeNetworkPackets(VirtualSocket* socket, uint32 cur_time); 178 void PurgeNetworkPackets(VirtualSocket* socket, uint32_t cur_time);
178 179
179 // Computes the number of milliseconds required to send a packet of this size. 180 // Computes the number of milliseconds required to send a packet of this size.
180 uint32 SendDelay(uint32 size); 181 uint32_t SendDelay(uint32_t size);
181 182
182 // Returns a random transit delay chosen from the appropriate distribution. 183 // Returns a random transit delay chosen from the appropriate distribution.
183 uint32 GetRandomTransitDelay(); 184 uint32_t GetRandomTransitDelay();
184 185
185 // Basic operations on functions. Those that return a function also take 186 // Basic operations on functions. Those that return a function also take
186 // ownership of the function given (and hence, may modify or delete it). 187 // ownership of the function given (and hence, may modify or delete it).
187 static Function* Accumulate(Function* f); 188 static Function* Accumulate(Function* f);
188 static Function* Invert(Function* f); 189 static Function* Invert(Function* f);
189 static Function* Resample(Function* f, double x1, double x2, uint32 samples); 190 static Function* Resample(Function* f,
191 double x1,
192 double x2,
193 uint32_t samples);
190 static double Evaluate(Function* f, double x); 194 static double Evaluate(Function* f, double x);
191 195
192 // NULL out our message queue if it goes away. Necessary in the case where 196 // NULL out our message queue if it goes away. Necessary in the case where
193 // our lifetime is greater than that of the thread we are using, since we 197 // our lifetime is greater than that of the thread we are using, since we
194 // try to send Close messages for all connected sockets when we shutdown. 198 // try to send Close messages for all connected sockets when we shutdown.
195 void OnMessageQueueDestroyed() { msg_queue_ = NULL; } 199 void OnMessageQueueDestroyed() { msg_queue_ = NULL; }
196 200
197 // Determine if two sockets should be able to communicate. 201 // Determine if two sockets should be able to communicate.
198 // We don't (currently) specify an address family for sockets; instead, 202 // We don't (currently) specify an address family for sockets; instead,
199 // the currently bound address is used to infer the address family. 203 // the currently bound address is used to infer the address family.
(...skipping 15 matching lines...) Expand all
215 private: 219 private:
216 friend class VirtualSocket; 220 friend class VirtualSocket;
217 221
218 typedef std::map<SocketAddress, VirtualSocket*> AddressMap; 222 typedef std::map<SocketAddress, VirtualSocket*> AddressMap;
219 typedef std::map<SocketAddressPair, VirtualSocket*> ConnectionMap; 223 typedef std::map<SocketAddressPair, VirtualSocket*> ConnectionMap;
220 224
221 SocketServer* server_; 225 SocketServer* server_;
222 bool server_owned_; 226 bool server_owned_;
223 MessageQueue* msg_queue_; 227 MessageQueue* msg_queue_;
224 bool stop_on_idle_; 228 bool stop_on_idle_;
225 uint32 network_delay_; 229 uint32_t network_delay_;
226 in_addr next_ipv4_; 230 in_addr next_ipv4_;
227 in6_addr next_ipv6_; 231 in6_addr next_ipv6_;
228 uint16 next_port_; 232 uint16_t next_port_;
229 AddressMap* bindings_; 233 AddressMap* bindings_;
230 ConnectionMap* connections_; 234 ConnectionMap* connections_;
231 235
232 IPAddress default_route_v4_; 236 IPAddress default_route_v4_;
233 IPAddress default_route_v6_; 237 IPAddress default_route_v6_;
234 238
235 uint32 bandwidth_; 239 uint32_t bandwidth_;
236 uint32 network_capacity_; 240 uint32_t network_capacity_;
237 uint32 send_buffer_capacity_; 241 uint32_t send_buffer_capacity_;
238 uint32 recv_buffer_capacity_; 242 uint32_t recv_buffer_capacity_;
239 uint32 delay_mean_; 243 uint32_t delay_mean_;
240 uint32 delay_stddev_; 244 uint32_t delay_stddev_;
241 uint32 delay_samples_; 245 uint32_t delay_samples_;
242 Function* delay_dist_; 246 Function* delay_dist_;
243 CriticalSection delay_crit_; 247 CriticalSection delay_crit_;
244 248
245 double drop_prob_; 249 double drop_prob_;
246 RTC_DISALLOW_COPY_AND_ASSIGN(VirtualSocketServer); 250 RTC_DISALLOW_COPY_AND_ASSIGN(VirtualSocketServer);
247 }; 251 };
248 252
249 // Implements the socket interface using the virtual network. Packets are 253 // Implements the socket interface using the virtual network. Packets are
250 // passed as messages using the message queue of the socket server. 254 // passed as messages using the message queue of the socket server.
251 class VirtualSocket : public AsyncSocket, public MessageHandler { 255 class VirtualSocket : public AsyncSocket, public MessageHandler {
(...skipping 17 matching lines...) Expand all
269 int Recv(void* pv, size_t cb) override; 273 int Recv(void* pv, size_t cb) override;
270 int RecvFrom(void* pv, size_t cb, SocketAddress* paddr) override; 274 int RecvFrom(void* pv, size_t cb, SocketAddress* paddr) override;
271 int Listen(int backlog) override; 275 int Listen(int backlog) override;
272 VirtualSocket* Accept(SocketAddress* paddr) override; 276 VirtualSocket* Accept(SocketAddress* paddr) override;
273 277
274 int GetError() const override; 278 int GetError() const override;
275 void SetError(int error) override; 279 void SetError(int error) override;
276 ConnState GetState() const override; 280 ConnState GetState() const override;
277 int GetOption(Option opt, int* value) override; 281 int GetOption(Option opt, int* value) override;
278 int SetOption(Option opt, int value) override; 282 int SetOption(Option opt, int value) override;
279 int EstimateMTU(uint16* mtu) override; 283 int EstimateMTU(uint16_t* mtu) override;
280 void OnMessage(Message* pmsg) override; 284 void OnMessage(Message* pmsg) override;
281 285
282 bool was_any() { return was_any_; } 286 bool was_any() { return was_any_; }
283 void set_was_any(bool was_any) { was_any_ = was_any; } 287 void set_was_any(bool was_any) { was_any_ = was_any; }
284 288
285 // For testing purpose only. Fired when client socket is bound to an address. 289 // For testing purpose only. Fired when client socket is bound to an address.
286 sigslot::signal2<VirtualSocket*, const SocketAddress&> SignalAddressReady; 290 sigslot::signal2<VirtualSocket*, const SocketAddress&> SignalAddressReady;
287 291
288 private: 292 private:
289 struct NetworkEntry { 293 struct NetworkEntry {
290 size_t size; 294 size_t size;
291 uint32 done_time; 295 uint32_t done_time;
292 }; 296 };
293 297
294 typedef std::deque<SocketAddress> ListenQueue; 298 typedef std::deque<SocketAddress> ListenQueue;
295 typedef std::deque<NetworkEntry> NetworkQueue; 299 typedef std::deque<NetworkEntry> NetworkQueue;
296 typedef std::vector<char> SendBuffer; 300 typedef std::vector<char> SendBuffer;
297 typedef std::list<Packet*> RecvBuffer; 301 typedef std::list<Packet*> RecvBuffer;
298 typedef std::map<Option, int> OptionsMap; 302 typedef std::map<Option, int> OptionsMap;
299 303
300 int InitiateConnect(const SocketAddress& addr, bool use_delay); 304 int InitiateConnect(const SocketAddress& addr, bool use_delay);
301 void CompleteConnect(const SocketAddress& addr, bool notify); 305 void CompleteConnect(const SocketAddress& addr, bool notify);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 348
345 // Store the options that are set 349 // Store the options that are set
346 OptionsMap options_map_; 350 OptionsMap options_map_;
347 351
348 friend class VirtualSocketServer; 352 friend class VirtualSocketServer;
349 }; 353 };
350 354
351 } // namespace rtc 355 } // namespace rtc
352 356
353 #endif // WEBRTC_BASE_VIRTUALSOCKETSERVER_H_ 357 #endif // WEBRTC_BASE_VIRTUALSOCKETSERVER_H_
OLDNEW
« no previous file with comments | « webrtc/base/virtualsocket_unittest.cc ('k') | webrtc/base/virtualsocketserver.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698