Browse Source

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 <[email protected]>
Co-authored-by: Simon Krajewski <[email protected]>
Kristin Rutenkolk 2 years ago
parent
commit
a053b3a1b9
1 changed files with 8 additions and 0 deletions
  1. 8 0
      src/std/socket.c

+ 8 - 0
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 );