Esempio n. 1
0
void pc_client_stop(pc_client_t *client) {
  if(PC_ST_INITED == client->state || PC_ST_CONNECTING == client->state) {
    client->state = PC_ST_CLOSED;
    return;
  }

  if(PC_ST_CLOSED == client->state) {
    return;
  }

  client->state = PC_ST_CLOSED;
  if(client->transport) {
    pc_transport_destroy(client->transport);
    client->transport = NULL;
  }

  if(client->heartbeat_timer != NULL) {
    uv_close((uv_handle_t *)client->heartbeat_timer, pc__handle_close_cb);
    client->heartbeat_timer = NULL;
    client->heartbeat = 0;
  }
  if(client->timeout_timer != NULL) {
    uv_close((uv_handle_t *)client->timeout_timer, pc__handle_close_cb);
    client->timeout_timer = NULL;
    client->timeout = 0;
  }
  if(client->close_async != NULL) {
    uv_close((uv_handle_t *)client->close_async, pc__handle_close_cb);
    client->close_async = NULL;
  }
}
Esempio n. 2
0
void pc_client_stop(pc_client_t *client) {
  pc_client_state state;
  uv_mutex_lock(&client->state_mutex);
  state = client->state;
  uv_mutex_unlock(&client->state_mutex);

  if (client->enable_reconnect && state != PC_ST_DISCONNECTING) {
    // still reconnecting, just return
    if (client->reconnecting){
      return;
    }

    pc__client_reconnect(client);
    return;
  }

  if(PC_ST_INITED == state) {
    client->state = PC_ST_CLOSED;
    return;
  }

  if(PC_ST_CLOSED == state) {
    return;
  }

  uv_mutex_lock(&client->state_mutex);
  client->state = PC_ST_CLOSED;
  uv_mutex_unlock(&client->state_mutex);

  if(client->transport) {
    pc_transport_destroy(client->transport);
    client->transport = NULL;
  }

  if(client->heartbeat_timer != NULL) {
    uv_close((uv_handle_t *)client->heartbeat_timer, pc__handle_close_cb);
    client->heartbeat_timer = NULL;
    client->heartbeat = 0;
  }
  if(client->timeout_timer != NULL) {
    uv_close((uv_handle_t *)client->timeout_timer, pc__handle_close_cb);
    client->timeout_timer = NULL;
    client->timeout = 0;
  }
  if(client->close_async != NULL) {
    uv_close((uv_handle_t *)client->close_async, pc__handle_close_cb);
    client->close_async = NULL;
  }

  if(client->enable_reconnect) {
    uv_close((uv_handle_t*)&client->reconnect_timer, NULL);
  }
}
Esempio n. 3
0
void pc__client_reconnect_reset(pc_client_t *client) {
  assert(client);
  if(client->transport) {
    pc_transport_destroy(client->transport);
    client->transport = NULL;
  }

  if(client->heartbeat_timer != NULL) {
    uv_timer_stop(client->heartbeat_timer);
    client->heartbeat = 0;
  }

  if(client->timeout_timer != NULL) {
    uv_timer_stop(client->timeout_timer);
    client->timeout = 0;
  } 
  
  if(client->requests) {
    pc_map_clear(client->requests);
  }

  if(client->pkg_parser) {
    pc_pkg_parser_reset(client->pkg_parser);
  }

  if(client->handshake_opts) {
    json_decref(client->handshake_opts);
    client->handshake_opts = NULL;
  }

  if(client->route_to_code) {
    json_decref(client->route_to_code);
    client->route_to_code = NULL;
  }
  if(client->code_to_route) {
    json_decref(client->code_to_route);
    client->code_to_route = NULL;
  }
  if(client->server_protos) {
    json_decref(client->server_protos);
    client->server_protos = NULL;
  }
  if(client->client_protos) {
    json_decref(client->client_protos);
    client->client_protos = NULL;
  }
  uv_mutex_lock(&client->state_mutex);
  client->state = PC_ST_INITED;
  uv_mutex_unlock(&client->state_mutex);
}