i writing small network utility, in somewhere in code have following lines:
if (connect(sock, addr_result->ai_addr, addr_result->ai_addrlen) < 0) syserr("connect");
i have 2 questions regarding timeouts:
- how can set timeout
connect()
using linux api? - if wanted measure timeout myself, correct way this?
register signal handler sigalarm. set alarm before calling connect , clear alarm after connect returns, if hit signal handler it's connection timeout.