Only set SO_LINGER on TCP sockets

SO_LINGER is meaningless for UDP and on some platforms, an attempt to
set that option on a UDP socket triggers an error (see Sourceforge
issues #50, #55 and #56).