Пример #1
0
 def recvfrom(self, buffersize, flags=0):
     """Like recv(buffersize, flags) but also return the sender's
     address."""
     read_bytes = -1
     timeout = self._select(False)
     if timeout == 1:
         raise SocketTimeout
     elif timeout == 0:
         raw_buf, gc_buf = rffi.alloc_buffer(buffersize)
         try:
             address, addr_p, addrlen_p = self._addrbuf()
             try:
                 read_bytes = _c.recvfrom(self.fd, raw_buf, buffersize, flags,
                                          addr_p, addrlen_p)
                 addrlen = rffi.cast(lltype.Signed, addrlen_p[0])
             finally:
                 lltype.free(addrlen_p, flavor='raw')
                 address.unlock()
             if read_bytes >= 0:
                 if addrlen:
                     address.addrlen = addrlen
                 else:
                     address = None
                 data = rffi.str_from_buffer(raw_buf, gc_buf, buffersize, read_bytes)
                 return (data, address)
         finally:
             rffi.keep_buffer_alive_until_here(raw_buf, gc_buf)
     raise self.error_handler()
Пример #2
0
 def recvfrom(self, buffersize, flags=0):
     """Like recv(buffersize, flags) but also return the sender's
     address."""
     read_bytes = -1
     timeout = self._select(False)
     if timeout == 1:
         raise SocketTimeout
     elif timeout == 0:
         buf = mallocbuf(buffersize)
         try:
             address, addr_p, addrlen_p = self._addrbuf()
             try:
                 read_bytes = _c.recvfrom(self.fd, buf, buffersize, flags,
                                          addr_p, addrlen_p)
                 addrlen = rffi.cast(lltype.Signed, addrlen_p[0])
             finally:
                 lltype.free(addrlen_p, flavor='raw')
                 address.unlock()
             if read_bytes >= 0:
                 if addrlen:
                     address.addrlen = addrlen
                 else:
                     address = None
                 data = ''.join([buf[i] for i in range(read_bytes)])
                 return (data, address)
         finally:
             lltype.free(buf, flavor='raw')
     raise self.error_handler()