mirror of https://github.com/yandex/odyssey.git
66 lines
1.2 KiB
C
66 lines
1.2 KiB
C
|
|
/*
|
|
* machinarium.
|
|
*
|
|
* Cooperative multitasking engine.
|
|
*/
|
|
|
|
#include <machinarium.h>
|
|
#include <machinarium_test.h>
|
|
|
|
static void
|
|
test_gai0(void *arg)
|
|
{
|
|
machine_t machine = arg;
|
|
machine_io_t io = machine_create_io(machine);
|
|
test(io != NULL);
|
|
struct addrinfo *res = NULL;
|
|
int rc = machine_getaddrinfo(io, "localhost", "http", NULL, &res, INT_MAX);
|
|
if (rc < 0) {
|
|
printf("failed to resolve address\n");
|
|
} else {
|
|
test(res != NULL);
|
|
if (res)
|
|
freeaddrinfo(res);
|
|
}
|
|
machine_free_io(io);
|
|
}
|
|
|
|
static void
|
|
test_gai1(void *arg)
|
|
{
|
|
machine_t machine = arg;
|
|
machine_io_t io = machine_create_io(machine);
|
|
test(io != NULL);
|
|
struct addrinfo *res = NULL;
|
|
int rc = machine_getaddrinfo(io, "localhost", "http", NULL, &res, INT_MAX);
|
|
if (rc < 0) {
|
|
printf("failed to resolve address\n");
|
|
} else {
|
|
test(res != NULL);
|
|
if (res)
|
|
freeaddrinfo(res);
|
|
}
|
|
machine_free_io(io);
|
|
machine_stop(machine);
|
|
}
|
|
|
|
void
|
|
test_getaddrinfo1(void)
|
|
{
|
|
machine_t machine = machine_create();
|
|
test(machine != NULL);
|
|
|
|
int rc;
|
|
rc = machine_create_fiber(machine, test_gai0, machine);
|
|
test(rc != -1);
|
|
|
|
rc = machine_create_fiber(machine, test_gai1, machine);
|
|
test(rc != -1);
|
|
|
|
machine_start(machine);
|
|
|
|
rc = machine_free(machine);
|
|
test(rc != -1);
|
|
}
|