Manages the client side of a single interchange connection.
347101
function InterchangeConnection(connectionManager, interchangeUrl) {
  var self = {};

  var socket;

  self.interchangeUrl = interchangeUrl;
  self.connected = false;
  self.sessionId = undefined;
  self.serverVersion = 'unknown';
  self.serverAgent = 'unknown';

  var pendingCommands = [];

  /**
   * Opens a socket connection to the interchange server.
   */
  self._open = function() {
    debug('Connecting to %s', interchangeUrl);

    socket = io.connect(interchangeUrl, {
        forceNew: true,
        transports: ['websocket']
    });

    ///////////////////
    // Socket Events //
    ///////////////////

    socket.on('connect', function() {
      debug('Connected to %s', interchangeUrl);
      self.connected = true;
      connectionManager.emit('connect', {
          interchangeUrl: interchangeUrl
      });
      _nextCommand();
    });

    socket.on('error', function(err) {
      console.error('Connection error %s', interchangeUrl);
      connectionManager.emit('error', {
          interchangeUrl: interchangeUrl,
          error: err
      });
    });

    socket.on('reconnect', function() {
      debug('Reconnecting %s', interchangeUrl);
      // If our client has previously set the session, then reissue it on
      // reconnection.
      if (self.sessionId) {
        self.SESSION(self.sessionId);
      }
      connectionManager.emit('reconnect', {
          interchangeUrl: interchangeUrl
      });
    });

    socket.on('disconnect', function() {
      debug('Disconnected %s', interchangeUrl);
      self.connected = false;
      connectionManager.emit('disconnect', {
          interchangeUrl: interchangeUrl
      });
    });

    socket.on('reconnect_failed', function() {
      debug('Reconnection failed %s', interchangeUrl);
      connectionManager.emit('reconnect_failed', {
          interchangeUrl: interchangeUrl
      });
    });

    ///////////////////////////////
    // Interchange Push Messages //
    ///////////////////////////////

    socket.on('STANZA', function(stanza) {
      debug('STANZA', stanza);
      connectionManager.emit('STANZA', stanza);
    });

    return self;
  }

  //////////////////////////
  // Interchange Commands //
  //////////////////////////

  self.SESSION = function(sessionId) {
    self.sessionId = sessionId;
    var url = 'vox:__session__' + (sessionId ? ('/session/' + sessionId) : '/session');
    return sendCommand('POST', url, {
          version: connectionManager.version,
          agent: connectionManager.agent,
       }, true)
      .then(function(reply) {
        var newSessionId = reply ? reply.newSessionId : 0;
        // If the server replies with a new session ID, then it has created a
        // new session for us.  Update our internal record.
        if (newSessionId) {
          self.sessionId = newSessionId;
        }
        reply = reply ? reply : {};
        reply.version = (reply.version ? reply.version : 'unknown').substr(0, 64);
        reply.agent = (reply.agent ? reply.agent : 'unknown').substr(0, 64);
        self.serverVersion = reply.version;
        self.serverAgent = reply.agent;
        reply.interchangeUrl = interchangeUrl;
        connectionManager.emit('SESSION', reply);
        _nextCommand();
        return reply;
      });
  }

  self.GET = function(url, payload) {
    return sendCommand('GET', url, payload);
  }

  self.POST = function(url, payload) {
    return sendCommand('POST', url, payload);
  }

  self.SUBSCRIBE = function(url, payload) {
    return sendCommand('SUBSCRIBE', url, payload);
  }

  self.UNSUBSCRIBE = function(url, payload) {
    return sendCommand('UNSUBSCRIBE', url, payload);
  }

  self.close = function() {
    socket.close();
    connectionManager._removeConnection(self);
  }

  /**
   * Helper function to send a command to the server.
   *
   * Returns a Promise for the server's response.  Rejects the Promise if the
   * reply's status is not 200.
   *
   * If this connection is not ready to receive commands, the command is queued
   * for later execution.
   */
  function sendCommand(method, url, payload, skipQueue) {
    if (!self.connected) {
      debug('Queueing %s %s', method, url);
      return new P(function(resolve, reject) {
        var p = P.method(function() {
          debug('Dequeueing %s %s', method, url);
          return _sendCommand(method, url, payload)
            .then(resolve)
            .catch(reject);
        });
        if (skipQueue) {
          pendingCommands.splice(0, 0, p);
        } else {
          pendingCommands.push(p);
        }
      });
    }
    return _sendCommand(method, url, payload);
  }

  function _sendCommand(method, url, payload) {
    return new P(function(resolve, reject) {
      var data = {
          url: url,
          payload: payload
      };
      debug('REQUEST %s %s %s\n', interchangeUrl, method, url, data);
      socket.emit(method, data, function(reply) {
        debug('REPLY %s %s %s\n', interchangeUrl, method, url, reply);
        if (reply && reply.status && reply.status != 200) {
          reject(new errors.HttpError(reply.status, reply.message));
        } else {
          resolve(reply);
        }
      });
    });
  }

  /**
   * Executes the next command on the queue.
   */
  function _nextCommand() {
    var fn = pendingCommands.shift();
    if (!fn) {
      return;
    }
    fn().then(_nextCommand);
  }

  return self;
}
610683
def connection_management(frame)
      case @state
      when :waiting_connection_preface
        # The first frame MUST be a SETTINGS frame at the start of a connection.
        @state = :connected
        connection_settings(frame)

      when :connected
        case frame[:type]
        when :settings
          connection_settings(frame)
        when :window_update
          @remote_window += frame[:increment]
          send_data(nil, true)
        when :ping
          if frame[:flags].include? :ack
            emit(:ack, frame[:payload])
          else
            send(type: :ping, stream: 0,
                 flags: [:ack], payload: frame[:payload])
          end
        when :goaway
          # Receivers of a GOAWAY frame MUST NOT open additional streams on
          # the connection, although a new connection can be established
          # for new streams.
          @state = :closed
          @closed_since = Time.now
          emit(:goaway, frame[:last_stream], frame[:error], frame[:payload])
        when :altsvc
          # 4.  The ALTSVC HTTP/2 Frame
          # An ALTSVC frame on stream 0 with empty (length 0) "Origin"
          # information is invalid and MUST be ignored.
          if frame[:origin] && !frame[:origin].empty?
            emit(frame[:type], frame)
          end
        when :blocked
          emit(frame[:type], frame)
        else
          connection_error
        end
      when :closed
        connection_error if (Time.now - @closed_since) > 15
      else
        connection_error
      end
    end
