Skip to content

Commit e875e64

Browse files
author
jin
committed
++
1 parent 261965c commit e875e64

File tree

2 files changed

+19
-23
lines changed

2 files changed

+19
-23
lines changed

build/server/server.node.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ namespace $ {
316316

317317
const server = $node.child_process.spawn(
318318
'node',
319-
[ `./${path}/-/node.js`, ... args ],
319+
[ '--enable-source-maps', '--trace-uncaught', `./${path}/-/node.js`, ... args ],
320320
{
321321
stdio: [ 'pipe', 'inherit', 'inherit' ],
322322
}

rest/server/server.node.ts

+18-22
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,7 @@ namespace $ {
143143

144144
} ) )
145145

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 ) )
149147

150148
const key_in = req.headers["sec-websocket-key"]
151149
const magic = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11'
@@ -170,34 +168,32 @@ namespace $ {
170168

171169
_ws_icome_partial = [] as Uint8Array[]
172170

173-
@ $mol_action
174-
ws_income(
171+
async ws_income(
175172
chunk: Buffer,
176173
upgrade: $mol_rest_message,
177174
sock: InstanceType< typeof $node.stream.Duplex >,
178175
) {
179176
console.log(chunk.byteLength)
177+
sock.pause()
178+
179+
this._ws_icome_partial.push( chunk )
180180
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
183181

184-
sock.pause()
182+
let frame = $mol_websocket_frame.from( this._ws_icome_partial[0] )
183+
const msg_size = frame.size() + frame.data().size
185184

186-
if( msg_size > patial_size + chunk.byteLength ) {
185+
if( msg_size > patial_size ) {
187186
setTimeout( ()=> sock.resume() )
188-
this._ws_icome_partial.push( chunk )
189187
return
190188
}
191189

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
200195
}
196+
frame = $mol_websocket_frame.from( chunk )
201197

202198
if( msg_size < chunk.byteLength ) {
203199
const tail = new Uint8Array( chunk.buffer, chunk.byteOffset + msg_size )
@@ -221,7 +217,7 @@ namespace $ {
221217
if( op !== 'txt' && op !== 'bin' ) return
222218

223219
if( data.length !== 0 ) {
224-
$mol_wire_sync( this.$ ).$mol_log3_rise({
220+
this.$.$mol_log3_rise({
225221
place: this,
226222
message: message.method(),
227223
url: message.uri(),
@@ -231,14 +227,14 @@ namespace $ {
231227

232228
try {
233229

234-
$mol_wire_sync( this.root() ).REQUEST( message )
230+
await $mol_wire_async( this.root() ).REQUEST( message )
235231
sock.resume()
236232

237233
} catch( error: any ) {
238234

239235
if( $mol_promise_like( error ) ) $mol_fail_hidden( error )
240-
241-
$mol_wire_sync( $$ ).$mol_log3_fail({
236+
237+
$$.$mol_log3_fail({
242238
place: this,
243239
message: error.message ?? '',
244240
stack: error.stack,

0 commit comments

Comments
 (0)