Socket Programming: Connect with timeout

http://developerweb.net/forum/showthread.php?p=13486
關鍵是下列幾行:
// Set non-blocking
if( (arg = fcntl(soc, F_GETFL, NULL)) < 0) {
fprintf(stderr, "Error fcntl(..., F_GETFL) (%s)\n", strerror(errno));
exit(0);
}
arg = O_NONBLOCK;
if( fcntl(soc, F_SETFL, arg) < 0) {
fprintf(stderr, "Error fcntl(..., F_SETFL) (%s)\n", strerror(errno));
exit(0);
}

留言

這個網誌中的熱門文章

RTC & CMOS 技術詳解

[自由網路] 如何取得 Google Drive (真實)外連位址 (Direct Link)