Unfortunately, gethostbyname is not reentrant. (maybe a stupid question) Is there any particular reason why you cannot use multiple processes instead?
Typed on a very small keyboard... ------------------------------ From: Jesper Persson <jesper.j.pers...@gmail.com> Sent: 29/05/2013 07:17 To: libwww <libwww@perl.org> Subject: is IO:Socket:INET thread safe? Hi everybody, I have a multithreaded program that monitors the content of web pages. On a newly installed CentOS server I have seen strange behaviour where I get 404 because http request is sent to a wrong ip address not maching the domain that was requested. I have inserted a print statement in IO:Socket:INET.pm in the procedure _get_addr to see what ip address the domain is translated to: sub _get_addr { my($sock,$addr_str, $multi) = @_; my @addr; if ($multi && $addr_str !~ /^\d+(?:\.\d+){3}$/) { (undef, undef, undef, undef, @addr) = gethostbyname($addr_str); } else { my $h = inet_aton($addr_str); push(@addr, $h) if defined $h; } open(FH, ">>/tmp/socket_get_addr.log"); print FH localtime().": addr_str: $addr_str, addr: ".inet_ntoa($addr[0])."\n"; close(FH); @addr; } >From the log file: Wed May 29 07:38:09 2013: addr_str: dk1.siteimprove.com, addr: 93.160.60.57 Wed May 29 07:38:09 2013: addr_str: siteimprove.dk, addr: 93.160.60.57 the ip address of siteimprove.dk is wrong and at the same second just before a lookup of dk1.siteimprove.com gets the same ip address and that is correct. 7 minutes later in the log file the siteimprove.dk domain is looked up correctly: Wed May 29 07:45:11 2013: addr_str: siteimprove.dk, addr: 93.160.60.87 Manually looking up the ip on then server gets the right ip address. this entry is in the hosts file: 93.160.60.87 siteimprove.dk CentOS release 6.3 (Final) Summary of my perl5 (revision 5 version 10 subversion 1) configuration: IO:Socket:INET version: $VERSION = "1.31"; Any help would be greatly appreciated. Regards Jesper Persson