941639
def initialize_switch_endpoints(self):
        """"""
        self._switches = {}
        self._port_group_info = {}
        self._validate_config()
        for s in cfg.CONF.ml2_arista.switch_info:
            switch_ip, switch_user, switch_pass = s.split(":")
            if switch_pass == "''":
                switch_pass = ''
            self._switches[switch_ip] = api.EAPIClient(
                switch_ip,
                switch_user,
                switch_pass,
                verify=False,
                timeout=cfg.CONF.ml2_arista.conn_timeout)
        self._check_dynamic_acl_support()
154268
def _migrate_single(self, conn, migration):
        """"""
        with contextlib.ExitStack() as stack:
            for wrapper in self._wrappers:
                stack.enter_context(wrapper(conn))
            migration.func(conn)
151864
async def teardown_conn(self, context):
        """"""

        client_id = context.user_data

        self._logger.info("Tearing down client connection: %s", client_id)
        if client_id not in self.clients:
            self._logger.warning("client_id %s did not exist in teardown_conn", client_id)
        else:
            del self.clients[client_id]
443067
def release(self, conn):
        """"""
        self._pool_lock.acquire()
        self._pool.put(ConnectionWrapper(self._pool, conn))
        self._current_acquired -= 1
        self._pool_lock.release()
276722
def handle(self, connection_id, message_content):
        
        LOGGER.warning("Received AuthorizationViolation from %s",
                       connection_id)
        # Close the connection
        endpoint = self._network.connection_id_to_endpoint(connection_id)
        self._network.remove_connection(connection_id)
        self._gossip.remove_temp_endpoint(endpoint)
        return HandlerResult(HandlerStatus.DROP)
