--- libaitio/src/sock.c 2013/12/12 23:36:31 1.11.2.5 +++ libaitio/src/sock.c 2013/12/18 12:40:21 1.13 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: sock.c,v 1.11.2.5 2013/12/12 23:36:31 misho Exp $ +* $Id: sock.c,v 1.13 2013/12/18 12:40:21 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -63,6 +63,9 @@ io_closeClient(sched_task_t *task) ioFreePTY(cli->cli_pty, cli->cli_name); if (s->sock_prog) { io_progDetach(s->sock_prog, cli->cli_pty); +#if 0 + io_progCloseAt(s->sock_prog, cli->cli_pty); +#endif cli->cli_pty ^= cli->cli_pty; io_progCheck(s->sock_prog, 42); } @@ -243,7 +246,7 @@ io_rxPty(sched_task_t *task) static void * io_bridgeClient(sched_task_t *task) { - int c, rlen; + int c, rlen, pty; pid_t pid; sockaddr_t sa; socklen_t salen = sizeof sa.ss; @@ -287,12 +290,14 @@ io_bridgeClient(sched_task_t *task) AIT_SET_BUFSIZ(&cli->cli_buf[0], 0, AIT_LEN(&s->sock_buf)); AIT_SET_BUFSIZ(&cli->cli_buf[1], 0, AIT_LEN(&s->sock_buf)); - switch ((pid = ioForkPTY(&cli->cli_pty, cli->cli_name, sizeof cli->cli_name, + switch ((pid = ioForkPTY(&pty, cli->cli_name, sizeof cli->cli_name, NULL, NULL, NULL))) { case -1: ELIBERR(io); break; case 0: + cli->cli_pty = pty; + array_Args(cli->cli_cmdline, 0, " \t", &args); argv = array_To(args); array_Destroy(&args); @@ -304,6 +309,7 @@ io_bridgeClient(sched_task_t *task) _exit(rlen); break; default: + cli->cli_pty = pty; cli->cli_pid = pid; schedRead(TASK_ROOT(task), io_rxPty, cli, cli->cli_pty, @@ -355,6 +361,8 @@ io_bridgeClient2Pool(sched_task_t *task) pthread_mutex_unlock(&s->sock_mtx); } + io_progCheck(s->sock_prog, 42); + cli->cli_parent = TASK_ARG(task); cli->cli_fd = c; cli->cli_pty = io_progAttach(s->sock_prog, 42); @@ -620,6 +628,18 @@ ioLoopSocket(sock_t * __restrict s, sched_task_func_t return schedRun(s->sock_root, &s->sock_kill); } +static void * +io_progPurge(sched_task_t *task) +{ + sock_t *s = (sock_t*) TASK_ARG(task); + + io_progVacuum(s->sock_prog, 0); + + schedTimer(TASK_ROOT(task), TASK_FUNC(task), TASK_ARG(task), + s->sock_timeout, TASK_DATA(task), TASK_DATLEN(task)); + taskExit(task, NULL); +} + /* * ioBridgeProg2Socket() - Start socket scheduler and bridge program to socket * @@ -633,8 +653,13 @@ ioBridgeProg2Socket(sock_t * __restrict s, const char if (!s || !prgname || s->sock_kill) return -1; - schedRead(s->sock_root, s->sock_prog ? io_bridgeClient2Pool : io_bridgeClient, - s, s->sock_fd, (void*) prgname, 0); + if (s->sock_prog) { + schedRead(s->sock_root, io_bridgeClient2Pool, + s, s->sock_fd, (void*) prgname, 0); + schedTimer(s->sock_root, io_progPurge, s, s->sock_timeout, NULL, 0); + } else + schedRead(s->sock_root, io_bridgeClient, + s, s->sock_fd, (void*) prgname, 0); return schedRun(s->sock_root, &s->sock_kill); }