如何解决或诊断一个问题,其中sysread()在Perl脚本块读取无限期和意外?



我有一些代码与ADAM模块(Advantech的以太网I/O模块,ADAM-6000/6200系列)通信,它连接到套接字,并在循环中成功读取数据,它过去工作得很好,但现在它停止并等待sysread()完成,永远不会完成。

我能做些什么来帮助解决或进一步诊断这个问题?

socket($socket, PF_INET, SOCK_STREAM, getprotobyname('tcp')) or die "Unable to Connect";
connect($socket, sockaddr_in('1000', inet_aton($ip_address)
....
print "nndo_command() begin:n";
print "Send: " . Data::Dumper::qquote($str) . "n";
syswrite($socket, $str);
usleep(600000);
print "Wrote to socketn";
print "Waiting on sysread to finish...n";
my $bytes = sysread($socket, $data_line, 200);
print "Data Read: " . Data::Dumper::qquote($data_line) . "n";
print "Bytes Read: $bytesn";

do_command() begin:
Send: "#01r"
Wrote to socket
Waiting on sysread to finish...

脚本执行不超过最后一行。在我重新启动脚本后,它再次工作了一点,然后在同一个地方再次停止。通常,脚本在循环中无限期地执行这些指令。

strace输出

write(4, "#01r", 4)                    = 4
clock_nanosleep(CLOCK_REALTIME, 0, {tv_sec=0, tv_nsec=600000000}, NULL) = 0
write(1, "Wrote to socketn", 16)       = 16
write(1, "Waiting on sysread to finish...n", 32) = 32
read(4, ">+00.018+00.016+00.020+00.008-00"..., 200) = 58
write(1, "Data Read: ">+00.018+00.016+00.0"..., 73) = 73
write(1, "Bytes Read: 58n", 15)        = 15
write(1, "n", 1)                       = 1
write(1, "Sleeping for .1 secondsn", 24) = 24
clock_nanosleep(CLOCK_REALTIME, 0, {tv_sec=0, tv_nsec=100000000}, NULL) = 0
write(1, "Read Cyclen", 11)            = 11
write(1, "nndo_command() begin:n", 22) = 22
write(1, "Send: "#01\r"n", 14)      = 14
write(4, "#01r", 4)                    = 4
clock_nanosleep(CLOCK_REALTIME, 0, {tv_sec=0, tv_nsec=600000000}, NULL) = 0
write(1, "Wrote to socketn", 16)       = 16
write(1, "Waiting on sysread to finish...n", 32) = 32
read(4,

重新启动远程计算机已解决问题。

最新更新