1
votes

when using connect() in a tcp client program or accept() in a tcp server program many possible exceptions may happen e.g, TCP SYN or TCP SYN/ACK is lost OR some other errors

(BTW, I'm wondering ,if TCP SYN is lots, will connect() retransmit TCP SYN or it just produces an error?)

ususally the source codes are like

if(connect()<0){
 ...
 exit(1);
}

or

if (accept()<)){
 ...
 exit(1);
}

however, if I want to try connect() or accept() again, is it possible or not? like

while(connect()<0){
       continue;
}

or

while(accept()<0){
      continue;
}

will such a dealing produce unacceptable consequences?

besides, how about send() and recv() thanks!

1
Elegance has nothing to do with it. The question, what is your functional requirement?user207421

1 Answers

0
votes

Generally once and accept or connect fails, they will always fail, so your while loops are just infinite loop on failure. There are some exceptions (non-blocking sockets that 'fail' with EINPROGRESS or EAGAIN), but generally when there's an error, you need to check the error code and do something appropriate, such as closing the socket and opening a new one.