Skip to content

Commit

Permalink
add broadcast ability to udp sockets (HaxeFoundation#432)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
3 people authored and RandomityGuy committed Jan 11, 2024
1 parent a45c9f0 commit b36a59e
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/std/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 );
Expand Down

0 comments on commit b36a59e

Please sign in to comment.