예제 #1
0
파일: client.c 프로젝트: NewYuil/libpomelo
int pc_client_connect(pc_client_t *client, struct sockaddr_in *addr) {
  pc_connect_t *conn_req = pc_connect_req_new(addr);

  if(conn_req == NULL) {
    LOGD( "Fail to malloc pc_connect_t.\n");
    goto error;
  }

  if(pc_connect(client, conn_req, NULL, pc__client_connected_cb)) {
    LOGD( "Fail to connect to server.\n");
    goto error;
  }

  // 1. start work thread
  // 2. wait connect result

  uv_thread_create(&client->worker, pc__worker, client);

  // TODO should set a timeout?
  pc__cond_wait(client, 0);

  pc_connect_req_destroy(conn_req);

  if(PC_ST_WORKING != client->state) {
    return -1;
  }

  return 0;
error:
  if(conn_req) pc_connect_req_destroy(conn_req);
  return -1;
}
예제 #2
0
파일: client.c 프로젝트: mashx/libpomelo
static void pc__client_connect3_cb(pc_connect_t* req, int status) {
  if(status == -1) {
    pc_client_stop(req->client);
    pc_connect_req_destroy(req);
    return;
  }

  pc_emit_event(req->client, PC_EVENT_RECONNECT, req->client);
  pc_connect_req_destroy(req);
}
예제 #3
0
파일: client.c 프로젝트: mashx/libpomelo
int pc_client_connect3(pc_client_t *client, struct sockaddr_in *addr) {
  pc_connect_t *conn_req = pc_connect_req_new(addr);

  if(client->enable_reconnect){
    memcpy(&client->addr, addr, sizeof(struct sockaddr_in));
  }

  if(conn_req == NULL) {
    fprintf(stderr, "Fail to malloc pc_connect_t.\n");
    goto error;
  }

  if(pc_connect(client, conn_req, NULL, pc__client_connect3_cb)) {
    fprintf(stderr, "Fail to connect to server.\n");
    goto error;
  }

  uv_thread_create(&client->worker, pc__worker, client);

  return 0;

error:
  if(conn_req) pc_connect_req_destroy(conn_req);
  return -1;
}
예제 #4
0
void   cc_pomelo_on_ansync_connect_cb(pc_connect_t* conn_req, int status)
{
    if (conn_req) {
        pc_connect_req_destroy(conn_req);
    }
    POMELO->connectCallBack(status);

}
예제 #5
0
void   cc_pomelo_on_ansync_connect_cb  (pc_connect_t* conn_req, int status){
    //CCLOG("data = %p\n", conn_req->data);
    if (conn_req) {
        pc_connect_req_destroy(conn_req);
    }
    s_CCPomelo->connectCallBack(status);

}
예제 #6
0
파일: client.c 프로젝트: 559210/libpomelo
void pc__client_reconnect_timer_cb(uv_timer_t* timer, int status) {
  /* unused */
  (void)status;
  pc_client_t* client = (pc_client_t*)timer->data;
  pc_connect_t* conn_req = pc_connect_req_new(&client->addr);
  if (!conn_req) {
    fprintf(stderr, "out of memory");
    pc_client_stop(client);
  }

  if(pc_connect(client, conn_req, NULL, pc__client_reconnected_cb)) {
    fprintf(stderr, "Fail to connect to server.\n");
    pc_connect_req_destroy(conn_req);
    client->reconnecting = 0;
    pc_client_stop(client);
  }
}
예제 #7
0
void cc_pomelo_on_connect_cb(pc_connect_t *conn_req, int status){
    s_CCPomelo->lockConnect();
    printf("data = %p\n", conn_req->data);
    pc_connect_req_destroy(conn_req);
    s_CCPomelo->connect_stage = KCCPomeloConnectStageDone;//连接完成 等待分发状态
    s_CCPomelo->connect_status = status;
    if(-1==status){
        printf("Connected error.\n");
    } else {
//        working = 1;
    }
//    pc_add_listener(s_CCPomelo->getClient(), PC_EVENT_DISCONNECT, on_close);
//    // add pomelo events listener
//    void (*on_disconnect)(pc_client_t *client, const char *event, void *data) = &CCPomelo::onDisconnectCallback;
//    void (*on_chat)(pc_client_t *client, const char *event, void *data) = &CCPomelo::onChatCallback;
//    void (*on_add)(pc_client_t *client, const char *event, void *data) = &CCPomelo::onAddCallback;
//    void (*on_leave)(pc_client_t *client, const char *event, void *data) = &CCPomelo::onLeaveCallback;
//    
//    pc_add_listener(s_CCPomelo->getClient(), "disconnect", on_disconnect);
//    pc_add_listener(s_CCPomelo->getClient(), "onChat", on_chat);
//    pc_add_listener(s_CCPomelo->getClient(), "onAdd", on_add);
//    pc_add_listener(s_CCPomelo->getClient(), "onLeave", on_leave);
    s_CCPomelo->unlockConnect();
}