Initial import of libucore
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include "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;
|
||||
}
|
||||
Reference in New Issue
Block a user