lib/socket: Changed error handling with sockets