Replace socket shutdown call with linger sockopt

The shutdown call was causing all pending I/O to be discarded.
Linger waits for pending I/O to complete before the close call returns.