Re^2: Handling sockets in a server
by skerr1 (Sexton) on Oct 21, 2005 at 12:58 UTC
|
Not to deviate too much from the questions in this post, so you can close a filehandle and you are able to check a return value from the close? I'm sorry I haven't seen this done. I do check success/failure on closing pipes and the man page link you included talks about pipes returning a failure if one of the system calls failed. So, I believe my statement is acurate about no failure returned on a file handle.
Hopefully, someone can help with the meat of this post.
Thanks,
| [reply] |
|
|
close FILEHANDLE or die "Could not close FILEHANDLE: $!\n";
to tell you what the errno varaible was set to when FILEHANDLE could not be closed.
--
(*) - This quote stolen with great embarrassment from Groucho Marx.
--
tbone1, YAPS (Yet Another Perl Schlub)
And remember, if he succeeds, so what.
- Chick McGee
| [reply] [d/l] |
|
|
Geez, now you sucked me in. Can you demonstrate a block of code that this works with. I've written several tools that tried to check the return on a close filehandle and never have I seen an error. I would like to see a true failure.
And if someone would like to answer the orginal questions of the post, I would like that too! :)
Thanks!
| [reply] |
|
|
I have seen someone do, instead. But indeed I've always considered it to be overly paranoid. The point being that a close on a regular filehandle may well fail, but we're confident that it will happen rarely enough no to go mad about it...
| [reply] |
Re^2: Handling sockets in a server
by skerr1 (Sexton) on Oct 21, 2005 at 17:25 UTC
|
OK, so it appears you are answering question #2 for closing the socket (not a connection). Can someone tell me when doing the close($sock) what are the possible reasons for failing to close the socket? How about possible reasons for failing to close a socket connection close($new_sock)?
Is shutdown($sock,2) useful? What does it do as it's not communicating with a client?
How about any answers for questions 3 and 4?
Thank you
| [reply] [d/l] [select] |
|
|
close on a socket could fail if the file descriptor has already been reaped [EBADF]. [EINTR] is also possible.
close is different from shutdown because close only cleans up the file descriptor in the current process, but shutdown will terminate the connection for all processes using it.
That is to say, if you fork a child process that has an open socket, closing it within either process will free the file descriptor associated with that socket, within that process, but the other process will be free to continue using it's copy of the file descriptor and the socket.
However, shutdown will terminate the connection for all processes that have a file descriptor associated with it. The file descriptor will remain after shutdown until they are explicitly closed or otherwise GC'd.
Not having a real fork available, I'll leave questions 3 & 4 to others :)
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] |
|
|
Thanks for the information. This was helpful. Can you tell me though what is the difference in return for closing the socket as apposed to the socket connection? What value am I getting out of closing each?
close($new_sock); # Closes connection, I think your statement on return values applies to this close
But what about
close($sock); # What value am I getting out of checking the close of this, the actual socket, not a connection?
Still waiting for 3 and 4 :)
| [reply] [d/l] [select] |
|
|
|
|
|
|
|