@@ -143,9 +143,7 @@ namespace $ {
143
143
144
144
} ) )
145
145
146
- socket . on ( 'data' , ( chunk : Buffer ) => {
147
- $mol_wire_async ( this ) . ws_income ( chunk , upgrade , socket )
148
- } )
146
+ socket . on ( 'data' , ( chunk : Buffer ) => this . ws_income ( chunk , upgrade , socket ) )
149
147
150
148
const key_in = req . headers [ "sec-websocket-key" ]
151
149
const magic = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11'
@@ -170,34 +168,32 @@ namespace $ {
170
168
171
169
_ws_icome_partial = [ ] as Uint8Array [ ]
172
170
173
- @ $mol_action
174
- ws_income (
171
+ async ws_income (
175
172
chunk : Buffer ,
176
173
upgrade : $mol_rest_message ,
177
174
sock : InstanceType < typeof $node . stream . Duplex > ,
178
175
) {
179
176
console . log ( chunk . byteLength )
177
+ sock . pause ( )
178
+
179
+ this . _ws_icome_partial . push ( chunk )
180
180
const patial_size = this . _ws_icome_partial . reduce ( ( sum , buf ) => sum + buf . byteLength , 0 )
181
- const frame = $mol_wire_sync ( $mol_websocket_frame ) . from ( chunk ) as $mol_websocket_frame
182
- const msg_size = frame . size ( ) + frame . data ( ) . size
183
181
184
- sock . pause ( )
182
+ let frame = $mol_websocket_frame . from ( this . _ws_icome_partial [ 0 ] )
183
+ const msg_size = frame . size ( ) + frame . data ( ) . size
185
184
186
- if ( msg_size > patial_size + chunk . byteLength ) {
185
+ if ( msg_size > patial_size ) {
187
186
setTimeout ( ( ) => sock . resume ( ) )
188
- this . _ws_icome_partial . push ( chunk )
189
187
return
190
188
}
191
189
192
- if ( this . _ws_icome_partial . length ) {
193
- this . _ws_icome_partial . push ( chunk )
194
- chunk = Buffer . alloc ( patial_size + chunk . byteLength )
195
- let offset = 0
196
- for ( const buf of this . _ws_icome_partial . splice ( 0 ) ) {
197
- chunk . set ( buf , offset )
198
- offset += buf . byteLength
199
- }
190
+ chunk = Buffer . alloc ( patial_size )
191
+ let offset = 0
192
+ for ( const buf of this . _ws_icome_partial . splice ( 0 ) ) {
193
+ chunk . set ( buf , offset )
194
+ offset += buf . byteLength
200
195
}
196
+ frame = $mol_websocket_frame . from ( chunk )
201
197
202
198
if ( msg_size < chunk . byteLength ) {
203
199
const tail = new Uint8Array ( chunk . buffer , chunk . byteOffset + msg_size )
@@ -221,7 +217,7 @@ namespace $ {
221
217
if ( op !== 'txt' && op !== 'bin' ) return
222
218
223
219
if ( data . length !== 0 ) {
224
- $mol_wire_sync ( this . $ ) . $mol_log3_rise ( {
220
+ this . $ . $mol_log3_rise ( {
225
221
place : this ,
226
222
message : message . method ( ) ,
227
223
url : message . uri ( ) ,
@@ -231,14 +227,14 @@ namespace $ {
231
227
232
228
try {
233
229
234
- $mol_wire_sync ( this . root ( ) ) . REQUEST ( message )
230
+ await $mol_wire_async ( this . root ( ) ) . REQUEST ( message )
235
231
sock . resume ( )
236
232
237
233
} catch ( error : any ) {
238
234
239
235
if ( $mol_promise_like ( error ) ) $mol_fail_hidden ( error )
240
-
241
- $mol_wire_sync ( $$ ) . $mol_log3_fail ( {
236
+
237
+ $$ . $mol_log3_fail ( {
242
238
place : this ,
243
239
message : error . message ?? '' ,
244
240
stack : error . stack ,
0 commit comments