Remove duplicated code for setting the socket options