예제 #1
0
파일: drone.c 프로젝트: safchain/ml-stress
static void drone_event_cb(struct bufferevent *bev, short events, void *arg) {
    struct session *session = arg;
    struct job *job = session->job;
    struct timeval now;

    if (events & BEV_EVENT_CONNECTED) {
        evutil_socket_t fd = bufferevent_getfd(bev);
        set_tcp_no_delay(fd);

        job->result->total_sessions++;
    } else if (events & BEV_EVENT_ERROR) {
        perror("Not connected");

        gettimeofday(&now, NULL);
        if (drone_report_error_ready(job, &now)) {
            snprintf(job->error_msg, sizeof(job->error_msg),
                    "Connection to the server lost(%zd message skipped)",
                    job->skipped_error_msg);

            drone_report_error(job, &now);
        }

        if (job->result->total_sessions)
            job->result->total_sessions--;

        bufferevent_setfd(bev, -1);
    }
}
예제 #2
0
파일: client.c 프로젝트: goby/wemcached
static void eventcb(struct bufferevent *bev, short events, void *ptr)
{
  if (events & BEV_EVENT_CONNECTED) {
    evutil_socket_t fd = bufferevent_getfd(bev);
    set_tcp_no_delay(fd);
  } else if (events & BEV_EVENT_ERROR) {
    printf("NOT Connected\n");
  }
}
예제 #3
0
static void accept_conn_cb(struct evconnlistener *listener,
    evutil_socket_t fd,struct sockaddr*address,int socklen, void*ctx)
{
  /* We got a new connection! Set up a bufferevent for it. */
  struct event_base *base=evconnlistener_get_base(listener);
  struct bufferevent *bev=bufferevent_socket_new(base,fd,BEV_OPT_CLOSE_ON_FREE);
  set_tcp_no_delay(fd);

  bufferevent_setcb(bev,echo_read_cb,NULL,echo_event_cb,NULL);

  bufferevent_enable(bev,EV_READ|EV_WRITE);
}
예제 #4
0
/* 事件回调函数,连接状态改变时回调的函数 */
void event_cb(struct bufferevent *bev, short events, void *ptr)
{
    struct event_base *tbase = (struct event_base*)ptr;
    if ( events & BEV_EVENT_CONNECTED){
	/* We're connected to server. Ordinarily we'd do
           something here, like start reading or writing. */
        evutil_socket_t fd = bufferevent_getfd(bev);
        set_tcp_no_delay(fd);
	    printf("Server is connected!\n");
    }else { //如果连接不成功的消息,就停止事件循环
    	bufferevent_free(bev);
    	event_base_loopbreak(tbase);
    	printf("Server connect erro!! or The connect have been shutdown: %X\n", events);
    }
}
예제 #5
0
파일: drone.c 프로젝트: safchain/ml-stress
static void drone_srv_accept_success_cb(struct evconnlistener *listener,
evutil_socket_t fd, struct sockaddr *address, int socklen, void *ctx) {
    struct event_base *base = evconnlistener_get_base(listener);
    struct bufferevent *bev = bufferevent_socket_new(base, fd,
            BEV_OPT_CLOSE_ON_FREE);
    struct client *client;

    client = calloc(1, sizeof(struct client));
    client->base = base;
    client->buffer = malloc(sizeof(Drone__JobRequest) + sizeof(u_int32_t));

    set_tcp_no_delay(fd);

    bufferevent_setcb(bev, drone_srv_read_cb, NULL, drone_srv_event_cb, client);
    bufferevent_enable(bev, EV_READ | EV_WRITE);
}
예제 #6
0
파일: net.c 프로젝트: JustXxx/shark
int disable_tcp_no_delay(int fd)
{
    return set_tcp_no_delay(fd, 0);
}
예제 #7
0
파일: net.c 프로젝트: JustXxx/shark
int enable_tcp_no_delay(int fd)
{
    return set_tcp_no_delay(fd, 1);
}