* Write stdin data * @param {Uint8Array|Buffer} data - Stdin data
(data)
| 263 | /** |
| 264 | * Write a UDP datagram received by an existing NAT flow. |
| 265 | * @param {Object} msg - { key, data } |
| 266 | */ |
| 267 | writeUdpRecv(msg) { |
| 268 | // Format: keyLen(1) + key + data. Endpoint metadata lives in the |
| 269 | // worker's flow table, which also prevents spoofed reply addresses. |
| 270 | const keyBytes = Buffer.from(msg.key, 'utf8'); |
| 271 | if (keyBytes.length > 255) return false; |
| 272 | const dataBytes = Buffer.isBuffer(msg.data) ? msg.data : Buffer.from(msg.data); |
| 273 | const payload = Buffer.alloc(1 + keyBytes.length + dataBytes.length); |
| 274 | payload[0] = keyBytes.length; |
| 275 | keyBytes.copy(payload, 1); |
| 276 | dataBytes.copy(payload, 1 + keyBytes.length); |
| 277 | return this.writeMessage(NET_MSG_UDP_RECV, payload); |
| 278 | } |
| 279 | |
| 280 | /** |
| 281 | * Write stdin data |
| 282 | * @param {Uint8Array|Buffer} data - Stdin data |
| 283 | */ |
| 284 | writeStdin(data) { |
| 285 | // Wait for previous stdin to be consumed |
| 286 | while (Atomics.load(this.int32, STDIN_FLAG_INDEX) !== 0) { |
| 287 | // Busy wait - stdin should be consumed quickly |
| 288 | Atomics.wait(this.int32, STDIN_FLAG_INDEX, 1, 5); |