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
8from telemetry.core import util
9
10util.AddDirToPythonPath(
11    util.GetTelemetryDir(), 'third_party', 'websocket-client')
12# pylint: disable=W0611
13from websocket import create_connection as _create_connection
14from websocket import WebSocketException
15from websocket import WebSocketTimeoutException
16
17
18def create_connection(*args, **kwargs):
19  sockopt = kwargs.get('sockopt', [])
20
21  # By default, we set SO_REUSEADDR on all websockets used by Telemetry.
22  # This prevents spurious address in use errors on Windows.
23  #
24  # TODO(tonyg): We may want to set SO_NODELAY here as well.
25  sockopt.append((socket.SOL_SOCKET, socket.SO_REUSEADDR, 1))
26
27  kwargs['sockopt'] = sockopt
28  return _create_connection(*args, **kwargs)
29