@@ -277,8 +277,7 @@ static void
277
277
ping_pong (struct lwan_request * request , uint16_t header , enum ws_opcode opcode )
278
278
{
279
279
const size_t len = header & 0x7f ;
280
- char msg [128 ];
281
- char mask [4 ];
280
+ char msg [4 + 128 ];
282
281
283
282
assert (header & WS_MASKED );
284
283
assert (opcode == WS_OPCODE_PING || opcode == WS_OPCODE_PONG );
@@ -291,28 +290,16 @@ ping_pong(struct lwan_request *request, uint16_t header, enum ws_opcode opcode)
291
290
__builtin_unreachable ();
292
291
}
293
292
294
- struct iovec vec [] = {
295
- {.iov_base = mask , .iov_len = sizeof (mask )},
296
- {.iov_base = msg , .iov_len = len },
297
- };
298
-
299
293
if (opcode == WS_OPCODE_PING ) {
300
- lwan_readv (request , vec , N_ELEMENTS ( vec ) );
301
- unmask (msg , len , mask );
294
+ lwan_recv (request , msg , len + 4 , 0 );
295
+ unmask (msg + 4 , len , msg );
302
296
write_websocket_frame (request , WS_MASKED | WS_OPCODE_PONG , msg , len );
303
297
} else {
304
298
/* From MDN: "You might also get a pong without ever sending a ping;
305
299
* ignore this if it happens." */
306
300
307
301
/* FIXME: should we care about the contents of PONG packets? */
308
- /* FIXME: should we have a lwan_recvmsg() too that takes an iovec? */
309
- const size_t total_len = vec [0 ].iov_len + vec [1 ].iov_len ;
310
- if (LIKELY (total_len < sizeof (msg ))) {
311
- lwan_recv (request , msg , total_len , MSG_TRUNC );
312
- } else {
313
- lwan_recv (request , vec [0 ].iov_base , vec [0 ].iov_len , MSG_TRUNC );
314
- lwan_recv (request , vec [1 ].iov_base , vec [1 ].iov_len , MSG_TRUNC );
315
- }
302
+ lwan_recv (request , msg , len + 4 , MSG_TRUNC );
316
303
}
317
304
}
318
305
0 commit comments