Index: webrtc/base/virtualsocketserver.h |
diff --git a/webrtc/base/virtualsocketserver.h b/webrtc/base/virtualsocketserver.h |
index 8673d40f839f02a16a7471b9f8d46fd4ca7fce8f..565222bfd2453357f6c22204446b21a92b5df93d 100644 |
--- a/webrtc/base/virtualsocketserver.h |
+++ b/webrtc/base/virtualsocketserver.h |
@@ -90,6 +90,16 @@ class VirtualSocketServer : public SocketServer, public sigslot::has_slots<> { |
drop_prob_ = drop_prob; |
} |
+ // If |blocked| is true, subsequent attempts to send will result in -1 being |
+ // returned, with the socket error set to EWOULDBLOCK. |
+ // |
+ // If this method is later called with |blocked| set to false, any sockets |
+ // that previously failed to send with EWOULDBLOCK will emit SignalWriteEvent. |
+ // |
+ // This can be used to simulate the send buffer on a network interface being |
+ // full, and test functionality related to EWOULDBLOCK/SignalWriteEvent. |
+ void SetSendingBlocked(bool blocked); |
+ |
// SocketFactory: |
Socket* CreateSocket(int type) override; |
Socket* CreateSocket(int family, int type) override; |
@@ -223,6 +233,9 @@ class VirtualSocketServer : public SocketServer, public sigslot::has_slots<> { |
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; |
@@ -251,12 +264,15 @@ class VirtualSocketServer : public SocketServer, public sigslot::has_slots<> { |
CriticalSection delay_crit_; |
double drop_prob_; |
+ bool sending_blocked_ = false; |
RTC_DISALLOW_COPY_AND_ASSIGN(VirtualSocketServer); |
}; |
// Implements the socket interface using the virtual network. Packets are |
// passed as messages using the message queue of the socket server. |
-class VirtualSocket : public AsyncSocket, public MessageHandler { |
+class VirtualSocket : public AsyncSocket, |
+ public MessageHandler, |
+ public sigslot::has_slots<> { |
public: |
VirtualSocket(VirtualSocketServer* server, int family, int type, bool async); |
~VirtualSocket() override; |
@@ -316,6 +332,8 @@ class VirtualSocket : public AsyncSocket, public MessageHandler { |
// Used by server sockets to set the local address without binding. |
void SetLocalAddress(const SocketAddress& addr); |
+ void OnSocketServerReadyToSend(); |
+ |
VirtualSocketServer* server_; |
int type_; |
bool async_; |
@@ -330,7 +348,9 @@ class VirtualSocket : public AsyncSocket, public MessageHandler { |
// Data which tcp has buffered for sending |
SendBuffer send_buffer_; |
- bool write_enabled_; |
+ // Set to false if the last attempt to send resulted in EWOULDBLOCK. |
+ // Set back to true when the socket can send again. |
+ bool ready_to_send_ = true; |
// Critical section to protect the recv_buffer and queue_ |
CriticalSection crit_; |