ぐらめぬ・ぜぷつぇんのはてダ(2007 to 2011)

2007年~2011年ごろまで はてなダイアリー に書いてた記事を引っ越してきました。

connect(2)で接続タイムアウト機能を実装したい場合


書きかけ。
基本、APUE-2ndのP563。

If the socket descriptor is in nonblocking mode, which we discuss further in
Section 16.8, connect will return -1 with errno set to the special error code
EINPROGRESS if the connection can't be established immediately. The applicatin can
use ieither poll or select to determine when the file desciptor is writable. At this
point, the connection is complete.

で、実際のコード例が
http://www.developerweb.net/forum/showthread.php?p=13486
に挙がっているので、それ参照。