コード例 #1
0
ファイル: stk_async_queue.c プロジェクト: flying-pig/libstk
void *stk_async_queue_pop(stk_async_queue_t *queue)
{
    void *data;
    __queue_data_t *elt;

    pthread_mutex_lock(&queue->mutex);
    if (stk_list_empty(&queue->list)) {
#ifdef STK_DEBUG
        stk_log_debug("if asynchronous queue has no element, return NULL");
        pthread_mutex_unlock(&queue->mutex);
        return NULL;
#else
        stk_log_debug("the asynchronous queue has no element, wait for data");
        pthread_cond_wait(&queue->cond, &queue->mutex);
#endif
    }
    elt = stk_list_pop_entry(&queue->list, __queue_data_t, list);
    data = elt->data;
    stk_pool_cleanup_del(queue->pool, elt);
    pthread_mutex_unlock(&queue->mutex);

    return data;
} 
コード例 #2
0
ファイル: stk_socket.c プロジェクト: workforme/demoproxy
stk_socket_t stk_accept(stk_socket_t listening_fd,
                        struct sockaddr_in *client_addr)
{
    /* TODO: for use STK_AGIN when accept errno is EAGAIN */
    stk_socket_t client_fd;
    socklen_t client_fd_len = sizeof(struct sockaddr_in);
    if ((client_fd = accept(listening_fd, (struct sockaddr *)client_addr,
                            &client_fd_len))
         < 0)
    {
        stk_log_error("listening_fd accept failed! errno:[%d]", errno);
        if (stk_socket_is_nonblocking(listening_fd)) {
             if (errno == EAGAIN) {
                 stk_log_debug("accept() not ready! errno:[%d]", errno);
                 return STK_AGAIN;
             }
        }
        return STK_ERR;
    }
    stk_log_info("accept a client[%d] connect!", client_fd);
    return client_fd;
}