| 90 | } |
| 91 | |
| 92 | void duk_trans_socket_waitconn(void) { |
| 93 | struct sockaddr_in addr; |
| 94 | socklen_t sz; |
| 95 | |
| 96 | if (server_sock < 0) { |
| 97 | fprintf(stderr, "%s: no server socket, skip waiting for connection\n", |
| 98 | __FILE__); |
| 99 | fflush(stderr); |
| 100 | return; |
| 101 | } |
| 102 | if (client_sock >= 0) { |
| 103 | (void) close(client_sock); |
| 104 | client_sock = -1; |
| 105 | } |
| 106 | |
| 107 | fprintf(stderr, "Waiting for debug connection on port %d\n", (int) DUK_DEBUG_PORT); |
| 108 | fflush(stderr); |
| 109 | |
| 110 | sz = (socklen_t) sizeof(addr); |
| 111 | client_sock = accept(server_sock, (struct sockaddr *) &addr, &sz); |
| 112 | if (client_sock < 0) { |
| 113 | fprintf(stderr, "%s: accept() failed, skip waiting for connection: %s\n", |
| 114 | __FILE__, strerror(errno)); |
| 115 | fflush(stderr); |
| 116 | goto fail; |
| 117 | } |
| 118 | |
| 119 | fprintf(stderr, "Debug connection established\n"); |
| 120 | fflush(stderr); |
| 121 | |
| 122 | /* XXX: For now, close the listen socket because we won't accept new |
| 123 | * connections anyway. A better implementation would allow multiple |
| 124 | * debug attaches. |
| 125 | */ |
| 126 | |
| 127 | if (server_sock >= 0) { |
| 128 | (void) close(server_sock); |
| 129 | server_sock = -1; |
| 130 | } |
| 131 | return; |
| 132 | |
| 133 | fail: |
| 134 | if (client_sock >= 0) { |
| 135 | (void) close(client_sock); |
| 136 | client_sock = -1; |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | /* |
| 141 | * Duktape callbacks |
no test coverage detected