Beispiel #1
0
    def __init__(self, _socket):
        """@type socket: native network socket or L{Socket}
        Whether socket is connected will be detected automatically by means
        of a zero-length write"""
        FileDescriptorChannel.__init__(self)
        if isinstance(_socket, Socket):
            self.socket = _socket.socket
        else:
            self.socket = _socket
        self.active = True
        self.blocking = True
        self.timeout = None
        self.socket.settimeout(None)

        # Detect whether socket is connected
        try:
            self.socket.send('')
        except socket.error as e:
            if e.errno in (10057, 11, 32):  
                # Resource temporarily unavailable or Broken pipe
                self.connected = False
            else:
                self.connected = True
        else:
            self.connected = True
Beispiel #2
0
 def __init__(self, socket):
     FileDescriptorChannel.__init__(self)
     self.socket = socket
     self.blocking = True
     self.active = True
     self.socket.settimeout(None)