io.sockets: receive directly into byte array

db4
Joe Groff 2011-10-16 22:57:32 -07:00
parent 20e49c273f
commit 5d0ff43613
1 changed files with 7 additions and 12 deletions

View File

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