Move CloseSocket out of SetSocketNonBlocking and pass SOCKET by const reference in SetSocket* functions
Summary: This is a backport of core PR10865
Test Plan:
make check
Reviewers: #bitcoin_abc, jasonbcox
Reviewed By: #bitcoin_abc, jasonbcox
Subscribers: teamcity
Differential Revision: https://reviews.bitcoinabc.org/D1876