The existing ListenAndServe function runs forever without any mechanism
to stop it. This change introduces Serve which receives a user-supplied
UDP listener; this allows the user to close the listener (on another
goroutine), which will cause the ReadFromUDP function will fail and the
loop will terminate, and the Serve() goroutine will be released.
The commit also changes existing behaviour of ListenAndServe, which used
to continue the loop endlessly even when encountering errors (such as
closed listener). The new Serve code (which is also used in
ListenAndServe) examines the error, and if will retry the loop only if
it's a transient error.
Moreover, full-cycle tests of the CoAP client and server were added in
server_test.go.
@dustin - I'd appreciate your opinion regarding this change of behaviour (dealing with errors in the endless loop).
The existing ListenAndServe function runs forever without any mechanism to stop it. This change introduces Serve which receives a user-supplied UDP listener; this allows the user to close the listener (on another goroutine), which will cause the ReadFromUDP function will fail and the loop will terminate, and the Serve() goroutine will be released.
The commit also changes existing behaviour of ListenAndServe, which used to continue the loop endlessly even when encountering errors (such as closed listener). The new Serve code (which is also used in ListenAndServe) examines the error, and if will retry the loop only if it's a transient error.
Moreover, full-cycle tests of the CoAP client and server were added in server_test.go.
@dustin - I'd appreciate your opinion regarding this change of behaviour (dealing with errors in the endless loop).