* handle received close respond * * @param {header.Header} hd The header * * @throws {Exception} when given stream is not running *
(hd)
| 352 | * |
| 353 | */ |
| 354 | async handleClose(hd) { |
| 355 | if (hd.data() >= this.streams.length) { |
| 356 | return; |
| 357 | } |
| 358 | |
| 359 | let stream = this.streams[hd.data()]; |
| 360 | |
| 361 | if (!stream.running()) { |
| 362 | // WARNING: Connection must be reset at this point because we cannot |
| 363 | // determine how many bytes to read |
| 364 | throw new Exception( |
| 365 | 'Remote is requesting for stream "' + |
| 366 | hd.data() + |
| 367 | '" to be closed, but the stream is not running', |
| 368 | false |
| 369 | ); |
| 370 | } |
| 371 | |
| 372 | let cResult = await stream.close(); |
| 373 | |
| 374 | let completedHeader = new header.Header(header.COMPLETED); |
| 375 | completedHeader.set(hd.data()); |
| 376 | this.sender.send(new Uint8Array([completedHeader.value()])); |
| 377 | |
| 378 | return cResult; |
| 379 | } |
| 380 | |
| 381 | /** |
| 382 | * handle received close respond |