Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add broadcast ability to udp sockets #432

Merged
merged 3 commits into from
Sep 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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