def __init__(self, family=AF_INET, type=SOCK_STREAM, proto=0): """Create a new socket.""" fd = _c.socket(family, type, proto) if _c.invalid_socket(fd): raise self.error_handler() # PLAT RISCOS self.fd = fd self.family = family self.type = type self.proto = proto self.timeout = defaults.timeout
def accept(self, SocketClass=None): """Wait for an incoming connection. Return (new socket object, client address).""" if SocketClass is None: SocketClass = RSocket if self._select(False) == 1: raise SocketTimeout address, addr_p, addrlen_p = self._addrbuf() try: newfd = _c.socketaccept(self.fd, addr_p, addrlen_p) addrlen = addrlen_p[0] finally: lltype.free(addrlen_p, flavor='raw') address.unlock() if _c.invalid_socket(newfd): raise self.error_handler() address.addrlen = rffi.cast(lltype.Signed, addrlen) sock = make_socket(newfd, self.family, self.type, self.proto, SocketClass) return (sock, address)
def fileno(self): fd = self.fd if _c.invalid_socket(fd): raise RSocketError("socket already closed") return fd