mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
Clean up some usockets initializers (#18994)
This commit is contained in:
@@ -404,9 +404,9 @@ struct us_listen_socket_t *us_socket_context_listen_unix(int ssl, struct us_sock
|
||||
ls->s.timeout = 255;
|
||||
ls->s.long_timeout = 255;
|
||||
ls->s.flags.low_prio_state = 0;
|
||||
ls->s.next = 0;
|
||||
ls->s.flags.allow_half_open = (options & LIBUS_SOCKET_ALLOW_HALF_OPEN);
|
||||
ls->s.flags.is_paused = 0;
|
||||
ls->s.next = 0;
|
||||
us_internal_socket_context_link_listen_socket(context, ls);
|
||||
|
||||
ls->socket_ext_size = socket_ext_size;
|
||||
@@ -737,9 +737,10 @@ struct us_socket_t *us_socket_context_connect_unix(int ssl, struct us_socket_con
|
||||
connect_socket->timeout = 255;
|
||||
connect_socket->long_timeout = 255;
|
||||
connect_socket->flags.low_prio_state = 0;
|
||||
connect_socket->connect_state = NULL;
|
||||
connect_socket->flags.allow_half_open = (options & LIBUS_SOCKET_ALLOW_HALF_OPEN);
|
||||
connect_socket->flags.is_paused = 0;
|
||||
connect_socket->connect_state = NULL;
|
||||
connect_socket->connect_next = NULL;
|
||||
us_internal_socket_context_link_socket(context, connect_socket);
|
||||
|
||||
return connect_socket;
|
||||
|
||||
@@ -466,7 +466,6 @@ void us_socket_local_address(int ssl, us_socket_r s, char *nonnull_arg buf, int
|
||||
/* 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_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, us_socket_r 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, us_socket_r s, const char *data, int length, int msg_more);
|
||||
struct us_socket_t* us_socket_open(int ssl, struct us_socket_t * s, int is_client, char* ip, int ip_length);
|
||||
|
||||
@@ -276,27 +276,6 @@ struct us_socket_t *us_socket_detach(int ssl, struct us_socket_t *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->flags.low_prio_state = 0;
|
||||
|
||||
/* We always use nodelay */
|
||||
bsd_socket_nodelay(client_fd, 1);
|
||||
us_internal_socket_context_link_socket(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) {
|
||||
#if defined(LIBUS_USE_LIBUV) || defined(WIN32)
|
||||
return 0;
|
||||
@@ -337,21 +316,17 @@ struct us_socket_t *us_socket_from_fd(struct us_socket_context_t *ctx, int socke
|
||||
|
||||
struct us_socket_t *s = (struct us_socket_t *) p1;
|
||||
s->context = ctx;
|
||||
s->timeout = 0;
|
||||
s->long_timeout = 0;
|
||||
s->timeout = 255;
|
||||
s->long_timeout = 255;
|
||||
s->flags.low_prio_state = 0;
|
||||
s->flags.is_paused = 0;
|
||||
s->flags.allow_half_open = 0;
|
||||
s->flags.is_paused = 0;
|
||||
s->connect_state = NULL;
|
||||
|
||||
/* We always use nodelay */
|
||||
bsd_socket_nodelay(fd, 1);
|
||||
|
||||
int flags = fcntl(fd, F_GETFL, 0);
|
||||
if (flags != -1) {
|
||||
flags |= O_NONBLOCK;
|
||||
fcntl(fd, F_SETFL, flags);
|
||||
}
|
||||
|
||||
apple_no_sigpipe(fd);
|
||||
bsd_set_nonblocking(fd);
|
||||
us_internal_socket_context_link_socket(ctx, s);
|
||||
|
||||
return s;
|
||||
|
||||
Reference in New Issue
Block a user