Skip to content
Browse files

io.sockets: adding "broadcast port", ideally would just be +broadcast…

…+ or something, but this works.
  • Loading branch information...
1 parent e722324 commit 95e647fc1e302511147844a9d0ea48f6617719a4 @mrjbq7 mrjbq7 committed May 29, 2012
Showing with 14 additions and 0 deletions.
  1. +5 −0 basis/io/sockets/sockets.factor
  2. +3 −0 basis/io/sockets/unix/unix.factor
  3. +6 −0 basis/io/sockets/windows/windows.factor
View
5 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 ;
+: <broadcast> ( datagram -- datagram )
+ <datagram> (broadcast) ;
+
: receive-unsafe ( n buf datagram -- count addrspec )
check-receive
[ (receive-unsafe) ] [ addr>> ] bi parse-sockaddr ; inline
View
3 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
View
6 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 <ref> 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 <ref> malloc-byte-array ; inline

0 comments on commit 95e647f

Please sign in to comment.
Something went wrong with that request. Please try again.