Network code cleanup

This includes a change to ensure that the listening socket is closed
immediately after accepting a connection.
Merge pull request #1 from glguy/master

Network code cleanup