2009年1月15日 星期四

nonblocking socket connect to handle the conditions of TCP RST and successful established

Connect to the server which listened data on the specific port

socket call sequence:
socket ==> OK
fcntl (set nonblocking mode) > OK
connect (immediately return because the file descriptor is in the nonblocking mode) ==> OK
select write socket (verify if the write socket is available or not) ==> OK
a1. select read socket (verify if the read socket is available or not) ==> OK (if the server will first send the data to the connected client)
a2. recv (recv the data) ==> OK (if the server will first send the data to the connected client)
b1. select read socket (verify if the read socket is available or not) ==> Failed (if the server doesn't send the data to the connected client)
b2. recv (recv the data) ==> No need to call the recv because the recv socket is not ready


Connect to the server which doesn't listen data on the specific port

socket call sequence:
socket ==> OK
fcntl (set nonblocking mode) ==> OK
connect (immediately return because the file descriptor is in the nonblocking mode) ==> OK
select write socket (verify if the write socket is available or not) ==> OK
select read socket (verify if the read socket is available or not) ==> OK
recv (recv the data) ==> return -1

沒有留言: