* Do not reutrn ErrShortRead in readUDP

A read of zero bytes indicates a peer shutdown for TCP sockets -- and
thus returning ErrShortRead is fine in readTCP -- but not for UDP
sockets. For UDP sockets a read of zero bytes literally indicates a
zero-byte datagram, and is a valid return value not indicating an error.

Removing this case will cause readUDP to correctly return a zero-byte
message.

* Return non-temporary error from serveUDP loop

Fixes #613
This commit is contained in:
Tom Thorogood 2018-01-10 00:27:26 +10:30 committed by Miek Gieben
parent e2db8456df
commit 69d25e845f
1 changed files with 6 additions and 6 deletions

View File

@ -509,7 +509,10 @@ func (srv *Server) serveUDP(l *net.UDPConn) error {
}
srv.lock.RUnlock()
if err != nil {
continue
if netErr, ok := err.(net.Error); ok && netErr.Temporary() {
continue
}
return err
}
go srv.serve(s.RemoteAddr(), handler, m, l, s, nil)
}
@ -626,11 +629,8 @@ func (srv *Server) readUDP(conn *net.UDPConn, timeout time.Duration) ([]byte, *S
conn.SetReadDeadline(time.Now().Add(timeout))
m := make([]byte, srv.UDPSize)
n, s, err := ReadFromSessionUDP(conn, m)
if err != nil || n == 0 {
if err != nil {
return nil, nil, err
}
return nil, nil, ErrShortRead
if err != nil {
return nil, nil, err
}
m = m[:n]
return m, s, nil