From b36a59e33763268e3cb2228e7a7c157cafc17e5b Mon Sep 17 00:00:00 2001 From: Kristin Rutenkolk Date: Thu, 21 Sep 2023 19:20:02 +0200 Subject: [PATCH] add broadcast ability to udp sockets (#432) * add broadcast ability to udp sockets * rename variable 'fast' to 'broadcast' * Update socket.c --------- Co-authored-by: Chris Rutenkolk Co-authored-by: Simon Krajewski --- src/std/socket.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/std/socket.c b/src/std/socket.c index 8453163f7..f717dc9ae 100644 --- a/src/std/socket.c +++ b/src/std/socket.c @@ -133,6 +133,13 @@ HL_PRIM hl_socket *hl_socket_new( bool udp ) { } } +HL_PRIM bool hl_socket_set_broadcast( hl_socket *s, bool b ) { + int broadcast = b; + if( !s ) + return false; + return setsockopt(s->sock,SOL_SOCKET,SO_BROADCAST,(char*)&broadcast,sizeof(broadcast)) == 0; +} + HL_PRIM void hl_socket_close( hl_socket *s ) { if( !s ) return; closesocket(s->sock); @@ -478,6 +485,7 @@ HL_PRIM bool hl_socket_select( varray *ra, varray *wa, varray *ea, char *tmp, in #define _SOCK _ABSTRACT(hl_socket) DEFINE_PRIM(_VOID,socket_init,_NO_ARG); DEFINE_PRIM(_SOCK,socket_new,_BOOL); +DEFINE_PRIM(_BOOL,socket_set_broadcast,_SOCK _BOOL); DEFINE_PRIM(_VOID,socket_close,_SOCK); DEFINE_PRIM(_I32,socket_send_char,_SOCK _I32); DEFINE_PRIM(_I32,socket_send,_SOCK _BYTES _I32 _I32 );