[关闭]
@zhongdao 2019-05-16T08:18:59.000000Z 字数 1370 阅读 543

ctcs挂掉原因排查

未分类


前言

现象

  1. connection from unknown [ 10.200.1.2 ] at port 39440 at Wed May 15 17:53:58 2019
  2. connection from localhost [ 127.0.0.1 ] at port 60886 at Wed May 15 17:54:02 2019
  3. connection from unknown [ 10.200.1.2 ] at port 39485 at Wed May 15 17:54:02 2019
  4. connection from unknown [ 127.0.0.1 ] at port 60932 at Wed May 15 17:54:07 2019
  5. Use of uninitialized value in subroutine entry at /usr/lib/x86_64-linux-gnu/perl/5.22/Socket.pm line 153.
  6. Bad arg length for Socket::unpack_sockaddr_in, length is 0, should be 16 at /usr/lib/x86_64-linux-gnu/perl/5.22/Socket.pm line 153.
  7. root@sqingpu:~/soft#

分析

  1. use Socket;
  2. socket(Server, PF_INET, SOCK_STREAM, $proto) || die "socket: $!";
  3. setsockopt(Server, SOL_SOCKET, SO_REUSEADDR,
  4. pack("l", 1)) || die "setsockopt: $!";
  5. bind(Server, sockaddr_in($port, INADDR_ANY)) || die "bind: $!";
  6. listen(Server,SOMAXCONN) || die "listen: $!";

改为 IO::Socket

  1. use IO::Socket;
  2. my $Server = IO::Socket::INET->new( Listen => 20,
  3. LocalPort => $port,
  4. Timeout => 5, #60 * 60,
  5. Reuse => 1)
  6. or die "No socket: $!";

c语言代码过程

过程

https://www.perlmonks.org/?node_id=751902

先看操作系统 C语言代码,然后替换

把 socet 换 IO:Socket

初始化

然后

fileno

$foo = &do_accept(*Server{IO});

my server->accept();

$Server->fileno()

参考资料

https://perldoc.perl.org/Socket.html

https://metacpan.org/release/IO/source/lib/IO/Socket.pm
https://metacpan.org/pod/IO%3A%3ASocket

Problem extracting socket from fileno
https://www.perlmonks.org/?node_id=751902

IO::Socket vs Socket do I “use” both?
https://stackoverflow.com/questions/22150346/iosocket-vs-socket-do-i-use-both

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注