( opChain *chain, typ int, content []byte, closeCode ...int, )
| 565 | } |
| 566 | |
| 567 | func (ws *Websocket) writeMessage( |
| 568 | opChain *chain, typ int, content []byte, closeCode ...int, |
| 569 | ) { |
| 570 | switch typ { |
| 571 | case websocket.TextMessage, websocket.BinaryMessage: |
| 572 | ws.printWrite(typ, content, 0) |
| 573 | |
| 574 | case websocket.CloseMessage: |
| 575 | if len(closeCode) > 1 { |
| 576 | opChain.fail(AssertionFailure{ |
| 577 | Type: AssertUsage, |
| 578 | Errors: []error{ |
| 579 | errors.New("unexpected multiple closeCode arguments"), |
| 580 | }, |
| 581 | }) |
| 582 | return |
| 583 | } |
| 584 | |
| 585 | code := websocket.CloseNormalClosure |
| 586 | if len(closeCode) > 0 { |
| 587 | code = closeCode[0] |
| 588 | } |
| 589 | |
| 590 | ws.printWrite(typ, content, code) |
| 591 | |
| 592 | content = websocket.FormatCloseMessage(code, string(content)) |
| 593 | |
| 594 | default: |
| 595 | opChain.fail(AssertionFailure{ |
| 596 | Type: AssertUsage, |
| 597 | Errors: []error{ |
| 598 | fmt.Errorf("unexpected websocket message type %s", |
| 599 | wsMessageType(typ)), |
| 600 | }, |
| 601 | }) |
| 602 | return |
| 603 | } |
| 604 | |
| 605 | if !ws.setWriteDeadline(opChain) { |
| 606 | return |
| 607 | } |
| 608 | |
| 609 | if err := ws.conn.WriteMessage(typ, content); err != nil { |
| 610 | opChain.fail(AssertionFailure{ |
| 611 | Type: AssertOperation, |
| 612 | Errors: []error{ |
| 613 | errors.New("failed to write to websocket"), |
| 614 | err, |
| 615 | }, |
| 616 | }) |
| 617 | return |
| 618 | } |
| 619 | } |
| 620 | |
| 621 | func (ws *Websocket) setReadDeadline(opChain *chain) bool { |
| 622 | deadline := infiniteTime |
no test coverage detected