]> gitweb.factorcode.org Git - factor.git/commitdiff
io.sockets: receive directly into byte array
authorJoe Groff <arcata@gmail.com>
Mon, 17 Oct 2011 05:57:32 +0000 (22:57 -0700)
committerJoe Groff <arcata@gmail.com>
Tue, 18 Oct 2011 04:23:11 +0000 (21:23 -0700)
basis/io/sockets/sockets.factor

index 0828d11b23c8c59139c8d51c77944b0be5bd0f24..ab76433f4979eb5fc40667e2e9556b717b242b9d 100644 (file)
@@ -8,7 +8,8 @@ grouping init io.backend io.binary io.encodings
 io.encodings.ascii io.encodings.binary io.pathnames io.ports
 io.streams.duplex kernel libc locals math math.parser memoize
 namespaces parser present sequences splitting strings summary
-system unix.ffi values vocabs.loader vocabs.parser ;
+system unix.ffi values vocabs.loader vocabs.parser
+sequences.private ;
 IN: io.sockets
 
 << {
@@ -373,23 +374,17 @@ SYMBOL: remote-address
     [ (receive) ] [ addr>> ] bi parse-sockaddr ; inline
 
 CONSTANT: datagram-size 65536
-STRUCT: datagram-buf { buf uchar[datagram-size] } ;
 
 :: receive ( datagram -- packet addrspec )
-    { datagram-buf } [| buf |
-        datagram-size buf datagram
-        receive-unsafe :> ( count addrspec )
-        count [ f f ] [
-            buf swap memory>byte-array addrspec
-        ] if-zero
-    ] with-scoped-allocation ; inline
+    datagram-size (byte-array) :> buf
+    datagram-size buf datagram
+    receive-unsafe :> ( count addrspec )
+    count buf resize addrspec ; inline
 
 :: receive-into ( buf datagram -- buf-slice addrspec )
     buf length :> n
     n buf datagram receive-unsafe :> ( count addrspec )
-    count [ f f ] [ drop
-        buf count head-slice addrspec
-    ] if-zero ; inline
+    buf count head-slice addrspec ; inline
 
 : send ( packet addrspec datagram -- )
     check-send (send) ; inline