Example #1
0
void print_thread(void *arg)
{
    int old = all_recved_packet_num;
    while(1)
    {
        old = all_recved_packet_num;
        ox_thread_sleep(1000);
        printf("recv %d packet /s\n", (all_recved_packet_num-old));
    }
}
Example #2
0
void
ox_connection_netpoll(struct connection_s* self, int64_t millisecond)
{
    if(millisecond < 0)
    {
        millisecond = 0;
    }

    /*  网络层调度函数:如果当前状态是未链接则尝试取出消息并链接服务器,否则处理来自逻辑层的消息队列    */
    if(self->status == connection_none)
    {
        ox_thread_sleep(millisecond);
        connection_proclist_handle(self);
    }
    else
    {
        int64_t current_time = ox_getnowtime();
        const int64_t end_time = current_time + millisecond;

        do
        {
            if(ox_fdset_poll(self->fdset, end_time-current_time) > 0)
            {
                if(ox_fdset_check(self->fdset, self->fd, ReadCheck))
                {
                    connection_read_handle(self);
                }

                if(self->fd != SOCKET_ERROR && ox_fdset_check(self->fdset, self->fd, WriteCheck))
                {
                    self->writable = true;
                    ox_fdset_del(self->fdset, self->fd, WriteCheck);
                }
            }

            if(self->writable)
            {
                connection_sendmsg_handle(self);
            }
            current_time = ox_getnowtime();
        }while(end_time > current_time);

        connection_proclist_handle(self);
    }
    
    ox_rwlist_flush(self->netmsg_list);
    connection_free_netmsglist(self);
}