1# Copyright 2013 The Chromium Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4from __future__ import absolute_import 5 6import socket 7 8# pylint: disable=unused-import 9from websocket import create_connection as _create_connection 10from websocket import WebSocketConnectionClosedException 11from websocket import WebSocketException 12from websocket import WebSocketTimeoutException 13 14 15def create_connection(*args, **kwargs): 16 sockopt = kwargs.get('sockopt', []) 17 18 # By default, we set SO_REUSEADDR on all websockets used by Telemetry. 19 # This prevents spurious address in use errors on Windows. 20 # 21 # TODO(tonyg): We may want to set SO_NODELAY here as well. 22 sockopt.append((socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)) 23 24 kwargs['sockopt'] = sockopt 25 return _create_connection(*args, **kwargs) 26