895467
protected void register(IConnection conn) {
        if (log.isDebugEnabled()) {
            if (conn == null) {
                log.debug("Register null connection, client id: {}", id);
            } else {
                log.debug("Register connection ({}:{}) client id: {}", conn.getRemoteAddress(), conn.getRemotePort(), id);
            }
        }
        if (conn != null) {
            IScope scope = conn.getScope();
            if (scope != null) {
                log.debug("Registering for scope: {}", scope);
                connections.add(conn);
            } else {
                log.warn("Clients scope is null. Id: {}", id);
            }
        } else {
            log.warn("Clients connection is null. Id: {}", id);
        }
    }
1015489
def _handle_incoming_data(self, conn):
        
        connection = [c for c in self.connections if c.conn == conn][0]
        data = conn.recv(1024)
        if data:
            connection.feed(data)
        else:
            self.connections.remove(connection)
245204
private void failOverConnection(Integer partitionId, Long initiatorHSId, Connection c) {
        ClientInterfaceHandleManager cihm = m_cihm.get(c.connectionId());
        if (cihm == null) {
            return;
        }

        List<Iv2InFlight> transactions =
                cihm.removeHandlesForPartitionAndInitiator(partitionId, initiatorHSId);

        if (!transactions.isEmpty()) {
            Iv2Trace.logFailoverTransaction(partitionId, initiatorHSId, transactions.size());
        }

        for (Iv2InFlight inFlight : transactions) {
            ClientResponseImpl response =
                    new ClientResponseImpl(
                            ClientResponseImpl.RESPONSE_UNKNOWN,
                            ClientResponse.UNINITIALIZED_APP_STATUS_CODE,
                            null,
                            new VoltTable[0],
                            DROP_TXN_MASTERSHIP);
            response.setClientHandle(inFlight.m_clientHandle);
            ByteBuffer buf = ByteBuffer.allocate(response.getSerializedSize() + 4);
            buf.putInt(buf.capacity() - 4);
            response.flattenToBuffer(buf);
            buf.flip();
            c.writeStream().enqueue(buf);
        }

        if (cihm.repairCallback != null) {
            cihm.repairCallback.repairCompleted(partitionId, initiatorHSId);
        }
    }
589084
function handleConnection(self, options) {
	if (TRACE)	console.log('Connected to ' + options.host + ':' + options.port)
    	//self.socket = socket;
	self.emit("connect");
}
675485
def eConnect(self, host, port, clientId=0, extraAuth=False):
        """"""
        return _swigibpy.EClientSocketBase_eConnect(self, host, port, clientId, extraAuth)
1040578
def cli(env, identifier, allocation, port, routing_type, routing_method):
    """"""
    mgr = SoftLayer.LoadBalancerManager(env.client)

    loadbal_id, group_id = loadbal.parse_id(identifier)

    # check if any input is provided
    if not any([allocation, port, routing_type, routing_method]):
        raise exceptions.CLIAbort(
            'At least one property is required to be changed!')

    mgr.edit_service_group(loadbal_id,
                           group_id,
                           allocation=allocation,
                           port=port,
                           routing_type=routing_type,
                           routing_method=routing_method)

    env.fout('Load balancer service group %s is being updated!' % identifier)
625035
public void handleDirectRequest(HttpServerExchange exchange) {
        Log.Info(this,"direct request received "+exchange);
        getDirectRequestResponse(exchange.getRequestPath()).then( (s,err) -> {
            exchange.setResponseCode(200);
            exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/html; charset=utf-8");
            exchange.getResponseSender().send(s == null  ? ""+err : s );
        });
    }
591332
static void handleClientDisconnect(H2ONode client) {
    if(client != H2O.SELF) {
      if (H2O.isFlatfileEnabled()) {
        H2O.removeNodeFromFlatfile(client);
      }
      H2O.removeClient(client);
    }
  }
1373549
def main(ctx, connection):
    """"""
    ctx.obj = Manager(connection=connection)
    ctx.obj.bind()
689014
def _ensure_connection(self):
        """"""
        conn = self.connect()
        if conn.recycle and conn.recycle < time.time():
            logger.debug('Client session expired after %is. Recycling.', self._recycle)
            self.close()
            conn = self.connect()
        return conn