diff options
author | 2023-09-14 21:26:37 -0700 | |
---|---|---|
committer | 2023-09-14 21:26:37 -0700 | |
commit | ced69d38180e963da1206f9932db76666cec9f72 (patch) | |
tree | a4c4462ff8747adc7d092891b1c299dfbb0ecc4a /packages/bun-usockets/src | |
parent | b262b0153a2d9667fcb47a970e8027d3b54f8a0a (diff) | |
download | bun-ced69d38180e963da1206f9932db76666cec9f72.tar.gz bun-ced69d38180e963da1206f9932db76666cec9f72.tar.zst bun-ced69d38180e963da1206f9932db76666cec9f72.zip |
async-ify all node:fs functions (#5360)
* async all node:fs functions
* draw the rest of the owl
* LLVM & Clang 16
---------
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'packages/bun-usockets/src')
-rw-r--r-- | packages/bun-usockets/src/context.c | 3 | ||||
-rw-r--r-- | packages/bun-usockets/src/crypto/openssl.c | 2 | ||||
-rw-r--r-- | packages/bun-usockets/src/eventing/epoll_kqueue.c | 4 | ||||
-rw-r--r-- | packages/bun-usockets/src/libusockets.h | 1 | ||||
-rw-r--r-- | packages/bun-usockets/src/socket.c | 53 |
5 files changed, 5 insertions, 58 deletions
diff --git a/packages/bun-usockets/src/context.c b/packages/bun-usockets/src/context.c index a4d243e85..9e0dd5356 100644 --- a/packages/bun-usockets/src/context.c +++ b/packages/bun-usockets/src/context.c @@ -29,6 +29,7 @@ int default_is_low_prio_handler(struct us_socket_t *s) { unsigned short us_socket_context_timestamp(int ssl, struct us_socket_context_t *context) { return context->timestamp; } +int us_internal_raw_root_certs(struct us_cert_string_t** out); int us_raw_root_certs(struct us_cert_string_t**out){ return us_internal_raw_root_certs(out); } @@ -568,7 +569,7 @@ void *us_socket_context_ext(int ssl, struct us_socket_context_t *context) { void us_socket_context_on_handshake(int ssl, struct us_socket_context_t *context, void (*on_handshake)(struct us_socket_context_t *, int success, struct us_bun_verify_error_t verify_error, void* custom_data), void* custom_data) { #ifndef LIBUS_NO_SSL if (ssl) { - us_internal_on_ssl_handshake((struct us_internal_ssl_socket_context_t *) context, on_handshake, custom_data); + us_internal_on_ssl_handshake((struct us_internal_ssl_socket_context_t *) context, (void (*)(struct us_internal_ssl_socket_t *, int success, struct us_bun_verify_error_t verify_error, void* custom_data))on_handshake, custom_data); return; } #endif diff --git a/packages/bun-usockets/src/crypto/openssl.c b/packages/bun-usockets/src/crypto/openssl.c index 0b55ca866..a03bf3520 100644 --- a/packages/bun-usockets/src/crypto/openssl.c +++ b/packages/bun-usockets/src/crypto/openssl.c @@ -45,7 +45,7 @@ void *sni_find(void *sni, const char *hostname); #include "./root_certs.h" #include <stdatomic.h> -static const root_certs_size = sizeof(root_certs) / sizeof(root_certs[0]); +static const size_t root_certs_size = sizeof(root_certs) / sizeof(root_certs[0]); static X509* root_cert_instances[root_certs_size] = {NULL}; static atomic_flag root_cert_instances_lock = ATOMIC_FLAG_INIT; static atomic_bool root_cert_instances_initialized = 0; diff --git a/packages/bun-usockets/src/eventing/epoll_kqueue.c b/packages/bun-usockets/src/eventing/epoll_kqueue.c index 7ab2be826..df694dd04 100644 --- a/packages/bun-usockets/src/eventing/epoll_kqueue.c +++ b/packages/bun-usockets/src/eventing/epoll_kqueue.c @@ -35,8 +35,8 @@ void us_loop_run_bun_tick(struct us_loop_t *loop, int64_t timeoutMs); /* Pointer tags are used to indicate a Bun pointer versus a uSockets pointer */ #define UNSET_BITS_49_UNTIL_64 0x0000FFFFFFFFFFFF #define CLEAR_POINTER_TAG(p) ((void *) ((uintptr_t) (p) & UNSET_BITS_49_UNTIL_64)) -#define LIKELY(cond) __builtin_expect((uint64_t)(void*)cond, 1) -#define UNLIKELY(cond) __builtin_expect((uint64_t)(void*)cond, 0) +#define LIKELY(cond) __builtin_expect((uint64_t)(void*)(cond), 1) +#define UNLIKELY(cond) __builtin_expect((uint64_t)(void*)(cond), 0) #ifdef LIBUS_USE_EPOLL #define GET_READY_POLL(loop, index) (struct us_poll_t *) loop->ready_polls[index].data.ptr diff --git a/packages/bun-usockets/src/libusockets.h b/packages/bun-usockets/src/libusockets.h index 5f4563605..e0a427ce5 100644 --- a/packages/bun-usockets/src/libusockets.h +++ b/packages/bun-usockets/src/libusockets.h @@ -386,7 +386,6 @@ void us_socket_remote_address(int ssl, struct us_socket_t *s, char *buf, int *le /* Bun extras */ struct us_socket_t *us_socket_pair(struct us_socket_context_t *ctx, int socket_ext_size, LIBUS_SOCKET_DESCRIPTOR* fds); struct us_socket_t *us_socket_from_fd(struct us_socket_context_t *ctx, int socket_ext_size, LIBUS_SOCKET_DESCRIPTOR fd); -struct us_socket_t *us_socket_detach(int ssl, struct us_socket_t *s); struct us_socket_t *us_socket_attach(int ssl, LIBUS_SOCKET_DESCRIPTOR client_fd, struct us_socket_context_t *ctx, int flags, int socket_ext_size); struct us_socket_t *us_socket_wrap_with_tls(int ssl, struct us_socket_t *s, struct us_bun_socket_context_options_t options, struct us_socket_events_t events, int socket_ext_size); int us_socket_raw_write(int ssl, struct us_socket_t *s, const char *data, int length, int msg_more); diff --git a/packages/bun-usockets/src/socket.c b/packages/bun-usockets/src/socket.c index 5f5a91acb..ce5203ccb 100644 --- a/packages/bun-usockets/src/socket.c +++ b/packages/bun-usockets/src/socket.c @@ -140,59 +140,6 @@ struct us_socket_t *us_socket_close(int ssl, struct us_socket_t *s, int code, vo return s; } -// This function is the same as us_socket_close but: -// - does not emit on_close event -// - does not close -struct us_socket_t *us_socket_detach(int ssl, struct us_socket_t *s) { - if (!us_socket_is_closed(0, s)) { - if (s->low_prio_state == 1) { - /* Unlink this socket from the low-priority queue */ - if (!s->prev) s->context->loop->data.low_prio_head = s->next; - else s->prev->next = s->next; - - if (s->next) s->next->prev = s->prev; - - s->prev = 0; - s->next = 0; - s->low_prio_state = 0; - } else { - us_internal_socket_context_unlink(s->context, s); - } - us_poll_stop((struct us_poll_t *) s, s->context->loop); - - /* Link this socket to the close-list and let it be deleted after this iteration */ - s->next = s->context->loop->data.closed_head; - s->context->loop->data.closed_head = s; - - /* Any socket with prev = context is marked as closed */ - s->prev = (struct us_socket_t *) s->context; - - return s; - } - return s; -} - -// This function is used for moving a socket between two different event loops -struct us_socket_t *us_socket_attach(int ssl, LIBUS_SOCKET_DESCRIPTOR client_fd, struct us_socket_context_t *ctx, int flags, int socket_ext_size) { - struct us_poll_t *accepted_p = us_create_poll(ctx->loop, 0, sizeof(struct us_socket_t) - sizeof(struct us_poll_t) + socket_ext_size); - us_poll_init(accepted_p, client_fd, POLL_TYPE_SOCKET); - us_poll_start(accepted_p, ctx->loop, flags); - - struct us_socket_t *s = (struct us_socket_t *) accepted_p; - - s->context = ctx; - s->timeout = 0; - s->low_prio_state = 0; - - /* We always use nodelay */ - bsd_socket_nodelay(client_fd, 1); - us_internal_socket_context_link(ctx, s); - - if (ctx->on_open) ctx->on_open(s, 0, 0, 0); - - return s; -} - struct us_socket_t *us_socket_pair(struct us_socket_context_t *ctx, int socket_ext_size, LIBUS_SOCKET_DESCRIPTOR* fds) { #ifdef LIBUS_USE_LIBUV return 0; |