2017-04-11 13:48:40 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* machinarium.
|
|
|
|
*
|
|
|
|
* cooperative multitasking engine.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <machinarium.h>
|
2017-05-17 14:20:04 +00:00
|
|
|
#include <machinarium_private.h>
|
2017-04-11 13:48:40 +00:00
|
|
|
|
|
|
|
MACHINE_API int
|
|
|
|
machine_close(machine_io_t obj)
|
|
|
|
{
|
|
|
|
mm_io_t *io = obj;
|
2017-05-18 10:31:25 +00:00
|
|
|
mm_machine_t *machine = mm_self;
|
2017-04-11 13:48:40 +00:00
|
|
|
if (io->fd == -1) {
|
|
|
|
mm_io_set_errno(io, EBADF);
|
|
|
|
return -1;
|
|
|
|
}
|
2017-04-12 12:33:34 +00:00
|
|
|
int rc;
|
|
|
|
rc = mm_loop_delete(&machine->loop, &io->handle);
|
|
|
|
if (rc == -1)
|
|
|
|
mm_io_set_errno(io, errno);
|
|
|
|
rc = close(io->fd);
|
|
|
|
if (rc == -1)
|
|
|
|
mm_io_set_errno(io, errno);
|
2017-04-11 13:48:40 +00:00
|
|
|
io->connected = 0;
|
|
|
|
io->fd = -1;
|
|
|
|
io->handle.fd = -1;
|
2017-04-12 12:19:30 +00:00
|
|
|
io->handle.on_read = NULL;
|
|
|
|
io->handle.on_write = NULL;
|
2017-04-11 13:48:40 +00:00
|
|
|
return 0;
|
|
|
|
}
|