From 57a06745a48093c25d0f4729ccea41a918d6427d Mon Sep 17 00:00:00 2001 From: dave caruso Date: Thu, 7 Sep 2023 04:58:44 -0700 Subject: Progress for Next.js (#4468) * L * ipc * asdfghjkl * dfghjk * it works! * types * patches for next.js * sdfghj * wsdfgn,./ * this * yolo * okay loser * asdfghjk * add some more APIs * MESS * sdfghjkl * remove native events from streams * stuff * remove lazy(primordials) test * debugging * okay * less fake extensions object * fix `Buffer.toString()` args logic * fix deserialize * make tests work * add test for `Buffer.toString` args * Update server.zig * remove test * update test * Update spawn-streaming-stdin.test.ts * fix linux build * Update fs.test.ts * cli message improvements * dfshaj * Fix fs.watch bug maybe? * remove --------- Co-authored-by: Dylan Conway --- packages/bun-usockets/src/socket.c | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'packages/bun-usockets/src/socket.c') diff --git a/packages/bun-usockets/src/socket.c b/packages/bun-usockets/src/socket.c index 61cbb2c0f..5f5a91acb 100644 --- a/packages/bun-usockets/src/socket.c +++ b/packages/bun-usockets/src/socket.c @@ -14,6 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +// clang-format off #include "libusockets.h" #include "internal/internal.h" @@ -192,6 +193,45 @@ struct us_socket_t *us_socket_attach(int ssl, LIBUS_SOCKET_DESCRIPTOR client_fd, 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; +#endif + if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) != 0) { + return 0; + } + + return us_socket_from_fd(ctx, socket_ext_size, fds[0]); +} + + +struct us_socket_t *us_socket_from_fd(struct us_socket_context_t *ctx, int socket_ext_size, LIBUS_SOCKET_DESCRIPTOR fd) { +#ifdef LIBUS_USE_LIBUV + return 0; +#endif + struct us_poll_t *p1 = us_create_poll(ctx->loop, 0, sizeof(struct us_socket_t) + socket_ext_size); + us_poll_init(p1, fd, POLL_TYPE_SOCKET); + us_poll_start(p1, ctx->loop, LIBUS_SOCKET_READABLE | LIBUS_SOCKET_WRITABLE); + + struct us_socket_t *s = (struct us_socket_t *) p1; + s->context = ctx; + s->timeout = 0; + s->long_timeout = 0; + s->low_prio_state = 0; + + /* We always use nodelay */ + bsd_socket_nodelay(fd, 1); + + us_internal_socket_context_link_socket(ctx, s); + + if (ctx->on_open) { + ctx->on_open(s, 0, 0, 0); + } + + return s; +} + + /* Not shared with SSL */ void *us_socket_get_native_handle(int ssl, struct us_socket_t *s) { -- cgit v1.2.3