Read methods
()
| 792 | // Read methods |
| 793 | |
| 794 | func (c *Conn) advanceFrame() (int, error) { |
| 795 | // 1. Skip remainder of previous frame. |
| 796 | |
| 797 | if c.readRemaining > 0 { |
| 798 | if _, err := io.CopyN(ioutil.Discard, c.br, c.readRemaining); err != nil { |
| 799 | return noFrame, err |
| 800 | } |
| 801 | } |
| 802 | |
| 803 | // 2. Read and parse first two bytes of frame header. |
| 804 | // To aid debugging, collect and report all errors in the first two bytes |
| 805 | // of the header. |
| 806 | |
| 807 | var errors []string |
| 808 | |
| 809 | p, err := c.read(2) |
| 810 | if err != nil { |
| 811 | return noFrame, err |
| 812 | } |
| 813 | |
| 814 | frameType := int(p[0] & 0xf) |
| 815 | final := p[0]&finalBit != 0 |
| 816 | rsv1 := p[0]&rsv1Bit != 0 |
| 817 | rsv2 := p[0]&rsv2Bit != 0 |
| 818 | rsv3 := p[0]&rsv3Bit != 0 |
| 819 | mask := p[1]&maskBit != 0 |
| 820 | c.setReadRemaining(int64(p[1] & 0x7f)) |
| 821 | |
| 822 | c.readDecompress = false |
| 823 | if rsv1 { |
| 824 | if c.newDecompressionReader != nil { |
| 825 | c.readDecompress = true |
| 826 | } else { |
| 827 | errors = append(errors, "RSV1 set") |
| 828 | } |
| 829 | } |
| 830 | |
| 831 | if rsv2 { |
| 832 | errors = append(errors, "RSV2 set") |
| 833 | } |
| 834 | |
| 835 | if rsv3 { |
| 836 | errors = append(errors, "RSV3 set") |
| 837 | } |
| 838 | |
| 839 | switch frameType { |
| 840 | case CloseMessage, PingMessage, PongMessage: |
| 841 | if c.readRemaining > maxControlFramePayloadSize { |
| 842 | errors = append(errors, "len > 125 for control") |
| 843 | } |
| 844 | if !final { |
| 845 | errors = append(errors, "FIN not set on control") |
| 846 | } |
| 847 | case TextMessage, BinaryMessage: |
| 848 | if !c.readFinal { |
| 849 | errors = append(errors, "data before FIN") |
| 850 | } |
| 851 | c.readFinal = final |
no test coverage detected