MCPcopy Create free account
hub / github.com/ElementsProject/lightning / websocket_connection_in

Function websocket_connection_in

connectd/connectd.c:732–826  ·  view source on GitHub ↗

~ I speak web socket . * * Actually that's dumb, websocket (aka rfc6455) looks nothing like that. */

Source from the content-addressed store, hash-verified

730 *
731 * Actually that's dumb, websocket (aka rfc6455) looks nothing like that. */
732static struct io_plan *websocket_connection_in(struct io_conn *conn,
733 struct daemon *daemon)
734{
735 int childmsg[2], execfail[2];
736 pid_t childpid;
737 int err;
738 struct conn_in conn_in_arg;
739
740 /* Did we fail to accept? */
741 if (!conn)
742 return accept_failed(daemon);
743
744 conn_in_arg.addr.u.wireaddr.is_websocket = true;
745 if (!get_remote_address(conn, &conn_in_arg.addr))
746 return io_close(conn);
747
748 status_debug("Websocket connection in from %s",
749 fmt_wireaddr_internal(tmpctx, &conn_in_arg.addr));
750
751 if (socketpair(AF_LOCAL, SOCK_STREAM, 0, childmsg) != 0)
752 goto fail;
753
754 if (pipe(execfail) != 0)
755 goto close_msgfd_fail;
756
757 if (fcntl(execfail[1], F_SETFD, fcntl(execfail[1], F_GETFD)
758 | FD_CLOEXEC) < 0)
759 goto close_execfail_fail;
760
761 childpid = fork();
762 if (childpid < 0)
763 goto close_execfail_fail;
764
765 if (childpid == 0) {
766 close(childmsg[0]);
767 close(execfail[0]);
768
769 /* Attach remote socket to stdin. */
770 if (dup2(io_conn_fd(conn), STDIN_FILENO) == -1)
771 goto child_errno_fail;
772
773 /* Attach our socket to stdout. */
774 if (dup2(childmsg[1], STDOUT_FILENO) == -1)
775 goto child_errno_fail;
776
777 /* Make (fairly!) sure all other fds are closed. */
778 closefrom(STDERR_FILENO + 1);
779
780 /* Tell websocket helper what we read so far. */
781 execlp(daemon->websocket_helper, daemon->websocket_helper,
782 NULL);
783
784 child_errno_fail:
785 err = errno;
786 /* Gcc's warn-unused-result fail. */
787 if (write(execfail[1], &err, sizeof(err))) {
788 ;
789 }

Callers

nothing calls this directly

Calls 8

accept_failedFunction · 0.85
get_remote_addressFunction · 0.85
io_closeFunction · 0.85
fmt_wireaddr_internalFunction · 0.85
io_conn_fdFunction · 0.85
closefromFunction · 0.85
tal_parentFunction · 0.85
close_noerrFunction · 0.85

Tested by

no test coverage detected