Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your code accepts one connection and then relays one block of data on one direction and then never looks at that connection again.</p> <p>Your second chunk of code has a variety of problems, but the big one is that it can deadlock. During your call to <code>B.sendall</code>, if <code>B</code> refuses to read any data until it is able to finish sending to <code>A</code>, which may be legal in the protocol you're relaying, your proxy and <code>B</code> will be waiting for each other forever because your proxy refuses to read any data from <code>B</code> until it finishes sending.</p> <p>A proper relays must attempt to do four things at once and may not wait for one thing to finish before starting another. These four things are:</p> <p>1) Read from connection A. (Unless a large amount of data is already backed up.)</p> <p>2) Read from connection B. (Unless a large amount of data is already backed up.)</p> <p>3) Write to connection A. (Unless there is no unrelayed data that has been received from connection B.)</p> <p>4) Write to connection B. (unless there is no unrelayed data that has been received from connection A.)</p> <p>In particular, you need <em>two</em> buffers, one for unsent data in each direction. You cannot alternate directions because that will require you to wait for one of the nodes to receive data, which can deadlock if that node is waiting for <em>you</em> to receive data.</p> <p>Generally, the simplest way to implement a proxy is with two threads per connection, one for each direction.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload