in reply to Re^2: EOF being read from open socket?
in thread EOF being read from open socket?

What makes you think it's still connected? What is sysread returning? 0? undefined? If undefined, what's in $!?

Replies are listed 'Best First'.
Re^4: EOF being read from open socket?
by Elijah (Hermit) on Aug 23, 2006 at 21:33 UTC
    It returns an integer 0 from the sysread function but loads undef into the buffer that sysread stores the data in. I think it is still open because the app never closes it. Maybe I am missing something but this socket is suppose to remain open so I assumed it was since the only one I close is the client socket.

      You have no else block on the if (sysread($ircsock, $ircdata, 512)) { block, so you don't handle the case where the server closes the connection at all, which results in exactly the loop you're seeing.

      As to why the server would close the socket when one of your clients disconnects, that may be because of the way the client is disconnecting. Most IRC clients will send a QUIT command to the server when they're about to disconnect, and I wouldn't be surprised if this causes the server to actively close the connection.

      Since you don't do any special processing for the QUIT command, I suspect that as soon as one of your clients exits it will cause the server to close the connection to your "proxy". A possible workaround would be to intercept all QUIT commands and just ignore them.

      On an unrelated note, I think your usage of sysread will get you into trouble. After each sysread you appear to expect that the result of a successful read will be a complete line. However there's nothing preventing sysread from returning half a line, or two lines at once.

        LOL.. Where were you when I needed you! :-) The intercept of the QUIT was exactly the problem. Soon after ikegami's last post I went back to the code and noticed I was letting the QUIT from the client get through to the server. I had to join the irc server with a different client directly and watch the proxy user quit when it's client quit which was not suppose to happen. That is when I realized I was never trapping and processing the QUIT from the client.

        As for the else, I suppose I could add a simple "exit(0)" in an else there but I never expect the server socket to close. It is bad practice to not handle it if it does though so thanks for pointing it out.

        wrt sysread, are you talking about the regex that looks for : at the begining of the buffer read? Are you saying that maybe this will fail if sysread reads 1 and 1/2 lines and then the second half of the second line in the next call? I can see your point if that is what you are talking about. Is there another way of reading from a socket that will ensure at least a complete line with each read? Possibly a slurp style read (<$ircsock>)?

      Sorry, without having something I can run myself, I've exhausted my ideas.