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
|
2017-06-13 11:49:50 +00:00
|
|
|
machine_close(machine_io_t *obj)
|
2017-04-11 13:48:40 +00:00
|
|
|
{
|
2017-06-13 11:49:50 +00:00
|
|
|
mm_io_t *io = mm_cast(mm_io_t*, obj);
|
2017-04-11 13:48:40 +00:00
|
|
|
if (io->fd == -1) {
|
2017-05-30 14:00:16 +00:00
|
|
|
mm_errno_set(EBADF);
|
2017-04-11 13:48:40 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2017-05-26 10:48:52 +00:00
|
|
|
if (io->attached)
|
2017-06-13 11:49:50 +00:00
|
|
|
machine_io_detach(obj);
|
2017-04-12 12:33:34 +00:00
|
|
|
int rc;
|
|
|
|
rc = close(io->fd);
|
|
|
|
if (rc == -1)
|
2017-05-30 14:00:16 +00:00
|
|
|
mm_errno_set(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;
|
|
|
|
}
|