Networking Forums

Networking Forums > Computer Networking > Linux Networking > Closing socket file descriptors

Reply
Thread Tools Display Modes

Closing socket file descriptors

 
 
Yang
Guest
Posts: n/a

 
      05-20-2007, 04:26 AM
Hi, I'm experiencing a problem when trying to close the file descriptor
for a socket, creating another socket, and then closing the file
descriptor for that second socket. I can't tell if my issue is about
Python or POSIX.

In the following, the first time through, everything works. On the
second connection, though, the same file descriptor as the first
connection may be re-used, but for some reason, trying to do
os.read/close on that file descriptor will cause an error.

Thanks in advance for any help on why this problem is occurring and/or
how to resolve it (preferrably, I can continue to use file descriptors
instead of resorting to socket.recv/socket.close).

def handle( s ):
print id(s), s
print os.read( s.fileno(), 4096 ) # s.recv(4096)
os.close( s.fileno() ) # s.close()
svr = socket.socket()
svr.bind( ( 'localhost', 8003 ) )
svr.listen( 1 )
while True:
print 'accepting'
s,_ = svr.accept()
handle( s )

# Traceback (most recent call last):
# File "./normal_server_close_error.py", line 25, in <module>
# handle( s )
# File "./normal_server_close_error.py", line 13, in handle
# print os.read( s.fileno(), 4096 ) # s.recv(4096)
# OSError: [Errno 9] Bad file descriptor
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
atomicity / thread-safety: PF_PACKET socket and tap file descriptor Max Schmied Linux Networking 0 02-28-2007 10:31 AM
closing a website JIP Broadband 9 12-14-2005 10:47 PM
Closing an account with NTL Mark Carver Broadband 6 03-06-2005 01:49 AM
Closing ports Antonio Grasso Windows Networking 1 11-24-2003 12:15 PM
use IPv6 socket to get file from Apache lgl Linux Networking 0 11-19-2003 08:34 AM



1 2 3 4 5 6 7 8 9 10 11