Delete friendship between VirtualSocket and VirtualSocketServer
Bug: webrtc:11567
Change-Id: I07d01b9eed798a69ba798e899b2bae57409ce332
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/207181
Reviewed-by: Tommi <tommi@webrtc.org>
Commit-Queue: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33276}
diff --git a/rtc_base/virtual_socket_server.h b/rtc_base/virtual_socket_server.h
index cb60f80..cec5225 100644
--- a/rtc_base/virtual_socket_server.h
+++ b/rtc_base/virtual_socket_server.h
@@ -151,25 +151,12 @@
// socket server. Intended to be used for test assertions.
uint32_t sent_packets() const { return sent_packets_; }
- // For testing purpose only. Fired when a client socket is created.
- sigslot::signal1<VirtualSocket*> SignalSocketCreated;
-
- protected:
- // Returns a new IP not used before in this network.
- IPAddress GetNextIP(int family);
- uint16_t GetNextPort();
-
- VirtualSocket* CreateSocketInternal(int family, int type);
-
// Binds the given socket to addr, assigning and IP and Port if necessary
int Bind(VirtualSocket* socket, SocketAddress* addr);
// Binds the given socket to the given (fully-defined) address.
int Bind(VirtualSocket* socket, const SocketAddress& addr);
- // Find the socket bound to the given address
- VirtualSocket* LookupBinding(const SocketAddress& addr);
-
int Unbind(const SocketAddress& addr, VirtualSocket* socket);
// Adds a mapping between this socket pair and the socket.
@@ -177,13 +164,6 @@
const SocketAddress& server,
VirtualSocket* socket);
- // Find the socket pair corresponding to this server address.
- VirtualSocket* LookupConnection(const SocketAddress& client,
- const SocketAddress& server);
-
- void RemoveConnection(const SocketAddress& client,
- const SocketAddress& server);
-
// Connects the given socket to the socket at the given address
int Connect(VirtualSocket* socket,
const SocketAddress& remote_addr,
@@ -192,6 +172,13 @@
// Sends a disconnect message to the socket at the given address
bool Disconnect(VirtualSocket* socket);
+ // Lookup address, and disconnect corresponding socket.
+ bool Disconnect(const SocketAddress& addr);
+
+ // Lookup connection, close corresponding socket.
+ bool Disconnect(const SocketAddress& local_addr,
+ const SocketAddress& remote_addr);
+
// Sends the given packet to the socket at the given address (if one exists).
int SendUdp(VirtualSocket* socket,
const char* data,
@@ -201,6 +188,44 @@
// Moves as much data as possible from the sender's buffer to the network
void SendTcp(VirtualSocket* socket);
+ // Like above, but lookup sender by address.
+ void SendTcp(const SocketAddress& addr);
+
+ // Computes the number of milliseconds required to send a packet of this size.
+ uint32_t SendDelay(uint32_t size);
+
+ // Cancel attempts to connect to a socket that is being closed.
+ void CancelConnects(VirtualSocket* socket);
+
+ // Clear incoming messages for a socket that is being closed.
+ void Clear(VirtualSocket* socket);
+
+ void ProcessOneMessage();
+
+ void PostSignalReadEvent(VirtualSocket* socket);
+
+ // Sending was previously blocked, but now isn't.
+ sigslot::signal0<> SignalReadyToSend;
+
+ protected:
+ // Returns a new IP not used before in this network.
+ IPAddress GetNextIP(int family);
+
+ // Find the socket bound to the given address
+ VirtualSocket* LookupBinding(const SocketAddress& addr);
+
+ private:
+ uint16_t GetNextPort();
+
+ VirtualSocket* CreateSocketInternal(int family, int type);
+
+ // Find the socket pair corresponding to this server address.
+ VirtualSocket* LookupConnection(const SocketAddress& client,
+ const SocketAddress& server);
+
+ void RemoveConnection(const SocketAddress& client,
+ const SocketAddress& server);
+
// Places a packet on the network.
void AddPacketToNetwork(VirtualSocket* socket,
VirtualSocket* recipient,
@@ -210,12 +235,6 @@
size_t header_size,
bool ordered);
- // Removes stale packets from the network
- void PurgeNetworkPackets(VirtualSocket* socket, int64_t cur_time);
-
- // Computes the number of milliseconds required to send a packet of this size.
- uint32_t SendDelay(uint32_t size);
-
// If the delay has been set for the address of the socket, returns the set
// delay. Otherwise, returns a random transit delay chosen from the
// appropriate distribution.
@@ -253,12 +272,6 @@
// NB: This scheme doesn't permit non-dualstack IPv6 sockets.
static bool CanInteractWith(VirtualSocket* local, VirtualSocket* remote);
- private:
- friend class VirtualSocket;
-
- // Sending was previously blocked, but now isn't.
- sigslot::signal0<> SignalReadyToSend;
-
typedef std::map<SocketAddress, VirtualSocket*> AddressMap;
typedef std::map<SocketAddressPair, VirtualSocket*> ConnectionMap;
@@ -331,9 +344,31 @@
int SetOption(Option opt, int value) override;
void OnMessage(Message* pmsg) override;
+ size_t recv_buffer_size() const { return recv_buffer_size_; }
+ size_t send_buffer_size() const { return send_buffer_.size(); }
+ const char* send_buffer_data() const { return send_buffer_.data(); }
+
+ // Used by server sockets to set the local address without binding.
+ void SetLocalAddress(const SocketAddress& addr);
+
bool was_any() { return was_any_; }
void set_was_any(bool was_any) { was_any_ = was_any; }
+ void SetToBlocked();
+
+ void UpdateRecv(size_t data_size);
+ void UpdateSend(size_t data_size);
+
+ void MaybeSignalWriteEvent(size_t capacity);
+
+ // Adds a packet to be sent. Returns delay, based on network_size_.
+ uint32_t AddPacket(int64_t cur_time, size_t packet_size);
+
+ int64_t UpdateOrderedDelivery(int64_t ts);
+
+ // Removes stale packets from the network. Returns current size.
+ size_t PurgeNetworkPackets(int64_t cur_time);
+
// For testing purpose only. Fired when client socket is bound to an address.
sigslot::signal2<VirtualSocket*, const SocketAddress&> SignalAddressReady;
@@ -354,9 +389,6 @@
int SendUdp(const void* pv, size_t cb, const SocketAddress& addr);
int SendTcp(const void* pv, size_t cb);
- // Used by server sockets to set the local address without binding.
- void SetLocalAddress(const SocketAddress& addr);
-
void OnSocketServerReadyToSend();
VirtualSocketServer* server_;
@@ -402,8 +434,6 @@
// Store the options that are set
OptionsMap options_map_;
-
- friend class VirtualSocketServer;
};
} // namespace rtc