I have a question about calling connect () on a TCP socket implementation. Which means that the call to connect () is not blocked. The connect () call performs a three-way handshake with another socket, sending syn, waiting for SYNACK, and then sending an ACK. The connect () call also returns true if the connection was successful or false if it failed.
If the call does not block, I assume that this means that the connection should return immediately, even if it is still waiting for SYNACK, but in this case it will never be able to return false when it cannot connect, because by that time it has already returned .
So my questions are: - What does it mean that the connect () call is not blocked. - How is the call connect () achieved? Is this only possible with threads? - Im mimicking the tcp stack in java, could you please simplify an example of what a non-blocking version would look like? I included a sketch of what apparently looks something like this: (more complex psuedo code than actual java):
public boolean connect(IpAddress dst, int port){
ipLayer.send(.....,<synpacket>);
try{
ipLayer.receive(...., receivePacket,<timeout>);
} catch( TimeoutException e ){
return false;
}
ipLayer.send(<ackpacket>);
return true;
}
source
share