qmsk/net/socket/socket.pyx
changeset 15 8e7037cc05c7
parent 14 c44754cc1ffe
child 16 24ce1035b338
equal deleted inserted replaced
14:c44754cc1ffe 15:8e7037cc05c7
   151         if sock_fd < 0 :
   151         if sock_fd < 0 :
   152             raise_errno('accept')
   152             raise_errno('accept')
   153         
   153         
   154         try :
   154         try :
   155             # prep the new socket
   155             # prep the new socket
   156             sock_obj = socket(sock_fd)
   156             sock_obj = socket(fd=sock_fd)
   157 
   157 
   158         except :
   158         except :
   159             # XXX: don't leak the socket fd? How does socket.__init__ handle this?
   159             # XXX: don't leak the socket fd? How does socket.__init__ handle this?
   160             platform.close(sock_fd)
   160             platform.close(sock_fd)
   161 
   161 
   348         # recv()
   348         # recv()
   349         cdef libc.ssize_t ret = platform.recv(self.fd, buf, len, flags)
   349         cdef libc.ssize_t ret = platform.recv(self.fd, buf, len, flags)
   350 
   350 
   351         if ret < 0 :
   351         if ret < 0 :
   352             raise_errno('recv')
   352             raise_errno('recv')
   353         
   353 
   354         # XXX: figure out how to call _PyString_Resize
   354         # truncate to correct length
   355         return str[:ret]
   355         # XXX: refcounts?
       
   356         cdef py.PyObject *str_obj = <py.PyObject *> str
       
   357 
       
   358         py._PyString_Resize(&str_obj, ret)
       
   359         
       
   360         return <object> str_obj
   356     
   361     
   357     def recvfrom (self, size_t len, int flags = 0) :
   362     def recvfrom (self, size_t len, int flags = 0) :
   358         """
   363         """
   359             Recieve a message, reading at most `len` bytes, also returning the source address.
   364             Recieve a message, reading at most `len` bytes, also returning the source address.
   360 
   365