mirror of https://github.com/yandex/odyssey.git
machinarium: do optimistic io call before polling
This commit is contained in:
parent
771f8e3141
commit
259fc79315
|
@ -69,6 +69,7 @@ mm_accept(mm_io_t *io, int backlog, machine_io_t *client, uint64_t time_ms)
|
|||
mm_io_set_errno(io, errno);
|
||||
return -1;
|
||||
}
|
||||
io->accept_listen = 1;
|
||||
}
|
||||
|
||||
/* subscribe for accept event */
|
||||
|
|
|
@ -44,8 +44,7 @@ mm_read_cb(mm_fd_t *handle)
|
|||
if (errno == EINTR)
|
||||
continue;
|
||||
io->read_status = errno;
|
||||
mm_scheduler_wakeup(io->read_fiber);
|
||||
return 0;
|
||||
goto wakeup;
|
||||
}
|
||||
io->read_pos += rc;
|
||||
left = io->read_size - io->read_pos;
|
||||
|
@ -54,12 +53,13 @@ mm_read_cb(mm_fd_t *handle)
|
|||
/* eof */
|
||||
io->read_eof = 1;
|
||||
io->read_status = 0;
|
||||
mm_scheduler_wakeup(io->read_fiber);
|
||||
return 0;
|
||||
goto wakeup;
|
||||
}
|
||||
}
|
||||
io->read_status = 0;
|
||||
mm_scheduler_wakeup(io->read_fiber);
|
||||
wakeup:
|
||||
if (io->read_fiber)
|
||||
mm_scheduler_wakeup(io->read_fiber);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -89,6 +89,16 @@ mm_read(mm_io_t *io, char *buf, int size, uint64_t time_ms)
|
|||
io->read_pos = 0;
|
||||
io->read_buf = buf;
|
||||
|
||||
io->handle.on_read = mm_read_cb;
|
||||
io->handle.on_read_arg = io;
|
||||
mm_read_cb(&io->handle);
|
||||
if (io->read_status != 0) {
|
||||
mm_io_set_errno(io, io->write_status);
|
||||
return -1;
|
||||
}
|
||||
if (io->read_pos == io->read_size)
|
||||
return 0;
|
||||
|
||||
/* subscribe for read event */
|
||||
int rc;
|
||||
rc = mm_loop_read(&machine->loop, &io->handle, mm_read_cb, io, 1);
|
||||
|
|
|
@ -42,15 +42,16 @@ mm_write_cb(mm_fd_t *handle)
|
|||
if (errno == EINTR)
|
||||
continue;
|
||||
io->write_status = errno;
|
||||
mm_scheduler_wakeup(io->write_fiber);
|
||||
return 0;
|
||||
goto wakeup;
|
||||
}
|
||||
io->write_pos += rc;
|
||||
left = io->write_size - io->write_pos;
|
||||
assert(left >= 0);
|
||||
}
|
||||
io->write_status = 0;
|
||||
mm_scheduler_wakeup(io->write_fiber);
|
||||
wakeup:
|
||||
if (io->write_fiber)
|
||||
mm_scheduler_wakeup(io->write_fiber);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -81,6 +82,16 @@ mm_write(mm_io_t *io, char *buf, int size, uint64_t time_ms)
|
|||
io->write_size = size;
|
||||
io->write_pos = 0;
|
||||
|
||||
io->handle.on_write = mm_write_cb;
|
||||
io->handle.on_write_arg = io;
|
||||
mm_write_cb(&io->handle);
|
||||
if (io->write_status != 0) {
|
||||
mm_io_set_errno(io, io->write_status);
|
||||
return -1;
|
||||
}
|
||||
if (io->write_pos == io->write_size)
|
||||
return 0;
|
||||
|
||||
/* subscribe for write event */
|
||||
int rc;
|
||||
rc = mm_loop_write(&machine->loop, &io->handle, mm_write_cb, io, 1);
|
||||
|
|
Loading…
Reference in New Issue