Exemplo n.º 1
0
 def __sockConnect( self, hostAddress, sockType, timeout, retries ):
   try:
     osSocket = socket.socket( sockType, socket.SOCK_STREAM )
   except socket.error as e:
     gLogger.warn( "Exception while creating a socket:", str( e ) ) 
     return S_ERROR( "Exception while creating a socket:%s" % str( e ) )
   # osSocket.setblocking( 0 )
   if timeout:
     tsocket = self.getSocketTimeout()
     gLogger.verbose( "Connection timeout set to: ", tsocket )
     osSocket.settimeout( tsocket )  # we try to connect 3 times with 1 second timeout
   try:
     osSocket.connect( hostAddress )
   except socket.error , e:
     if e.args[0] == "timed out":
       osSocket.close()
       if retries:
         return self.__sockConnect( hostAddress, sockType, timeout, retries - 1 )
       else:
         return S_ERROR( "Can't connect: %s" % str( e ) )
     if e.args[0] not in ( 114, 115 ):
       return S_ERROR( "Can't connect: %s" % str( e ) )
     #Connect in progress
     oL = select.select( [], [ osSocket ], [], timeout )[1]
     if len( oL ) == 0:
       osSocket.close()
       return S_ERROR( "Connection timeout" )
     errno = osSocket.getsockopt( socket.SOL_SOCKET, socket.SO_ERROR )
     if errno != 0:
       return S_ERROR( "Can't connect: %s" % str( ( errno, os.strerror( errno ) ) ) )
Exemplo n.º 2
0
 def __sockConnect(self, hostAddress, sockType, timeout, retries):
     try:
         osSocket = socket.socket(sockType, socket.SOCK_STREAM)
     except socket.error as e:
         gLogger.warn("Exception while creating a socket:", str(e))
         return S_ERROR("Exception while creating a socket:%s" % str(e))
     # osSocket.setblocking( 0 )
     if timeout:
         tsocket = self.getSocketTimeout()
         gLogger.verbose("Connection timeout set to: ", tsocket)
         osSocket.settimeout(
             tsocket)  # we try to connect 3 times with 1 second timeout
     try:
         osSocket.connect(hostAddress)
     except socket.error, e:
         if e.args[0] == "timed out":
             osSocket.close()
             if retries:
                 return self.__sockConnect(hostAddress, sockType, timeout,
                                           retries - 1)
             else:
                 return S_ERROR("Can't connect: %s" % str(e))
         if e.args[0] not in (114, 115):
             return S_ERROR("Can't connect: %s" % str(e))
         #Connect in progress
         oL = select.select([], [osSocket], [], timeout)[1]
         if len(oL) == 0:
             osSocket.close()
             return S_ERROR("Connection timeout")
         errno = osSocket.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR)
         if errno != 0:
             return S_ERROR("Can't connect: %s" % str(
                 (errno, os.strerror(errno))))
Exemplo n.º 3
0
 def dumpLocalCFGToFile(self, fileName):
     try:
         with open(fileName, "w") as fd:
             fd.write(str(self.localCFG))
         gLogger.verbose("Configuration file dumped", "'%s'" % fileName)
     except IOError:
         gLogger.error("Can't dump cfg file", "'%s'" % fileName)
         return S_ERROR("Can't dump cfg file '%s'" % fileName)
     return S_OK()
Exemplo n.º 4
0
 def dumpLocalCFGToFile( self, fileName ):
   try:
     with open( fileName, "w" ) as fd:
       fd.write( str( self.localCFG ) )
     gLogger.verbose( "Configuration file dumped", "'%s'" % fileName )
   except IOError:
     gLogger.error( "Can't dump cfg file", "'%s'" % fileName )
     return S_ERROR( "Can't dump cfg file '%s'" % fileName )
   return S_OK()