X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fio%2Ftest%2Frun-45-eof.c;fp=ccan%2Fio%2Ftest%2Frun-45-eof.c;h=6a7f99218777f63a3f0b5760439068045b5b6997;hp=0000000000000000000000000000000000000000;hb=fedf515165bfafaf4fb98252ecda1abe050c8da5;hpb=b6e8d929d2c0c37afc840ac99e3e0f469e33e6c0 diff --git a/ccan/io/test/run-45-eof.c b/ccan/io/test/run-45-eof.c new file mode 100644 index 00000000..6a7f9921 --- /dev/null +++ b/ccan/io/test/run-45-eof.c @@ -0,0 +1,45 @@ +#include +/* Include the C files directly. */ +#include +#include +#include +#include +#include + +static size_t len; + +static void finished_read(struct io_conn *conn, int *expect) +{ + ok1(errno == *expect); +} + +static struct io_plan *init_conn_read(struct io_conn *conn, int *expect) +{ + io_set_finish(conn, finished_read, expect); + return io_read(conn, &expect, sizeof(expect), io_never, expect); +} + +static struct io_plan *init_conn_read_partial(struct io_conn *conn, int *expect) +{ + io_set_finish(conn, finished_read, expect); + return io_read_partial(conn, &expect, sizeof(expect), &len, + io_never, expect); +} + +int main(void) +{ + int fd, expect_errno = 0; + + /* This is how many tests you plan to run */ + plan_tests(2); + fd = open("/dev/null", O_RDONLY); + io_new_conn(NULL, fd, init_conn_read, &expect_errno); + + fd = open("/dev/null", O_RDONLY); + io_new_conn(NULL, fd, init_conn_read_partial, &expect_errno); + + io_loop(NULL, NULL); + + /* This exits depending on whether all tests passed */ + return exit_status(); +}