io-socket

How do I set `SO_RCVTIMEO` on a socket in Perl?

别等时光非礼了梦想. 提交于 2019-12-02 08:26:42
问题 If I try like this: my $sock = IO::Socket::INET->new( … ) or die "no socket for you"; defined $sock->setsockopt(SOL_SOCKET, SO_RCVTIMEO, 30) or die "setsockopt: $!"; then my script suffers death from "setsockopt: Invalid argument at [line 2]". The IO::Socket and perlfunc pods do not say, though perlfunc gives an example with TCP_NODELAY which makes it look like the above should work. ( quick note: I've answered my own question, as best I can, but certainly welcome a better answer. The most

How do I set `SO_RCVTIMEO` on a socket in Perl?

谁说我不能喝 提交于 2019-12-02 07:15:51
If I try like this: my $sock = IO::Socket::INET->new( … ) or die "no socket for you"; defined $sock->setsockopt(SOL_SOCKET, SO_RCVTIMEO, 30) or die "setsockopt: $!"; then my script suffers death from "setsockopt: Invalid argument at [line 2]". The IO::Socket and perlfunc pods do not say, though perlfunc gives an example with TCP_NODELAY which makes it look like the above should work. ( quick note: I've answered my own question, as best I can, but certainly welcome a better answer. The most obvious "better" would be for it to be portable, at least on POSIX machines) By using strace on the Perl