コード例 #1
0
ファイル: pollset.cpp プロジェクト: AmesianX/libzmq
zmq::pollset_t::pollset_t (const zmq::ctx_t &ctx_) :
    ctx(ctx_),
    stopping (false)
{
    pollset_fd = pollset_create (-1);
    errno_assert (pollset_fd != -1);
}
コード例 #2
0
ファイル: aix.c プロジェクト: 2014lh/node-v0.x-archive
int uv__platform_loop_init(uv_loop_t* loop) {
  loop->fs_fd = -1;

  /* Passing maxfd of -1 should mean the limit is determined
   * by the user's ulimit or the global limit as per the doc */
  loop->backend_fd = pollset_create(-1);

  if (loop->backend_fd == -1)
    return -1;

  return 0;
}
コード例 #3
0
ファイル: main_ipc.cpp プロジェクト: YangChunQuan/Code
int Rpollset()
{
#ifdef  AIX
    int servfd = listen_net(g_port);
    if (servfd < 0)
    {
        printf("listen_net failed:%s \n", strerror(errno));
        return -1;
    }

    struct poll_ctl  pollset[CLIENT_NUM];

    for(int i = 0; i< CLIENT_NUM; i++)
    {
        pollset[i].fd = my_accept(servfd);
        if (pollset[i].fd < 0)
        {
            printf("my_accept failed %s\n", strerror(errno));
            return -1;
        }
        int buff = 1024*1024;
        socklen_t len = sizeof(int);
        if(setsockopt(pollset[i].fd , SOL_SOCKET,SO_RCVBUF , &buff , len) == -1)
        {
            printf("setsockopt SO_RCVBUF failed:%s\n", strerror(errno));
        }
        if(setsockopt(pollset[i].fd , SOL_SOCKET,SO_SNDBUF , &buff , len) == -1)
        {
            printf("setsockopt SO_SNDBUF failed:%s\n", strerror(errno));
        }
    }

    pollset_t ps = pollset_create(-1);
    if(ps < 0)
    {
        printf("pollset_create failed %s\n",strerror(errno));
        return -1;
    }

    for(int i = 0; i< CLIENT_NUM; i++)
    {
        pollset[i].events = POLLIN;
        pollset[i].cmd = PS_ADD;
        printf("my_accept clifd[%d] %d\n", i , pollset[i].fd);
    }

    nRet = pollset_ctl(ps, pollset, CLIENT_NUM);
    if(nRet < 0)
    {
        printf("pollset_ctl failed %s\n",strerror(errno));
        return -1;
    }

    char  buff[MAX_FD][1024];
    int   readlen[MAX_FD];
    memset(buff, 0, MAX_FD*1024);
    memset(readlen, 0, sizeof(readlen));

    struct pollfd fds[CLIENT_NUM];
    memset(fds, 0, sizeof(fds));
    int conn = CLIENT_NUM;
    int nRet = 0;
    gettimeofday(&time_c, NULL);
    while (true)
    {
        if (_HandleSignal() < 0)
            break;

        if (conn == 0)
        {
            printf("no fd poll\n");
            break;
        }
        if (g_count2 >= loop_times && loop_times != 0)
        {
            printf("finish\n");
            break;
        }
        gettimeofday(&time_a, NULL);
        nRet = pollset_poll(ps, fds, CLIENT_NUM, -1);
        gettimeofday(&time_b, NULL);
        if (nRet < 0)
        {
            printf("poll failed %s\n", strerror(errno));
            break;
        }

        unsigned long long use_time0 = (time_b.tv_sec - time_a.tv_sec) * 1000000 + (time_b.tv_usec - time_a.tv_usec);
        total_time0 += use_time0;
        g_count0++;

        for(int i = 0; i< CLIENT_NUM; i++)
        {
            if(fds[i].fd > 0 && (fds[i].revents & (POLLIN | POLLERR)))
            {
                gettimeofday(&time_e, NULL);
                nRet = read(fds[i].fd, buff[fds[i].fd]+readlen[fds[i].fd], g_len-readlen[fds[i].fd]);
                gettimeofday(&time_f, NULL);
                if (nRet == 0)
                {
                    printf("%d fd %d close\n", i, fds[i].fd);
                    struct poll_ctl  delset;
                    delset.cmd = PS_DELETE;
                    delset.fd = fds[i].fd;
                    nRet = pollset_ctl(ps, &delset, 1);
                    if(nRet < 0)
                    {
                        printf("pollset_ctl failed %s\n",strerror(errno));
                        return -1;
                    }
                    fds[i].fd = -1;
                    conn -- ;
                    break;
                }
                if (nRet < 0)
                {
                    printf("%d fd %d err %s \n", i, fds[i].fd,strerror(errno));
                    fds[i].fd = -1;
                    conn -- ;
                    break;
                }

                unsigned long long use_time1 = (time_f.tv_sec - time_e.tv_sec) * 1000000 + (time_f.tv_usec - time_e.tv_usec);
                total_time1 += use_time1;
                g_count1++;

                if (nRet != g_len-readlen[fds[i].fd])//没读完
                {
                    readlen[fds[i].fd] += nRet;
                }
                else if (nRet == g_len-readlen[fds[i].fd])//读完
                {
                    if(g_verify == 1 && buff[fds[i].fd][0] != 'a')
                    {
                        printf("format error %s\n", buff[fds[i].fd]);
                        return -1;
                    }
                    readlen[fds[i].fd] = 0;
                    g_count2++;
                    memcpy(rbuff, buff[fds[i].fd], sizeof(buff[fds[i].fd]));
                    memset(buff[fds[i].fd], 0, sizeof(buff[fds[i].fd]));
                }

            }
        }

    }
    gettimeofday(&time_d, NULL);


    unsigned long long use_time2 = (time_d.tv_sec - time_c.tv_sec) * 1000000 + (time_d.tv_usec - time_c.tv_usec);
    total_time2 += use_time2;

    nRet = pollset_destroy(ps);
    if(nRet < 0)
    {
        printf("pollset_destroy failed %s\n",strerror(errno));
        return -1;
    }
#endif
    return 0;
}