fix socket.accept, and add simple PyString_Resize code
authorTero Marttila <terom@fixme.fi>
Sun, 16 Aug 2009 23:45:43 +0300
changeset 15 8e7037cc05c7
parent 14 c44754cc1ffe
child 16 24ce1035b338
fix socket.accept, and add simple PyString_Resize code
qmsk/net/socket/socket.pyx
--- a/qmsk/net/socket/socket.pyx	Sun Aug 16 23:32:00 2009 +0300
+++ b/qmsk/net/socket/socket.pyx	Sun Aug 16 23:45:43 2009 +0300
@@ -153,7 +153,7 @@
         
         try :
             # prep the new socket
-            sock_obj = socket(sock_fd)
+            sock_obj = socket(fd=sock_fd)
 
         except :
             # XXX: don't leak the socket fd? How does socket.__init__ handle this?
@@ -350,9 +350,14 @@
 
         if ret < 0 :
             raise_errno('recv')
+
+        # truncate to correct length
+        # XXX: refcounts?
+        cdef py.PyObject *str_obj = <py.PyObject *> str
+
+        py._PyString_Resize(&str_obj, ret)
         
-        # XXX: figure out how to call _PyString_Resize
-        return str[:ret]
+        return <object> str_obj
     
     def recvfrom (self, size_t len, int flags = 0) :
         """