34 lines
674 B
C
34 lines
674 B
C
#include <stdio.h>
|
|
#include <unistd.h>
|
|
#include "ucore/iomux.h"
|
|
|
|
extern struct IOMuxFD s_fd;
|
|
|
|
void stdin_read_cb(struct IOMux *mux, struct IOMuxFD *fd, unsigned int event)
|
|
{
|
|
char buf[64];
|
|
ssize_t len = read(fd->fd, buf, sizeof buf);
|
|
printf("Read %d bytes\n", len);
|
|
iomux_unregister_fd(mux, fd);
|
|
if (len > 0) {
|
|
s_fd.what = MUX_EV_READ;
|
|
iomux_register_fd(mux, &s_fd);
|
|
}
|
|
}
|
|
|
|
struct IOMuxFD s_fd = {
|
|
.fd = 0,
|
|
.what = MUX_EV_READ,
|
|
.callback = stdin_read_cb,
|
|
|
|
};
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
struct IOMux *mux = iomux_create(IOMUX_TYPE_DEFAULT);
|
|
iomux_register_fd(mux, &s_fd);
|
|
iomux_run(mux);
|
|
|
|
return 0;
|
|
}
|