Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!csn!boulder!spot.Colorado.EDU!frechett From: frechett@spot.Colorado.EDU (-=Runaway Daemon=-) Newsgroups: comp.unix.questions Subject: Perl Socket problem Summary: ^C locks up socket with perl server Keywords: sockets perl Message-ID: <1991May31.095020.15271@colorado.edu> Date: 31 May 91 09:50:20 GMT Sender: news@colorado.edu (The Daily Planet) Organization: University of Colorado, Boulder Lines: 75 Nntp-Posting-Host: spot.colorado.edu I have created an interesting server that runs on my machine. It allows people to browse through an archive that I haev of hp48sx programs. The server is written in perl and it runs on a port of my machine. Code fragment follows. [deleted] $sport = $port; # sport is used by me for record keeping; print "Starting server on port $port\n"; unshift(@INC,"/users/en-ecen/frechett/perl"); require 'socket.ph'; $sockaddr = 'S n a4 x8'; # Template for pack # get protocol from /etc/protocols ($name, $aliases, $proto) = getprotobyname('tcp'); # get service by protocol name ($name, $aliases, $port) = getservbyname($port, 'tcp') unless $port =~ /^\d+$/; $this = pack($sockaddr, &AF_INET, $port, "\0\0\0\0"); select(NS); $| = 1; select(stdout); # Open socket socket(S, &PF_INET, &SOCK_STREAM, $proto) || die "socket: $!"; bind(S, $this) || die "bind: $!"; # Bind name to socket. listen(S, 5) || die "connect: $!"; # Listen for connection select(S); $| = 1; select(stdout); CONNECTION: for (;;) { do appendit("$sport> Listening again\n"); # Log it ($addr = accept(NS,S)) || die $! do appendit("$sport> accept ok\n"); # Log it # Get Specifics on connection from addr ($af,$port,$inetaddr) = unpack($sockaddr,$addr); @inetaddr = unpack('C4',$inetaddr); do appendit("$sport> $af port=$port Inet address @inetaddr[0].@inetaddr[1].@inetaddr[2].@inetaddr[3]\n"); # Main loop select(NS); reset $privledged; # Make sure privledged flag is clear. do motd(); LINE: while () { # Start main loop.. Reading socket chop; [deleted] This is what opens the socket and gets it running.. Everthing happens inside this while loop. Now this is the problem. If someone connected to the server from outside presses control-C it locks up the connection. If tehy just disconnect and come back everything is fine and if they stay connected with it in this state teh server eventually dies. My first try was to catch it with SIG{'INT'} but someone pointed out that this only works if connected to a tty which appears to be true. If I kill the server from my machine with ^C it catches it fine and does what I want.. But when a user presses control-C it still doesn't catch it. IT doesn't matter where they are or what they are doing, if they press control-C it locks. SO, this leads me to believe that it is a socket problem and although there are alot of perl hackers out there, not as many have played with sockets. What I need to know is if there is something special about sockets and connections of this type that would create a problem such as this? Is there some other way that I can open the socket to prevent this with the same results as far as actual operation? I really need to work this out. Hmmmmmmmmmmmmmmmmmmmmmmmmmm.... Just in the last 30 seconds I found out something else related.. I tried a few different control characters on the server to see if anything else would kill it. ^C ^\ and ^O all locked up the connection. On a hunch I toggled the autoflush on sendINT of telnet and now none of those three control characters will do it.. This is frustrating because now I can't track it down to anything in particular but the combination of an interupt and flush seem to kill it. Any ideas as to what might be wrong? ian -=Runaway Daemon=- (UNIXOPS University of Colorado at Boulder)