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

node:dgram compatibility improvements #16446

Draft
wants to merge 126 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
126 commits
Select commit Hold shift + click to select a range
98d2a9e
Add dns.setServers
heimskr Dec 13, 2024
8052a0e
Special case for falsey hostnames in dns.lookup
heimskr Dec 13, 2024
5587ac0
Add an argument to ERR_INVALID_IP_ADDRESS
heimskr Dec 13, 2024
d3b13e3
Expose AI_ALL, AI_ADDRCONFIG and AI_V4MAPPED from netdb.h under dns
heimskr Dec 13, 2024
69a5b10
Better DNS lookup
heimskr Dec 16, 2024
9019d7a
Better DNS error objects
heimskr Dec 16, 2024
7bbfdae
Fix some dgram tests
heimskr Dec 16, 2024
9a15f30
Initial work on dns.Resolver isolation
heimskr Dec 17, 2024
5ab64c0
Isolated resolution
heimskr Dec 17, 2024
a5805bc
Implement resolveAny via horrible callback hell
heimskr Dec 17, 2024
f5cc373
CAA record support
heimskr Dec 18, 2024
c729dbb
Glorious promises
heimskr Dec 18, 2024
8bafda4
Remove a comment that's not quite true anymore
heimskr Dec 18, 2024
130aa1b
Simplify some Zig
heimskr Dec 18, 2024
a62e2dc
Some dns.ts fixes
heimskr Dec 18, 2024
56b5141
Simplify some Zig again
heimskr Dec 18, 2024
b2a76cc
Isolate promisified Resolver objects
heimskr Dec 18, 2024
c7c22c4
No more NAPTR in resolveAny
heimskr Dec 18, 2024
e8e19c7
There isn't actually a _socket parameter to dgram sockets' error hand…
heimskr Dec 18, 2024
f4e30f9
Add ENOSERVER
heimskr Dec 18, 2024
01e9cbf
Don't do regular lookup for A/AAAA
heimskr Dec 18, 2024
e2d9f59
Merge branch 'main' of github.com:oven-sh/bun into kai/dns-test-fixes
heimskr Dec 18, 2024
35a0c6d
Fix A record resolution
heimskr Dec 19, 2024
ec09c1f
Add test-dns.js
heimskr Dec 19, 2024
e2160db
Add test-dns-get-server.js
heimskr Dec 19, 2024
3aa930e
Customizable timeout and tries options for DNS resolvers
heimskr Dec 19, 2024
89499ad
Fix Windows compilation probably
heimskr Dec 19, 2024
9df2f83
Include ws2def.h instead of netdb.h on Windows
heimskr Dec 19, 2024
ae79ce2
Add+fix test-dns-lookup.js
heimskr Dec 19, 2024
eff93bd
Don't overwrite "name" properties of warning objects
heimskr Dec 19, 2024
a8d1082
Honor `type` and `code` parameters of process.emitWarning
heimskr Dec 20, 2024
c9438ff
Properly emit invalid hostname warnings
heimskr Dec 20, 2024
0e6bdaf
Add test-dns-lookupService.js
heimskr Dec 20, 2024
a415b60
Implement Resolver.cancel()
heimskr Dec 20, 2024
9047047
Add test-dns-channel-cancel-promise.js
heimskr Dec 20, 2024
922050c
Per-resolver reversing
heimskr Dec 20, 2024
166a55a
Initial work on DNS timeout support
heimskr Dec 20, 2024
8bf4542
Proper refcounting for DNSResolvers
heimskr Dec 21, 2024
606b05f
Fix test-dns.js
heimskr Dec 21, 2024
ff7f4bb
Better ref()ing
heimskr Dec 23, 2024
8672289
Add test-dns-channel-timeout.js
heimskr Dec 23, 2024
cbc971c
Add support for default DNS lookup result order
heimskr Dec 23, 2024
ba1322f
Obey DNS result order
heimskr Dec 23, 2024
2e17364
Implement --dns-result-order
heimskr Dec 24, 2024
2792588
Update test-dns-default-order-ipv{4,6}.js
heimskr Dec 24, 2024
f17eb8d
Add test-dns-lookup-promises-options-deprecated.js
heimskr Dec 24, 2024
5429471
Fix test-dns-lookup.js
heimskr Dec 24, 2024
c1fc9cf
Add test-dns-lookupService-promises.js
heimskr Dec 24, 2024
48dfa29
Add test-dns-multi-channel.js
heimskr Dec 24, 2024
a7b4f64
Add error codes to dns.promises
heimskr Dec 26, 2024
34eceb4
Add test-dns-resolve-promises.js
heimskr Dec 26, 2024
25461e5
Make rrtype default to A if unspecified
heimskr Dec 26, 2024
232fd73
Use SystemError in c_ares.zig
heimskr Dec 26, 2024
1a82209
Reimplement resolveAny with an actual ANY query
heimskr Dec 27, 2024
a6862b1
Validate hostname type
heimskr Dec 27, 2024
9733f0e
Add test-dns-set-default-order.js
heimskr Dec 27, 2024
cae9d2d
Implement dns.Resolver.setLocalAddress
heimskr Dec 27, 2024
9448f18
Fix some memory leaks
heimskr Dec 27, 2024
fee3983
Don't allow setting DNS servers while any queries are active
heimskr Dec 27, 2024
f542dd1
Add test-dns-setserver-when-querying.js
heimskr Dec 27, 2024
cccad8f
Add test-dns-setservers-type-check.js
heimskr Dec 27, 2024
e89adec
Fix test-dns.js
heimskr Dec 27, 2024
98e1733
Didn't mean to add those yet, whoops
heimskr Dec 27, 2024
6e4fbea
Set SystemError name property to "DNSException"
heimskr Dec 27, 2024
f4e077d
Get test-dns.js and test-dns-lookupService.js passing simultaneously
heimskr Dec 27, 2024
e7db0c3
dgram: mark bind state as unbound if Bun.udpSocket throws
heimskr Dec 27, 2024
a69f91c
Merge branch 'kai/dns-test-fixes' into kai/dgram-test-fixes
heimskr Dec 27, 2024
012886a
Initial work on test-dgram-bind-shared-ports.js
heimskr Dec 30, 2024
178e809
test-dgram-bind-shared-ports.js
heimskr Dec 31, 2024
5182825
test-dgram-bind-socket-close-before-lookup.js
heimskr Dec 31, 2024
e7f5c2c
test-dgram-close-during-bind.js
heimskr Dec 31, 2024
08e8565
test-dgram-close.js
heimskr Dec 31, 2024
575741a
test-dgram-connect.js
heimskr Dec 31, 2024
99c8c3d
test-dgram-custom-lookup.js
heimskr Dec 31, 2024
cd492f8
test-dgram-error-message-address.js
heimskr Dec 31, 2024
f03ec3d
Fix dgram socket error emission
heimskr Jan 2, 2025
b6bb5a1
Add test-dgram-sendto.js
heimskr Jan 4, 2025
04fed35
Add test-dgram-send-invalid-msg-type.js
heimskr Jan 4, 2025
0254cb2
dgram: options.reusePort
heimskr Jan 6, 2025
0b25392
Add test-dgram-implicit-bind-failure.js
heimskr Jan 6, 2025
019e6c7
Implement ipv6Only in dgram.createSocket
heimskr Jan 6, 2025
7a20256
Add test-dgram-msgsize.js
heimskr Jan 7, 2025
d2ebd94
Add test-dgram-pingpong.js
heimskr Jan 7, 2025
5cc8be1
Merge branch 'main' into kai/dgram-test-fixes
heimskr Jan 15, 2025
baadc66
Some fixes
heimskr Jan 15, 2025
64a1a2c
Add test-dgram-setBroadcast.js
heimskr Jan 16, 2025
7aea8f2
Add test-dgram-reuseport.js
heimskr Jan 16, 2025
7f7591a
Add dgram setTTL
heimskr Jan 16, 2025
4b00fb7
test-dgram-recv-error.js
heimskr Jan 16, 2025
87bcc5f
test-dgram-send-bad-arguments.js
heimskr Jan 16, 2025
4607bc0
Buffer.concat for all arrayview types (fixes test-dgram-send-default-…
heimskr Jan 16, 2025
478867a
test-dgram-send-error.js
heimskr Jan 16, 2025
344b5ba
Fix incorrect reported byte length in UDP send callback
heimskr Jan 16, 2025
109e91f
UDP interface names for IPv6 link-local addrs
heimskr Jan 16, 2025
1c003b2
Multicast TTL
heimskr Jan 16, 2025
efae2d4
Add getters/setters for deprecated internal dgram properties/methods
heimskr Jan 16, 2025
5a0b649
Fix errnoSys usage in udp_socket.zig on Linux
heimskr Jan 16, 2025
a3241d4
dgram setMulticastLoopback
heimskr Jan 16, 2025
a3b4060
Fix setsockopt error reporting on Windows
heimskr Jan 16, 2025
d84697d
Actually fix setsockopt error reporting on Windows?
heimskr Jan 16, 2025
15b5759
Okay this time I actually tested *before* committing
heimskr Jan 16, 2025
1a21ef2
Ignore Tailscale interfaces in test-dgram-udp6-link-local-address.js
heimskr Jan 16, 2025
ba108d6
Fix Windows error codes for UDP bind failure
heimskr Jan 16, 2025
741261f
Fix link-local addresses on Linux
heimskr Jan 16, 2025
b3ab551
We need to also set errno on Windows here
heimskr Jan 16, 2025
c3030e8
Windows error handling, again
heimskr Jan 16, 2025
55a4abf
test-dgram-udp6-link-local-address.js: prefer non-loopback interfaces
heimskr Jan 16, 2025
2c22ee6
Windows error handling, again, again
heimskr Jan 16, 2025
f821a63
Merge branch 'main' into kai/dgram-test-fixes
heimskr Jan 16, 2025
a38b0ba
Fix some tests broken by recent changes
heimskr Jan 17, 2025
d88a600
Windows error handling, again, again, again
heimskr Jan 17, 2025
5372e13
Windows error handling *definitely* fixed
heimskr Jan 17, 2025
90ef237
Address feedback
heimskr Jan 17, 2025
838878a
Address more feedback
heimskr Jan 17, 2025
fe14643
Merge branch 'main' into kai/dgram-test-fixes
heimskr Jan 17, 2025
bf14f16
Add timeout for test-dgram-cluster-close-during-bind.js
heimskr Jan 17, 2025
781a6ad
Coerce port again
heimskr Jan 17, 2025
a672e67
Prefer en0 in test-dgram-udp6-link-local-address.js
heimskr Jan 17, 2025
15e9518
Fix test-dgram-msgsize.js on Windows
heimskr Jan 17, 2025
07d72a1
Success is not an error.
heimskr Jan 17, 2025
95654de
Use SO_REUSEADDR if SO_REUSEPORT is unavailable
heimskr Jan 17, 2025
e6dc8e7
setMulticastInterface
heimskr Jan 17, 2025
cc82997
Address feedback
heimskr Jan 17, 2025
f61269f
Default to scope ID 0
heimskr Jan 17, 2025
2ccc2c2
Merge branch 'main' into kai/dgram-test-fixes
heimskr Jan 17, 2025
67b98c7
dgram: addMembership + dropMembership
heimskr Jan 17, 2025
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
234 changes: 189 additions & 45 deletions packages/bun-usockets/src/bsd.c

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions packages/bun-usockets/src/internal/networking/bsd.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

#include "libusockets.h"

#ifdef _WIN32
#ifdef _WIN32
#ifndef NOMINMAX
#define NOMINMAX
#endif
Expand Down Expand Up @@ -178,9 +178,15 @@ int bsd_udp_packet_buffer_local_ip(struct udp_recvbuf *msgvec, int index, char *
LIBUS_SOCKET_DESCRIPTOR apple_no_sigpipe(LIBUS_SOCKET_DESCRIPTOR fd);
LIBUS_SOCKET_DESCRIPTOR bsd_set_nonblocking(LIBUS_SOCKET_DESCRIPTOR fd);
void bsd_socket_nodelay(LIBUS_SOCKET_DESCRIPTOR fd, int enabled);
int bsd_socket_broadcast(LIBUS_SOCKET_DESCRIPTOR fd, int enabled);
int bsd_socket_ttl_unicast(LIBUS_SOCKET_DESCRIPTOR fd, int ttl);
int bsd_socket_ttl_multicast(LIBUS_SOCKET_DESCRIPTOR fd, int ttl);
int bsd_socket_multicast_loopback(LIBUS_SOCKET_DESCRIPTOR fd, int enabled);
int bsd_socket_multicast_interface(LIBUS_SOCKET_DESCRIPTOR fd, const struct sockaddr_storage *addr);
int bsd_socket_set_membership(LIBUS_SOCKET_DESCRIPTOR fd, const struct sockaddr_storage *addr, const struct sockaddr_storage *iface, int drop);
int bsd_socket_keepalive(LIBUS_SOCKET_DESCRIPTOR fd, int on, unsigned int delay);
void bsd_socket_flush(LIBUS_SOCKET_DESCRIPTOR fd);
LIBUS_SOCKET_DESCRIPTOR bsd_create_socket(int domain, int type, int protocol);
LIBUS_SOCKET_DESCRIPTOR bsd_create_socket(int domain, int type, int protocol, int *err);

void bsd_close_socket(LIBUS_SOCKET_DESCRIPTOR fd);
void bsd_shutdown_socket(LIBUS_SOCKET_DESCRIPTOR fd);
Expand Down Expand Up @@ -211,7 +217,7 @@ LIBUS_SOCKET_DESCRIPTOR bsd_create_listen_socket(const char *host, int port, int
LIBUS_SOCKET_DESCRIPTOR bsd_create_listen_socket_unix(const char *path, size_t pathlen, int options, int* error);

/* Creates an UDP socket bound to the hostname and port */
LIBUS_SOCKET_DESCRIPTOR bsd_create_udp_socket(const char *host, int port);
LIBUS_SOCKET_DESCRIPTOR bsd_create_udp_socket(const char *host, int port, int options, int *err);
int bsd_connect_udp_socket(LIBUS_SOCKET_DESCRIPTOR fd, const char *host, int port);
int bsd_disconnect_udp_socket(LIBUS_SOCKET_DESCRIPTOR fd);

Expand Down
18 changes: 10 additions & 8 deletions packages/bun-usockets/src/libusockets.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
#endif

#ifdef BUN_DEBUG
#define nonnull_fn_decl
#else
#define nonnull_fn_decl
#else
#ifndef nonnull_fn_decl
#define nonnull_fn_decl __attribute__((nonnull))
#endif
Expand Down Expand Up @@ -98,7 +98,7 @@ enum {
LIBUS_SOCKET_ALLOW_HALF_OPEN = 2,
/* Setting reusePort allows multiple sockets on the same host to bind to the same port. Incoming connections are distributed by the operating system to listening sockets. This option is available only on some platforms, such as Linux 3.9+, DragonFlyBSD 3.6+, FreeBSD 12.0+, Solaris 11.4, and AIX 7.2.5+*/
LIBUS_LISTEN_REUSE_PORT = 4,
/* etting ipv6Only will disable dual-stack support, i.e., binding to host :: won't make 0.0.0.0 be bound.*/
/* Setting ipv6Only will disable dual-stack support, i.e., binding to host :: won't make 0.0.0.0 be bound.*/
LIBUS_SOCKET_IPV6_ONLY = 8,
};

Expand Down Expand Up @@ -153,10 +153,12 @@ struct us_udp_packet_buffer_t *us_create_udp_packet_buffer();

//struct us_udp_socket_t *us_create_udp_socket(us_loop_r loop, void (*data_cb)(struct us_udp_socket_t *, struct us_udp_packet_buffer_t *, int), void (*drain_cb)(struct us_udp_socket_t *), char *host, unsigned short port);

struct us_udp_socket_t *us_create_udp_socket(us_loop_r loop, void (*data_cb)(struct us_udp_socket_t *, void *, int), void (*drain_cb)(struct us_udp_socket_t *), void (*close_cb)(struct us_udp_socket_t *), const char *host, unsigned short port, void *user);
struct us_udp_socket_t *us_create_udp_socket(us_loop_r loop, void (*data_cb)(struct us_udp_socket_t *, void *, int), void (*drain_cb)(struct us_udp_socket_t *), void (*close_cb)(struct us_udp_socket_t *), const char *host, unsigned short port, int flags, int *err, void *user);

void us_udp_socket_close(struct us_udp_socket_t *s);

int us_udp_socket_set_broadcast(struct us_udp_socket_t *s, int enabled);

/* This one is ugly, should be ext! not user */
void *us_udp_socket_user(struct us_udp_socket_t *s);

Expand Down Expand Up @@ -223,11 +225,11 @@ struct us_bun_socket_context_options_t {
const char *ssl_ciphers;
int ssl_prefer_low_memory_usage; /* Todo: rename to prefer_low_memory_usage and apply for TCP as well */
const char **key;
unsigned int key_count;
unsigned int key_count;
const char **cert;
unsigned int cert_count;
unsigned int cert_count;
const char **ca;
unsigned int ca_count;
unsigned int ca_count;
unsigned int secure_options;
int reject_unauthorized;
int request_cert;
Expand Down Expand Up @@ -310,7 +312,7 @@ struct us_listen_socket_t *us_socket_context_listen_unix(int ssl, us_socket_cont
void us_listen_socket_close(int ssl, struct us_listen_socket_t *ls) nonnull_fn_decl;

/*
Returns one of
Returns one of
- struct us_socket_t * - indicated by the value at on_connecting being set to 1
This is the fast path where the DNS result is available immediately and only a single remote
address is available
Expand Down
24 changes: 12 additions & 12 deletions packages/bun-usockets/src/quic.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void on_udp_socket_writable(struct us_udp_socket_t *s) {

// we need two differetn handlers to know to put it in client or servcer context
void on_udp_socket_data_client(struct us_udp_socket_t *s, struct us_udp_packet_buffer_t *buf, int packets) {

int fd = us_poll_fd((struct us_poll_t *) s);
//printf("Reading on fd: %d\n", fd);

Expand All @@ -113,7 +113,7 @@ void on_udp_socket_data_client(struct us_udp_socket_t *s, struct us_udp_packet_b
// do we have udp socket contexts? or do we just have user data?

us_quic_socket_context_t *context = us_udp_socket_user(s);

/* We just shove it to lsquic */
for (int i = 0; i < packets; i++) {
char *payload = us_udp_packet_buffer_payload(buf, i);
Expand Down Expand Up @@ -155,15 +155,15 @@ void on_udp_socket_data_client(struct us_udp_socket_t *s, struct us_udp_packet_b
int ret = lsquic_engine_packet_in(context->client_engine, payload, length, (struct sockaddr *) &local_addr, peer_addr, (void *) s, 0);
//printf("Engine returned: %d\n", ret);


}

lsquic_engine_process_conns(context->client_engine);

}

void on_udp_socket_data(struct us_udp_socket_t *s, struct us_udp_packet_buffer_t *buf, int packets) {


//printf("UDP socket got data: %p\n", s);

Expand All @@ -175,7 +175,7 @@ void on_udp_socket_data(struct us_udp_socket_t *s, struct us_udp_packet_buffer_t

// process conns now? to accept new connections?
lsquic_engine_process_conns(context->engine);

/* We just shove it to lsquic */
for (int i = 0; i < packets; i++) {
char *payload = us_udp_packet_buffer_payload(buf, i);
Expand Down Expand Up @@ -218,7 +218,7 @@ void on_udp_socket_data(struct us_udp_socket_t *s, struct us_udp_packet_buffer_t
int ret = lsquic_engine_packet_in(context->engine, payload, length, (struct sockaddr *) &local_addr, peer_addr, (void *) s, 0);
//printf("Engine returned: %d\n", ret);


}

lsquic_engine_process_conns(context->engine);
Expand Down Expand Up @@ -653,9 +653,9 @@ struct ssl_ctx_st *get_ssl_ctx(void *peer_ctx, const struct sockaddr *local) {

SSL_CTX_set_min_proto_version(ctx, TLS1_3_VERSION);
SSL_CTX_set_max_proto_version(ctx, TLS1_3_VERSION);

//SSL_CTX_set_default_verify_paths(ctx);

// probably cannot use this when http is in use?
// alpn is needed
SSL_CTX_set_alpn_select_cb(ctx, select_alpn, NULL);
Expand Down Expand Up @@ -950,7 +950,7 @@ us_quic_socket_context_t *us_create_quic_socket_context(struct us_loop_t *loop,
.ea_stream_if_ctx = context,

.ea_get_ssl_ctx = get_ssl_ctx,

// lookup certificate
.ea_lookup_cert = sni_lookup,
.ea_cert_lu_ctx = 0,
Expand Down Expand Up @@ -980,7 +980,7 @@ us_quic_socket_context_t *us_create_quic_socket_context(struct us_loop_t *loop,
.ea_stream_if_ctx = context,

//.ea_get_ssl_ctx = get_ssl_ctx, // for client?

// lookup certificate
//.ea_lookup_cert = sni_lookup, // for client?
//.ea_cert_lu_ctx = 13, // for client?
Expand Down Expand Up @@ -1008,7 +1008,7 @@ us_quic_socket_context_t *us_create_quic_socket_context(struct us_loop_t *loop,

us_quic_listen_socket_t *us_quic_socket_context_listen(us_quic_socket_context_t *context, const char *host, int port, int ext_size) {
/* We literally do create a listen socket */
return (us_quic_listen_socket_t *) us_create_udp_socket(context->loop, /*context->recv_buf*/ NULL, on_udp_socket_data, on_udp_socket_writable, host, port, context);
return (us_quic_listen_socket_t *) us_create_udp_socket(context->loop, /*context->recv_buf*/ NULL, on_udp_socket_data, on_udp_socket_writable, host, port, 0, context);
//return NULL;
}

Expand All @@ -1030,7 +1030,7 @@ us_quic_socket_t *us_quic_socket_context_connect(us_quic_socket_context_t *conte
addr->sin6_family = AF_INET6;

// Create the UDP socket binding to ephemeral port
struct us_udp_socket_t *udp_socket = us_create_udp_socket(context->loop, /*context->recv_buf*/ NULL, on_udp_socket_data_client, on_udp_socket_writable, 0, 0, context);
struct us_udp_socket_t *udp_socket = us_create_udp_socket(context->loop, /*context->recv_buf*/ NULL, on_udp_socket_data_client, on_udp_socket_writable, 0, 0, 0, context);

// Determine what port we got, creating the local sockaddr
int ephemeral = us_udp_socket_bound_port(udp_socket);
Expand Down
46 changes: 35 additions & 11 deletions packages/bun-usockets/src/udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ int us_udp_socket_send(struct us_udp_socket_t *s, void** payloads, size_t* lengt
num -= count;
// TODO nohang flag?
int sent = bsd_sendmmsg(fd, buf, MSG_DONTWAIT);
if (sent < 0) {
if (sent < 0) {
return sent;
}
total_sent += sent;
Expand Down Expand Up @@ -91,9 +91,7 @@ void us_udp_socket_remote_ip(struct us_udp_socket_t *s, char *buf, int *length)
}
}

void *us_udp_socket_user(struct us_udp_socket_t *s) {
struct us_udp_socket_t *udp = (struct us_udp_socket_t *) s;

void *us_udp_socket_user(struct us_udp_socket_t *udp) {
return udp->user;
}

Expand All @@ -108,6 +106,18 @@ void us_udp_socket_close(struct us_udp_socket_t *s) {
s->on_close(s);
}

int us_udp_socket_set_broadcast(struct us_udp_socket_t *s, int enabled) {
return bsd_socket_broadcast(us_poll_fd(&s->p), enabled);
}

int us_udp_socket_set_ttl_unicast(struct us_udp_socket_t *s, int ttl) {
return bsd_socket_ttl_unicast(us_poll_fd(&s->p), ttl);
}

int us_udp_socket_set_ttl_multicast(struct us_udp_socket_t *s, int ttl) {
return bsd_socket_ttl_multicast(us_poll_fd(&s->p), ttl);
}

int us_udp_socket_connect(struct us_udp_socket_t *s, const char* host, unsigned short port) {
return bsd_connect_udp_socket(us_poll_fd((struct us_poll_t *)s), host, port);
}
Expand All @@ -116,17 +126,31 @@ int us_udp_socket_disconnect(struct us_udp_socket_t *s) {
return bsd_disconnect_udp_socket(us_poll_fd((struct us_poll_t *)s));
}

int us_udp_socket_set_multicast_loopback(struct us_udp_socket_t *s, int enabled) {
return bsd_socket_multicast_loopback(us_poll_fd(&s->p), enabled);
}

int us_udp_socket_set_multicast_interface(struct us_udp_socket_t *s, const struct sockaddr_storage *addr) {
return bsd_socket_multicast_interface(us_poll_fd(&s->p), addr);
}

int us_udp_socket_set_membership(struct us_udp_socket_t *s, const struct sockaddr_storage *addr, const struct sockaddr_storage *iface, int drop) {
return bsd_socket_set_membership(us_poll_fd(&s->p), addr, iface, drop);
}

struct us_udp_socket_t *us_create_udp_socket(
struct us_loop_t *loop,
void (*data_cb)(struct us_udp_socket_t *, void *, int),
void (*drain_cb)(struct us_udp_socket_t *),
struct us_loop_t *loop,
void (*data_cb)(struct us_udp_socket_t *, void *, int),
void (*drain_cb)(struct us_udp_socket_t *),
void (*close_cb)(struct us_udp_socket_t *),
const char *host,
unsigned short port,
const char *host,
unsigned short port,
int flags,
int *err,
void *user
) {

LIBUS_SOCKET_DESCRIPTOR fd = bsd_create_udp_socket(host, port);
LIBUS_SOCKET_DESCRIPTOR fd = bsd_create_udp_socket(host, port, flags, err);
if (fd == LIBUS_SOCKET_ERROR) {
return 0;
}
Expand Down Expand Up @@ -157,6 +181,6 @@ struct us_udp_socket_t *us_create_udp_socket(
udp->next = NULL;

us_poll_start((struct us_poll_t *) udp, udp->loop, LIBUS_SOCKET_READABLE | LIBUS_SOCKET_WRITABLE);

return (struct us_udp_socket_t *) udp;
}
Loading
Loading