poorconn.delay_before_sending

poorconn.delay_before_sending(s, t, length=1024)

Chop the content (bytes in socket.socket.send() and socket.socket.sendall()) to be sent in length bytes and delay t seconds before sending every time.

This function achieves the results by patching s’s member methods send() and sendall(). s’s sendfile() method is not patched due to its inconsistent behavior across operating systems.

Parameters
  • s (socket.socket) – The socket.socket object whose sending methods are to be delayed every time.

  • t (float) – Number of seconds to delay.

  • length (int) – Number of bytes of each of the slices into which the content is chopped.

Returns

A DelayBeforeSendingController object that controls the patched socket object.

Return type

poorconn._send.DelayBeforeSendingController