Beispiel #1
0
int  loop_init()
{
    WSADATA data;
    DWORD bytes = 0;
    int error;
    SOCKET sockfd = INVALID_SOCKET;
    GUID guid_connectex = WSAID_CONNECTEX;

    CHECK(WSAStartup(MAKEWORD(2, 2), &data) == 0);
    sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
    if(sockfd == INVALID_SOCKET)
    {
        fprintf(stderr, ("WSAIoctl() failed, %s."), LAST_ERROR_MSG);
        return 0;
    }

    /* obtain ConnectEx function pointer */
    error = WSAIoctl(sockfd, SIO_GET_EXTENSION_FUNCTION_POINTER, &guid_connectex,
        sizeof(guid_connectex), &default_loop.fnConnectEx, sizeof(default_loop.fnConnectEx),
        &bytes, 0, 0);
    closesocket(sockfd);
    if (error == SOCKET_ERROR)
    {
        fprintf(stderr, ("WSAIoctl() failed, %s."), LAST_ERROR_MSG);
        return 0;
    }

    /* connection tree container */
    default_loop.total_connection = avl_create_tree();
    if (default_loop.total_connection == NULL)
    {
        fprintf(stderr, ("avl_create_tree() failed."));
        return 0;
    }

    /* per-handle data */
    default_loop.connection_data = avl_create_tree();
    if (default_loop.connection_data == NULL)
    {
        fprintf(stderr, ("avl_create_tree() failed."));
        avl_destroy_tree(default_loop.connection_data);
        return 0;
    }

    /* create I/O completion port handle */
    default_loop.completion_port = CreateCompletionPort(0);
    if (default_loop.completion_port == NULL)
    {
        fprintf(stderr, ("CreateCompletionPort() failed, %s."), LAST_ERROR_MSG);
        avl_destroy_tree(default_loop.total_connection);
        avl_destroy_tree(default_loop.connection_data);
        return 0;
    }

    return 1;
}
Beispiel #2
0
/*
 * This function destroys tree rooted at root
 */
void avl_destroy_tree(avl_st *root)
{

	if (root == NULL)
	{
		return;
	}

	avl_destroy_tree(root->bst_left);
	avl_destroy_tree(root->bst_right);
	avl_dealloc_node(&root);

}
Beispiel #3
0
/**
 * Process file by name and call syntax analyse
 *
 * @param file_name File name to process
 */
void process_file(char *file_name)
{
    assert(file_name != NULL);

    FILE *f;

    f = fopen(file_name, "r");
    if (f) {
	Tnode_ptr symtab;
	avl_init(&symtab);
	syntax(f, &symtab);
	fclose(f);
	avl_destroy_tree(&symtab);
    } else {
	error(ERROR_FOPEN);
    }
}
void comp_routine_release()
{
    int i;
    int count = avl_size(g_connections_map);
    SOCKET* array = (SOCKET*)malloc(count * sizeof(int));
    avl_serialize(g_connections_map, (avl_key_t*)array, count);
    for (i = 0; i < count; ++i)
    {
        socket_data_t* data = (socket_data_t*)avl_find(g_connections_map, array[i]);
        if (data)
        {
            free_data(data);
            avl_delete(g_connections_map, array[i]);
        }
    }
    free(array);
    avl_destroy_tree(g_connections_map);
    WSACleanup();
}
Beispiel #5
0
void loop_destroy()
{
    CloseHandle(default_loop.completion_port);
    avl_destroy_tree(default_loop.connection_data);
    avl_destroy_tree(default_loop.total_connection);
}