mirror of https://github.com/yandex/odyssey.git
flint: add connect cancel test
This commit is contained in:
parent
9c1085cf83
commit
379268d0a2
|
@ -50,12 +50,9 @@ mm_io_timer_start(uv_timer_t *timer, uv_timer_cb callback, uint64_t time_ms)
|
|||
}
|
||||
|
||||
static inline void
|
||||
mm_io_timer_stop(uv_timer_t *timer)
|
||||
mm_io_timer_stop(mmio *io, uv_timer_t *timer)
|
||||
{
|
||||
uv_timer_stop(timer);
|
||||
uv_handle_t *handle = (uv_handle_t*)timer;
|
||||
if (! uv_is_closing(handle))
|
||||
uv_close(handle, NULL);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -15,9 +15,7 @@ mm_io_connect_timeout_cb(uv_timer_t *handle)
|
|||
io->connect_timeout = 1;
|
||||
/* cancel connection request,
|
||||
* connect callback will be called anyway */
|
||||
uv_handle_t *to_cancel;
|
||||
to_cancel = (uv_handle_t*)&io->handle;
|
||||
uv_close(to_cancel, NULL);
|
||||
mm_io_close_handle(io, (uv_handle_t*)&io->handle);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -28,7 +26,7 @@ mm_io_connect_cb(uv_connect_t *handle, int status)
|
|||
goto wakeup;
|
||||
if (io->connect_timeout)
|
||||
goto wakeup;
|
||||
mm_io_timer_stop(&io->connect_timer);
|
||||
mm_io_timer_stop(io, &io->connect_timer);
|
||||
wakeup:
|
||||
io->connect_status = status;
|
||||
mm_wakeup(io->f, io->connect_fiber);
|
||||
|
@ -39,10 +37,8 @@ mm_io_connect_cancel_cb(mmfiber *fiber, void *arg)
|
|||
{
|
||||
mmio *io = arg;
|
||||
io->write_timeout = 0;
|
||||
mm_io_timer_stop(&io->connect_timer);
|
||||
uv_handle_t *to_cancel;
|
||||
to_cancel = (uv_handle_t*)&io->handle;
|
||||
uv_close(to_cancel, NULL);
|
||||
mm_io_timer_stop(io, &io->connect_timer);
|
||||
mm_io_close_handle(io, (uv_handle_t*)&io->handle);
|
||||
}
|
||||
|
||||
MM_API int
|
||||
|
|
|
@ -10,7 +10,8 @@ TESTS = test_new \
|
|||
test_wait \
|
||||
test_cancel_sleep \
|
||||
test_cancel_sleep_2 \
|
||||
test_io_new
|
||||
test_io_new \
|
||||
test_io_connect
|
||||
all: validate clean $(TESTS)
|
||||
test_new:
|
||||
$(CC) $(CFLAGS) test_new.c $(LFLAGS) -o test_new
|
||||
|
@ -26,6 +27,8 @@ test_cancel_sleep_2:
|
|||
$(CC) $(CFLAGS) test_cancel_sleep_2.c $(LFLAGS) -o test_cancel_sleep_2
|
||||
test_io_new:
|
||||
$(CC) $(CFLAGS) test_io_new.c $(LFLAGS) -o test_io_new
|
||||
test_io_connect:
|
||||
$(CC) $(CFLAGS) test_io_connect.c $(LFLAGS) -o test_io_connect
|
||||
validate:
|
||||
@if [ ! -f $(LFLAGS_LIB) ]; then \
|
||||
echo ""; \
|
||||
|
|
Binary file not shown.
|
@ -0,0 +1,52 @@
|
|||
|
||||
/*
|
||||
* machinarium.
|
||||
*
|
||||
* Cooperative multitasking engine.
|
||||
*/
|
||||
|
||||
#include <machinarium.h>
|
||||
#include <assert.h>
|
||||
|
||||
static void
|
||||
test_connect(void *arg)
|
||||
{
|
||||
mm_t env = arg;
|
||||
printf("child started\n");
|
||||
mmio_t client = mm_io_new(env);
|
||||
int rc;
|
||||
rc = mm_connect(client, "8.8.8.16", 1324, 0);
|
||||
printf("child resumed\n");
|
||||
assert(rc < 0);
|
||||
mm_close(client);
|
||||
if (mm_is_cancel(env))
|
||||
printf("child marked as cancel\n");
|
||||
printf("child end\n");
|
||||
}
|
||||
|
||||
static void
|
||||
test_waiter(void *arg)
|
||||
{
|
||||
mm_t env = arg;
|
||||
|
||||
printf("waiter started\n");
|
||||
|
||||
int id = mm_create(env, test_connect, env);
|
||||
mm_sleep(env, 0);
|
||||
mm_cancel(env, id);
|
||||
mm_wait(env, id);
|
||||
|
||||
printf("waiter 1 ended \n");
|
||||
mm_stop(env);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
mm_t env = mm_new();
|
||||
mm_create(env, test_waiter, env);
|
||||
mm_start(env);
|
||||
printf("shutting down\n");
|
||||
mm_free(env);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue