Configures the client socket
340339
protected function configureSocket()
    {
        $class = $this->options['socket_class'];
        $options = $this->options['socket_options'];
        $this->socket = new $class($this->uri, $options);
    }
171313
function connection(socket, server) {
  var conn = new Connection(socket)
    , tcp = (server instanceof TcpServer);

  var maxclients = this.conf.get(ConfigKey.MAXCLIENTS);
  if(maxclients && (this.state.length + 1 > maxclients)) {

    this.state.emit('rejected', conn.client.addr, maxclients);

    this.log.debug('rejected %s, exceeds maxclients %s',
      conn.client.addr, maxclients);

    function onWrite() {
      socket.end();
    }

    return conn.write(MaxClients, onWrite.bind(this));
  }

  if(tcp) {
    this.log.debug('accepted connection from %s', conn.client.addr);
  }else if(server) {
    this.log.debug('accepted connection to %s', server.name);
  }else if(!server) {
    this.log.debug('accepted connection in %s', process.pid);
  }

  var timeout = this.conf.get(ConfigKey.TIMEOUT);
  if(typeof timeout === 'number' && timeout) {
    this.log.debug('setting idle timeout for client #%s to %ss',
      conn.id, timeout);
    // config is seconds, socket want milliseconds
    socket.setTimeout(timeout * 1000, function onTimeout() {
      // TODO: log client connection timeout
      socket.destroy();
    })
  }

  conn.once('disconnect', this.disconnect.bind(this));
  conn.on('command', this.command);
  this._state.addConnection(conn);
}
371770
def configure(self, *, hwm: int=None, rcvtimeo: int=None, sndtimeo: int=None, linger: int=None) -> 'Socket':
        
        if hwm is not None:
            self.set_hwm(hwm)
        if rcvtimeo is not None:
            self.setsockopt(zmq.RCVTIMEO, rcvtimeo)
        if sndtimeo is not None:
            self.setsockopt(zmq.SNDTIMEO, sndtimeo)
        if linger is not None:
            self.setsockopt(zmq.LINGER, linger)
        return self
1110766
private function establishSocketConnection()
    {
        $host = $this->params['host'];
        if (!empty($this->params['protocol'])) {
            $host = $this->params['protocol'].'://'.$host;
        }
        $timeout = 15;
        if (!empty($this->params['timeout'])) {
            $timeout = $this->params['timeout'];
        }
        $options = [];
        if (!empty($this->params['sourceIp'])) {
            $options['socket']['bindto'] = $this->params['sourceIp'].':0';
        }

        if (isset($this->params['stream_context_options'])) {
            $options = array_merge($options, $this->params['stream_context_options']);
        }
        $streamContext = stream_context_create($options);
        $this->stream = @stream_socket_client($host.':'.$this->params['port'], $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, $streamContext);
        if (false === $this->stream) {
            throw new Swift_TransportException(
                'Connection could not be established with host '.$this->params['host'].
                ' ['.$errstr.' #'.$errno.']'
                );
        }
        if (!empty($this->params['blocking'])) {
            stream_set_blocking($this->stream, 1);
        } else {
            stream_set_blocking($this->stream, 0);
        }
        stream_set_timeout($this->stream, $timeout);
        $this->in = &$this->stream;
        $this->out = &$this->stream;
    }
509606
def _configured_socket(address, options):
    
    sock = _create_connection(address, options)
    ssl_context = options.ssl_context

    if ssl_context is not None:
        host = address[0]
        try:
            # According to RFC6066, section 3, IPv4 and IPv6 literals are
            # not permitted for SNI hostname.
            if _HAVE_SNI and not is_ip_address(host):
                sock = ssl_context.wrap_socket(sock, server_hostname=host)
            else:
                sock = ssl_context.wrap_socket(sock)
        except IOError as exc:
            sock.close()
            raise ConnectionFailure("SSL handshake failed: %s" % (str(exc),))
        if ssl_context.verify_mode and options.ssl_match_hostname:
            try:
                match_hostname(sock.getpeercert(), hostname=host)
            except CertificateError:
                sock.close()
                raise

    sock.settimeout(options.socket_timeout)
    return sock
212233
function setDefaultMaxSockets(conf) {
    conf.max_sockets = parseInt(conf.max_sockets, 10);
    if (conf.max_sockets > 0) {
        http.globalAgent.maxSockets = conf.max_sockets;
    }
}
1366937
protected final void configureSocketChannel(SocketChannel sc) throws IOException {
    sc.socket().setSoTimeout(this.soTimeout);
    sc.configureBlocking(false);
    if (this.socketOptions.get(StandardSocketOption.SO_REUSEADDR) != null) {
      sc.socket().setReuseAddress(StandardSocketOption.SO_REUSEADDR.type()
          .cast(this.socketOptions.get(StandardSocketOption.SO_REUSEADDR)));
    }
    if (this.socketOptions.get(StandardSocketOption.SO_SNDBUF) != null) {
      sc.socket().setSendBufferSize(StandardSocketOption.SO_SNDBUF.type()
          .cast(this.socketOptions.get(StandardSocketOption.SO_SNDBUF)));
    }
    if (this.socketOptions.get(StandardSocketOption.SO_KEEPALIVE) != null) {
      sc.socket().setKeepAlive(StandardSocketOption.SO_KEEPALIVE.type()
          .cast(this.socketOptions.get(StandardSocketOption.SO_KEEPALIVE)));
    }
    if (this.socketOptions.get(StandardSocketOption.SO_LINGER) != null) {
      sc.socket().setSoLinger(this.soLingerOn, StandardSocketOption.SO_LINGER.type()
          .cast(this.socketOptions.get(StandardSocketOption.SO_LINGER)));
    }
    if (this.socketOptions.get(StandardSocketOption.SO_RCVBUF) != null) {
      sc.socket().setReceiveBufferSize(StandardSocketOption.SO_RCVBUF.type()
          .cast(this.socketOptions.get(StandardSocketOption.SO_RCVBUF)));

    }
    if (this.socketOptions.get(StandardSocketOption.TCP_NODELAY) != null) {
      sc.socket().setTcpNoDelay(StandardSocketOption.TCP_NODELAY.type()
          .cast(this.socketOptions.get(StandardSocketOption.TCP_NODELAY)));
    }
  }
689093
def _setup():
    
    _SOCKET.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
    _SOCKET.bind(('', PORT))
    udp = threading.Thread(target=_listen, daemon=True)
    udp.start()
400231
def add_socket(self, socket):
        
        if socket not in self._sockets:
            self._sockets.add(socket)
            socket.on_closed.connect(self.remove_socket)
1306170
private function init()
    {
        if(!isset($this->config)) {
            $this->config = Config::getInstance();
            $this->client = new Client(
                $this->generateClientConfiguration()
            );
        }
    }
1221285
private void initSocket()
    throws IOException
  {
    _idleTimeout = _port.getKeepaliveTimeout();

    _port.ssl(_socket);

    writeStream().init(_socket.stream());

    // ReadStream cannot use getWriteStream or auto-flush
    // because of duplex mode
    // ReadStream is = getReadStream();
    _readStream.init(_socket.stream());

    if (log.isLoggable(Level.FINEST)) {
      log.finest(dbgId() + "starting connection " + this
                 + ", total=" + _port.getConnectionCount());
    }
  }
926853
def server_bind(self):
        

        if self.allow_reuse_address:
            self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        self.socket.bind(self.server_address)
383459
def __configure_client(self, config):
        
        self.logger.info("Configuring p4 client...")
        client_dict = config.to_dict()
        client_dict['root_path'] = os.path.expanduser(config.get('root_path'))
        os.chdir(client_dict['root_path'])
        client_dict['hostname'] = system.NODE
        client_dict['p4view'] = config['p4view'] % self.environment.target.get_context_dict()
        client = re.sub('//depot', '    //depot', p4client_template % client_dict)
        self.logger.info(lib.call("%s client -i" % self.p4_command,
                                  stdin=client,
                                  env=self.p4environ,
                                  cwd=client_dict['root_path']))
887361
def client_socket(self, config):
		
		if self.__client_socket is None:
			self.__client_socket = self.create_client_socket(config)
		return self.__client_socket
198488
def build_socket(self):
        
        try:
            self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            self.sock.settimeout(self.SOCKET_TIMEOUT)
            self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
            # Check if TLS
            if self.request_object.protocol == 'https':
                self.sock = ssl.wrap_socket(self.sock, ciphers=self.CIPHERS)
            self.sock.connect(
                (self.request_object.dest_addr, self.request_object.port))
        except socket.error as msg:
            raise errors.TestError(
                'Failed to connect to server',
                {
                    'host': self.request_object.dest_addr,
                    'port': self.request_object.port,
                    'proto': self.request_object.protocol,
                    'message': msg,
                    'function': 'http.HttpUA.build_socket'
                })
544958
public void setSocket(Socket socket) throws IOException {
        if (this.socket != null) {
            this.socket.close();
            this.socket = null;
        }
        this.socket = socket;
        setTimeout(timeout);
        prepareStreams(socket);
    }
1241424
function connection(socket){
	this.socket = socket;
	if (!!this.options.encoding) socket.setEncoding(this.options.encoding);
	socket.on('data', this.emit.bind(this, 'data'));
	this.emit('connection', socket);
}