2017-05-15 14:21:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* machinarium.
|
|
|
|
*
|
|
|
|
* Cooperative multitasking engine.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <machinarium.h>
|
|
|
|
#include <machinarium_test.h>
|
|
|
|
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
|
|
|
static void
|
2017-05-24 10:11:03 +00:00
|
|
|
test_connect_coroutine(void *arg)
|
2017-05-15 14:21:34 +00:00
|
|
|
{
|
2017-05-18 10:20:40 +00:00
|
|
|
machine_io_t client = machine_io_create();
|
2017-05-15 14:21:34 +00:00
|
|
|
test(client != NULL);
|
|
|
|
|
|
|
|
struct sockaddr_in sa;
|
|
|
|
sa.sin_family = AF_INET;
|
|
|
|
sa.sin_addr.s_addr = inet_addr("8.8.8.8");
|
|
|
|
sa.sin_port = htons(1234);
|
|
|
|
int rc;
|
|
|
|
rc = machine_connect(client, (struct sockaddr *)&sa, INT_MAX);
|
|
|
|
test(rc == -1);
|
2017-05-17 14:23:21 +00:00
|
|
|
test(machine_cancelled());
|
2017-05-15 14:21:34 +00:00
|
|
|
|
2017-05-18 10:20:40 +00:00
|
|
|
machine_io_free(client);
|
2017-05-15 14:21:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_waiter(void *arg)
|
|
|
|
{
|
2017-05-24 10:11:03 +00:00
|
|
|
int id = machine_coroutine_create(test_connect_coroutine, NULL);
|
2017-05-15 14:21:34 +00:00
|
|
|
test(id != -1);
|
|
|
|
|
|
|
|
int rc;
|
2017-05-17 14:23:21 +00:00
|
|
|
rc = machine_cancel(id);
|
2017-05-15 14:21:34 +00:00
|
|
|
test(rc == 0);
|
|
|
|
|
2017-05-17 14:23:21 +00:00
|
|
|
machine_sleep(0);
|
2017-05-15 14:21:34 +00:00
|
|
|
|
2017-05-18 10:20:40 +00:00
|
|
|
rc = machine_join(id);
|
2017-05-15 14:21:34 +00:00
|
|
|
test(rc == -1);
|
|
|
|
|
2017-05-17 14:23:21 +00:00
|
|
|
machine_stop();
|
2017-05-15 14:21:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
test_connect_cancel1(void)
|
|
|
|
{
|
2017-05-17 14:23:21 +00:00
|
|
|
machinarium_init();
|
|
|
|
|
|
|
|
int id;
|
2017-05-17 14:35:55 +00:00
|
|
|
id = machine_create("test", test_waiter, NULL);
|
2017-05-17 14:23:21 +00:00
|
|
|
test(id != -1);
|
2017-05-15 14:21:34 +00:00
|
|
|
|
|
|
|
int rc;
|
2017-05-18 10:20:40 +00:00
|
|
|
rc = machine_wait(id);
|
2017-05-15 14:21:34 +00:00
|
|
|
test(rc != -1);
|
|
|
|
|
2017-05-17 14:23:21 +00:00
|
|
|
machinarium_free();
|
2017-05-15 14:21:34 +00:00
|
|
|
}
|