qmsk/net/transport/socket.py
changeset 33 c71de00715d6
parent 28 020c89baaa33
child 37 14db3fe42b6c
equal deleted inserted replaced
32:2168a9ffaef7 33:c71de00715d6
    85             Raises a ServiceBindAddrinfoError if this fails
    85             Raises a ServiceBindAddrinfoError if this fails
    86         """
    86         """
    87 
    87 
    88         try :
    88         try :
    89             # socket()
    89             # socket()
    90             sock = self._socket(ai.family, ai.socktype, ai.protocol)
    90             sock = cls._socket(ai.family, ai.socktype, ai.protocol)
    91 
    91 
    92             # bind()
    92             # bind()
    93             sock.bind(ai.addr)
    93             sock.bind(ai.addr)
    94 
    94 
    95         # XXX: except socket.error as e :
    95         # XXX: except socket.error as e :
   115         """
   115         """
   116         
   116         
   117         errors = []
   117         errors = []
   118         
   118         
   119         # resolve the endpoint and try socket+bind
   119         # resolve the endpoint and try socket+bind
   120         for ai in endpoint.getaddrinfo(family, socktype, protocol, AI_PASSIVE) :
   120         for ai in endpoint.resolve(family, socktype, protocol, AI_PASSIVE) :
   121             try :
   121             try :
   122                 # try to socket+bind this addrinfo
   122                 # try to socket+bind this addrinfo
   123                 sock = cls._bind_addrinfo(ai)
   123                 sock = cls._bind_addrinfo(ai)
   124             
   124             
   125             except SocketBindAddrinfoError, error :
   125             except SocketBindAddrinfoError, error :
   258         """
   258         """
   259         
   259         
   260         errors = []
   260         errors = []
   261         
   261         
   262         # resolve the endpoint and try socket+bind
   262         # resolve the endpoint and try socket+bind
   263         for ai in endpoint.getaddrinfo(family, socktype, protocol) :
   263         for ai in endpoint.resolve(family, socktype, protocol) :
   264             try :
   264             try :
   265                 # try to connect the socket to this addrinfo
   265                 # try to connect the socket to this addrinfo
   266                 cls._connect_sock_addrinfo(sock, ai)
   266                 cls._connect_sock_addrinfo(sock, ai)
   267             
   267             
   268             except SocketConnectAddrinfoError, error :
   268             except SocketConnectAddrinfoError, error :
   279         else :
   279         else :
   280             # no suitable address found :(
   280             # no suitable address found :(
   281             raise SocketConnectEndpointError(endpoint, errors)
   281             raise SocketConnectEndpointError(endpoint, errors)
   282     
   282     
   283     @classmethod
   283     @classmethod
   284     def _connect_endpoint (self, endpoint, family, socktype, protocol = 0) :
   284     def _connect_endpoint (cls, endpoint, family, socktype, protocol = 0) :
   285         """
   285         """
   286             Create a new socket and connect it to the given remote endpoint, using the given parameters to resolve the
   286             Create a new socket and connect it to the given remote endpoint, using the given parameters to resolve the
   287             endpoint.
   287             endpoint.
   288         """
   288         """
   289 
   289 
   290         errors = []
   290         errors = []
   291         
   291         
   292         # resolve the endpoint and try socket+bind
   292         # resolve the endpoint and try socket+bind
   293         for ai in endpoint.getaddrinfo(family, socktype, protocol) :
   293         for ai in endpoint.resolve(family, socktype, protocol) :
   294             try :
   294             try :
   295                 # try to socket+connect this addrinfo
   295                 # try to socket+connect this addrinfo
   296                 sock = cls._connect_addrinfo(ai)
   296                 sock = cls._connect_addrinfo(ai)
   297             
   297             
   298             except SocketConnectAddrinfoError, error :
   298             except SocketConnectAddrinfoError, error :