[Jahshaka-cvs] jah/jahtools/jbatch handlers.py,1.3,1.4
Status: Beta
Brought to you by:
jahshaka
From: Charles Y. <lil...@us...> - 2007-03-19 02:20:23
|
Update of /cvsroot/jahshaka/jah/jahtools/jbatch In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv972 Modified Files: handlers.py Log Message: + Correction to handlers (close must return an int) Index: handlers.py =================================================================== RCS file: /cvsroot/jahshaka/jah/jahtools/jbatch/handlers.py,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- handlers.py 15 Mar 2007 08:55:57 -0000 1.3 +++ handlers.py 17 Mar 2007 09:41:03 -0000 1.4 @@ -29,7 +29,11 @@ return -1 def close( self ): - self.stream.close( ) + if self.stream is not None: + self.stream.close( ) + self.stream = None + return 0 + return -1 def is_stream( self ): return True @@ -75,6 +79,7 @@ self.dump.close( ) if self.stream is not None: self.stream.close( ) + return 0 def is_stream( self ): return True @@ -133,10 +138,16 @@ # TCP Reader/Writer # -# NB: It assumes that the url to open starts with oml:tcp[:server[:port]]:.ext +# It assumes that the url to open starts with oml:tcp[:server[:port]]:.ext # where server defaults to '' or localhost (depending on write or read) -# port defaults to 51630 -# and extension must be mpg, dv, ts or whatever is being generated... +# port defaults to 51630 +# extension must be mpg, dv, ts or whatever is being generated +# +# It shouldn't matter whether reader or writer are opened first - the first +# one in will bind the port and wait indefinitely for a connection (hence, it +# behaves precisely like a fifo). +# +# Caveat: Does this introduce a race condition? Is there a cleaner solution? class tcp_handler( openmedialib.stream_handler_delegate ): def __init__( self ): @@ -169,22 +180,19 @@ parse_error = True if not parse_error: - if flags == 0: - if server == '': - server = "localhost" + if flags == 0 and server == '': + server = "localhost" + self.socket = socket.socket( socket.AF_INET, socket.SOCK_STREAM ) + self.socket.setsockopt( socket.SOL_SOCKET, socket.SO_REUSEADDR, 1 ) + try: + self.socket.bind( ( server, port ) ) + self.socket.listen( 5 ) + self.stream, address = self.socket.accept( ) + except socket.error, e: self.stream = socket.socket( socket.AF_INET, socket.SOCK_STREAM ) try: self.stream.connect( ( server, port ) ) - except Exception: - self.stream = None - elif flags == 1: - self.socket = socket.socket( socket.AF_INET, socket.SOCK_STREAM ) - self.socket.setsockopt( socket.SOL_SOCKET, socket.SO_REUSEADDR, 1 ) - try: - self.socket.bind( ( server, port ) ) - self.socket.listen( 5 ) - self.stream, address = self.socket.accept( ) - except Exception, e: + except socket.error: self.stream = None return self.stream is not None |