Added proper error return for closing while reading

This commit is contained in:
Jacob Stewart
2023-06-10 03:18:51 -04:00
parent ed1a1e3e08
commit 3210959afb

10
conn.go
View File

@@ -27,10 +27,16 @@ func newConn(peer *webrtc.PeerConnection, websocket net.Conn) *Conn {
func (c *Conn) Read(b []byte) (int, error) { func (c *Conn) Read(b []byte) (int, error) {
select { select {
case err := <-c.errorChan: case err, ok := <-c.errorChan:
if !ok {
return 0, net.ErrClosed
}
return 0, err // There was some error return 0, err // There was some error
case dat := <- c.readChan: case dat, ok := <- c.readChan:
if !ok {
return 0, net.ErrClosed
}
if len(dat) > len(b) { if len(dat) > len(b) {
return 0, fmt.Errorf("message too big") // TODO - Instead of failing, should we just return partial? return 0, fmt.Errorf("message too big") // TODO - Instead of failing, should we just return partial?
} }