@@ -241,7 +241,7 @@ addToLibrary({
241
241
addr ,
242
242
port ,
243
243
socket : ws ,
244
- dgram_send_queue : [ ]
244
+ msg_send_queue : [ ]
245
245
} ;
246
246
247
247
SOCKFS . websocket_sock_ops . addPeer ( sock , peer ) ;
@@ -254,7 +254,7 @@ addToLibrary({
254
254
#if SOCKET_DEBUG
255
255
dbg ( 'websocket queuing port message (port ' + sock . sport + ')' ) ;
256
256
#endif
257
- peer . dgram_send_queue . push ( new Uint8Array ( [
257
+ peer . msg_send_queue . push ( new Uint8Array ( [
258
258
255 , 255 , 255 , 255 ,
259
259
'p' . charCodeAt ( 0 ) , 'o' . charCodeAt ( 0 ) , 'r' . charCodeAt ( 0 ) , 't' . charCodeAt ( 0 ) ,
260
260
( ( sock . sport & 0xff00 ) >> 8 ) , ( sock . sport & 0xff )
@@ -283,13 +283,13 @@ addToLibrary({
283
283
Module [ 'websocket' ] . emit ( 'open' , sock . stream . fd ) ;
284
284
285
285
try {
286
- var queued = peer . dgram_send_queue . shift ( ) ;
286
+ var queued = peer . msg_send_queue . shift ( ) ;
287
287
while ( queued ) {
288
288
#if SOCKET_DEBUG
289
289
dbg ( 'websocket sending queued data (' + queued . byteLength + ' bytes): ' + [ Array . prototype . slice . call ( new Uint8Array ( queued ) ) ] ) ;
290
290
#endif
291
291
peer . socket . send ( queued ) ;
292
- queued = peer . dgram_send_queue . shift ( ) ;
292
+ queued = peer . msg_send_queue . shift ( ) ;
293
293
}
294
294
} catch ( e ) {
295
295
// not much we can do here in the way of proper error handling as we've already
@@ -493,8 +493,9 @@ addToLibrary({
493
493
sock . daddr = peer . addr ;
494
494
sock . dport = peer . port ;
495
495
496
- // always "fail" in non-blocking mode
497
- throw new FS . ErrnoError ( { { { cDefs . EINPROGRESS } } } ) ;
496
+ // because we cannot synchronously block to wait for the WebSocket
497
+ // connection to complete, we return here pretending that the connection
498
+ // was a success.
498
499
} ,
499
500
listen ( sock , backlog ) {
500
501
if ( ! ENVIRONMENT_IS_NODE ) {
@@ -606,7 +607,9 @@ addToLibrary({
606
607
if ( ! dest || dest . socket . readyState === dest . socket . CLOSING || dest . socket . readyState === dest . socket . CLOSED ) {
607
608
throw new FS . ErrnoError ( { { { cDefs . ENOTCONN } } } ) ;
608
609
} else if ( dest . socket . readyState === dest . socket . CONNECTING ) {
609
- throw new FS . ErrnoError ( { { { cDefs . EAGAIN } } } ) ;
610
+ #if SOCKET_DEBUG
611
+ dbg ( 'socket sendmsg called while socket is still connecting.' ) ;
612
+ #endif
610
613
}
611
614
}
612
615
@@ -631,21 +634,21 @@ addToLibrary({
631
634
}
632
635
#endif
633
636
634
- // if we're emulating a connection-less dgram socket and don't have
635
- // a cached connection , queue the buffer to send upon connect and
636
- // lie, saying the data was sent now.
637
- if ( sock . type === { { { cDefs . SOCK_DGRAM } } } ) {
638
- if ( ! dest || dest . socket . readyState !== dest . socket . OPEN ) {
639
- // if we're not connected, open a new connection
637
+ // if we don't have a cached connectionless UDP datagram connection, or
638
+ // the TCP socket is still connecting , queue the message to be sent upon
639
+ // connect, and lie, saying the data was sent now.
640
+ if ( ! dest || dest . socket . readyState !== dest . socket . OPEN ) {
641
+ // if we're not connected, open a new connection
642
+ if ( sock . type === { { { cDefs . SOCK_DGRAM } } } ) {
640
643
if ( ! dest || dest . socket . readyState === dest . socket . CLOSING || dest . socket . readyState === dest . socket . CLOSED ) {
641
644
dest = SOCKFS . websocket_sock_ops . createPeer ( sock , addr , port ) ;
642
645
}
646
+ }
643
647
#if SOCKET_DEBUG
644
- dbg ( 'websocket queuing (' + length + ' bytes): ' + [ Array . prototype . slice . call ( new Uint8Array ( data ) ) ] ) ;
648
+ dbg ( 'websocket queuing (' + length + ' bytes): ' + [ Array . prototype . slice . call ( new Uint8Array ( data ) ) ] ) ;
645
649
#endif
646
- dest . dgram_send_queue . push ( data ) ;
647
- return length ;
648
- }
650
+ dest . msg_send_queue . push ( data ) ;
651
+ return length ;
649
652
}
650
653
651
654
try {
0 commit comments