From 5d0ff43613e3f1d14f2db3727fb4b80547260c87 Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Sun, 16 Oct 2011 22:57:32 -0700 Subject: [PATCH] io.sockets: receive directly into byte array --- basis/io/sockets/sockets.factor | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/basis/io/sockets/sockets.factor b/basis/io/sockets/sockets.factor index 0828d11b23..ab76433f49 100644 --- a/basis/io/sockets/sockets.factor +++ b/basis/io/sockets/sockets.factor @@ -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