Annotation of libaitio/example/test_exec.c, revision 1.2
1.2 ! misho 1: #include <stdio.h>
! 2: #include <unistd.h>
! 3: #include <string.h>
! 4: #include <errno.h>
! 5: #include <aitio.h>
! 6: #include <sys/wait.h>
! 7:
! 8:
! 9: int
! 10: main(int argc, char **argv)
! 11: {
! 12: prog_t *p;
! 13: int f;
! 14: int ret = 0;
! 15: char str[BUFSIZ];
! 16:
! 17: if (argc < 2)
! 18: return 1;
! 19:
! 20: p = io_progInit(argv[1], 3, 10);
! 21: if (!p) {
! 22: ELIBERR(io);
! 23: return 2;
! 24: } else if ((ret = io_progCheck(p, 0))) {
! 25: printf("0.exited procs=%d\n", ret);
! 26: goto end;
! 27: } else {
! 28: printf("wait for keystroke %p ", p);
! 29: getchar();
! 30: }
! 31:
! 32: ret = io_progCheck(p, 0);
! 33: if (ret) {
! 34: printf("1.exited procs=%d\n", ret);
! 35: goto end;
! 36: }
! 37:
! 38: printf("last=%d\n", array_Last(p->prog_fds));
! 39:
! 40: ret = io_progGrow(p, 8);
! 41: printf("+grow_progs=%d\n", ret);
! 42:
! 43: printf("wait for keystroke %p ", p);
! 44: getchar();
! 45:
! 46: ret = io_progVacuum(p, 5);
! 47: printf("+vacuum_progs=%d\n", ret);
! 48:
! 49: printf("wait for keystroke %p ", p);
! 50: getchar();
! 51:
! 52: again:
! 53: f = io_progAttach(p, 0);
! 54: printf("f=%d\n", f);
! 55: write(f, "v\n", 1);
! 56: memset(str, 0, sizeof str);
! 57: while (read(f, str, sizeof str) > 0) {
! 58: printf(">>> %s", str);
! 59: memset(str, 0, sizeof str);
! 60: read(0, str, sizeof str);
! 61: if (*str == '.')
! 62: break;
! 63: write(f, str, strlen(str));
! 64: }
! 65: io_progDetach(p, f);
! 66:
! 67: printf("(r) wait for keystroke %p ", p);
! 68: if (getchar() == 'a')
! 69: goto again;
! 70: end:
! 71: io_progDestroy(&p);
! 72: return ret;
! 73: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>