Beispiel #1
0
static void test_queue_remove_one(void)
{
    queue_node_t *root = &(q[0]), *elem1 = &(q[1]), *elem2 = &(q[2]);
    queue_node_t *elem3 = &(q[3]);

    queue_add_head(root, elem1);
    queue_add_head(root, elem2);
    queue_add_head(root, elem3);
    queue_remove(root, elem2);

    TEST_ASSERT(root->next == elem3);
    TEST_ASSERT(root->next->next == elem1);
    TEST_ASSERT_NULL(root->next->next->next);
}
Beispiel #2
0
static void test_queue_add_head_two(void)
{
    queue_node_t *root = &(q[0]), *elem1 = &(q[1]), *elem2 = &(q[2]);

    elem1->data = 25303;
    elem2->data = 64960;

    queue_add_head(root, elem1);
    queue_add_head(root, elem2);

    TEST_ASSERT(root->next == elem2);
    TEST_ASSERT_EQUAL_INT(64960, root->next->data);

    TEST_ASSERT(root->next->next == elem1);
    TEST_ASSERT_EQUAL_INT(25303, root->next->next->data);

    TEST_ASSERT_NULL(root->next->next->next);
}
Beispiel #3
0
void runserver(int numthreads, unsigned short serverport) {
///////////////////////////////////////////////////////////////
	int i=0;
	for(;i<numthreads;i++){
		pthread_t thread;
		pthread_create(&thread,NULL, &worker_start, NULL); 
	}
    	printf("made %d threads\n", numthreads);
//////////////////////////////////////////////////////////////   
    int main_socket = prepare_server_socket(serverport);
    if (main_socket < 0) {
        exit(-1);
    }
    signal(SIGINT, signal_handler);

    struct sockaddr_in client_address;
    socklen_t addr_len;

    fprintf(stderr, "Server listening on port %d.  Going into request loop.\n", serverport);
    while (still_running) {
        struct pollfd pfd = {main_socket, POLLIN};
        int prv = poll(&pfd, 1, 10000);

        if (prv == 0) {
            continue;
        } else if (prv < 0) {
            PRINT_ERROR("poll");
            still_running = FALSE;
            continue;
        }
        
        addr_len = sizeof(client_address);
        memset(&client_address, 0, addr_len);

        int new_sock = accept(main_socket, (struct sockaddr *)&client_address, &addr_len);
        if (new_sock > 0) {
            
            time_t now = time(NULL);
            char* ip = inet_ntoa(client_address.sin_addr);
            int port = ntohs(client_address.sin_port);
            fprintf(stderr, "Got connection from %s:%d at %s\n", ip, port, ctime(&now));
/////////////////////////////////////////////////////////////////////
           queue_add_head(new_sock, ip, port);
           printf("added to queue\n");
           pthread_cond_signal(&cond);
/////////////////////////////////////////////////////////////////////
        }
    }
    pthread_cond_broadcast(&cond);
    fprintf(stderr, "Server shutting down.\n");
        
    close(main_socket);
}
Beispiel #4
0
static void test_queue_add_head_one(void)
{
    queue_node_t *root = &(q[0]), *elem = &(q[1]);

    elem->data = 44011;

    queue_add_head(root, elem);

    TEST_ASSERT(root->next == elem);
    TEST_ASSERT_EQUAL_INT(44011, root->next->data);

    TEST_ASSERT_NULL(root->next->next);
}
Beispiel #5
0
static void test_queue_remove_head_one(void)
{
    queue_node_t *root = &(q[0]), *elem = &(q[1]), *res;

    elem->data = 62801;

    queue_add_head(root, elem);

    res = queue_remove_head(root);

    TEST_ASSERT(res == elem);
    TEST_ASSERT_EQUAL_INT(62801, res->data);

    res = queue_remove_head(root);

    TEST_ASSERT_NULL(res);
}