From 51fcae2d8b94234a25004645c502985414ff360f Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Tue, 29 May 2012 10:46:19 -0700 Subject: [PATCH] io.sockets: adding "broadcast port", ideally would just be +broadcast+ or something, but this works. --- basis/io/sockets/sockets.factor | 5 +++++ basis/io/sockets/unix/unix.factor | 3 +++ basis/io/sockets/windows/windows.factor | 6 ++++++ 3 files changed, 14 insertions(+) diff --git a/basis/io/sockets/sockets.factor b/basis/io/sockets/sockets.factor index 093989e390..9338068438 100644 --- a/basis/io/sockets/sockets.factor +++ b/basis/io/sockets/sockets.factor @@ -281,6 +281,8 @@ TUPLE: raw-port < port addr ; HOOK: (raw) io-backend ( addr -- raw ) +HOOK: (broadcast) io-backend ( datagram -- datagram ) + HOOK: (receive-unsafe) io-backend ( n buf datagram -- size addrspec ) ERROR: invalid-port object ; @@ -363,6 +365,9 @@ SYMBOL: remote-address >>addr ] with-destructors ; +: ( datagram -- datagram ) + (broadcast) ; + : receive-unsafe ( n buf datagram -- count addrspec ) check-receive [ (receive-unsafe) ] [ addr>> ] bi parse-sockaddr ; inline diff --git a/basis/io/sockets/unix/unix.factor b/basis/io/sockets/unix/unix.factor index 4fcb90b9c7..57207ff67a 100644 --- a/basis/io/sockets/unix/unix.factor +++ b/basis/io/sockets/unix/unix.factor @@ -125,6 +125,9 @@ M: unix (datagram) M: unix (raw) [ SOCK_RAW server-socket-fd ] with-destructors ; +M: unix (broadcast) + dup handle>> SOL_SOCKET SO_BROADCAST set-socket-option ; + :: do-receive ( n buf port -- count sockaddr ) port addr>> empty-sockaddr/size :> ( sockaddr len ) port handle>> handle-fd ! s diff --git a/basis/io/sockets/windows/windows.factor b/basis/io/sockets/windows/windows.factor index 39d4310bb2..579dc85abb 100755 --- a/basis/io/sockets/windows/windows.factor +++ b/basis/io/sockets/windows/windows.factor @@ -8,6 +8,9 @@ windows.winsock locals ; FROM: namespaces => get ; IN: io.sockets.windows +: set-socket-option ( handle level opt -- ) + 1 int dup byte-length setsockopt socket-error ; + M: windows addrinfo-error ( n -- ) winsock-return-check ; @@ -86,6 +89,9 @@ M: windows (datagram) ( addrspec -- handle ) M: windows (raw) ( addrspec -- handle ) [ SOCK_RAW server-socket ] with-destructors ; +M: windows (broadcast) ( datagram -- datagram ) + dup handle>> SOL_SOCKET SO_BROADCAST set-socket-option ; + : malloc-int ( n -- alien ) int malloc-byte-array ; inline