いわおかです。

神戸さんのテストプログラムですが、相手によっては EALREADY の時間が
長いので、以下のように変更して実行しました。

--- contest.c.orig	Tue Aug 19 10:38:36 2003
+++ contest.c	Tue Aug 19 10:32:31 2003
@@ -81,6 +81,7 @@
 		perror("connect");
 		switch (errno) {
 		case EAGAIN:
+		case EALREADY:
 		case EINPROGRESS:
 #if (GETSOCKOPT_AFTER_EINPROGRESS == 1)
 			len = sizeof(value);

結果は以下のとおりです。

% uname -a
FreeBSD xxxx.fe.rn.tuat.ac.jp 4.8-STABLE FreeBSD 4.8-STABLE #4: Thu Jul 31 14:25:33 JST 2003     iwaoka / xxxx.fe.rn.tuat.ac.jp:/usr/obj/usr/src/sys/XXXX  i386
% ./a.out 165.93.213.34 12345
connect to family = 2, port = 12345, addr = 165.93.213.34
connect: Operation now in progress
getsockopt => 0
connect to family = 2, port = 12345, addr = 165.93.213.34
connect: Operation already in progress
getsockopt => 0
(中略)
connect to family = 2, port = 12345, addr = 165.93.213.34
connect: Operation already in progress
getsockopt => 0
connect to family = 2, port = 12345, addr = 165.93.213.34
connect: Invalid argument
getsockopt => Connection refused

ということで、EINVAL になっていることが確認できました。

In the message <6B1D9A46-D1E4-11D7-845E-0003936E4BC8 / verama.net>,
  on Tue, Aug 19, 2003 at 10:28:23AM +0900, Mitsuru Ogino wrote:
> $ uname -a
> FreeBSD xxx.verama.net 5.1-RELEASE FreeBSD 5.1-RELEASE #1:
> Mon Aug 11 21:39:49 JST 2003
> root / xxx.xxx.xxx:/usr/src/sys/i386/compile/VIC i386
> 
> $ ./a.out 192.168.0.xxx 12345
> connect to family = 2, port = 12345, addr = 192.168.0.xxx
> connect: Operation now in progress
> getsockopt => 0
> connect to family = 2, port = 12345, addr = 192.168.0.xxx
> connect: Operation already in progress
> 
> $ ./a.out localhost 12345
> connect to family = 2, port = 12345, addr = 127.0.0.1
> connect: Operation now in progress
> getsockopt => Connection refused
> connect to family = 2, port = 12345, addr = 127.0.0.1
> connect: Invalid argument
> getsockopt => 0

こちらも、EALREADY の処理を入れると同じようになりそうですね。

いわおか