Exemple #1
0
int main(int argc, char** argv)
{
    int result;

    (void)argc;
    (void)argv;

    if (platform_init() != 0)
    {
        (void)printf("Could not initialize platform\r\n");
        result = -1;
    }
    else
    {
        size_t last_memory_used = 0;
        SOCKET_LISTENER_HANDLE socket_listener;

        gballoc_init();

        socket_listener = socketlistener_create(5671);
        if (socketlistener_start(socket_listener, on_socket_accepted, NULL) != 0)
        {
            (void)printf("Could not start socket listener\r\n");
            result = -1;
        }
        else
        {
            bool keep_running = true;
            while (keep_running)
            {
                size_t current_memory_used;
                size_t maximum_memory_used;
                socketlistener_dowork(socket_listener);

                current_memory_used = gballoc_getCurrentMemoryUsed();
                maximum_memory_used = gballoc_getMaximumMemoryUsed();

                if (current_memory_used != last_memory_used)
                {
                    (void)printf("Current memory usage:%lu (max:%lu)\r\n", (unsigned long)current_memory_used, (unsigned long)maximum_memory_used);
                    last_memory_used = current_memory_used;
                }

                if (sent_messages == msg_count)
                {
                    break;
                }

                if (connection != NULL)
                {
                    connection_dowork(connection);
                }
            }

            result = 0;
        }

        socketlistener_destroy(socket_listener);
        platform_deinit();

        (void)printf("Max memory usage:%lu\r\n", (unsigned long)gballoc_getCurrentMemoryUsed());
        (void)printf("Current memory usage:%lu\r\n", (unsigned long)gballoc_getMaximumMemoryUsed());

        gballoc_deinit();
    }

    return result;
}
Exemple #2
0
int main(int argc, char** argv)
{
	int result;

    (void)argc, argv;
	amqpalloc_set_memory_tracing_enabled(true);

	if (platform_init() != 0)
	{
		result = -1;
	}
	else
	{
		size_t last_memory_used = 0;

		SOCKET_LISTENER_HANDLE socket_listener = socketlistener_create(5672);
		if (socketlistener_start(socket_listener, on_socket_accepted, NULL) != 0)
		{
			result = -1;
		}
		else
		{
			while (true)
			{
				size_t current_memory_used;
				size_t maximum_memory_used;
				socketlistener_dowork(socket_listener);

				current_memory_used = amqpalloc_get_current_memory_used();
				maximum_memory_used = amqpalloc_get_maximum_memory_used();

				if (current_memory_used != last_memory_used)
				{
					printf("Current memory usage:%lu (max:%lu)\r\n", (unsigned long)current_memory_used, (unsigned long)maximum_memory_used);
					last_memory_used = current_memory_used;
				}

				if (sent_messages == msg_count)
				{
					break;
				}

				if (connection != NULL)
				{
					connection_dowork(connection);
				}
			}

			result = 0;
		}

		socketlistener_destroy(socket_listener);
		platform_deinit();

		printf("Max memory usage:%lu\r\n", (unsigned long)amqpalloc_get_maximum_memory_used());
		printf("Current memory usage:%lu\r\n", (unsigned long)amqpalloc_get_current_memory_used());
	}

#ifdef _CRTDBG_MAP_ALLOC
	_CrtDumpMemoryLeaks();
#endif

	return result;
}