--- libaitio/src/sock.c 2013/11/22 09:24:58 1.4.4.9 +++ libaitio/src/sock.c 2013/11/22 09:59:51 1.4.4.10 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: sock.c,v 1.4.4.9 2013/11/22 09:24:58 misho Exp $ +* $Id: sock.c,v 1.4.4.10 2013/11/22 09:59:51 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -157,7 +157,7 @@ io_txPty(sched_task_t *task) static void * io_rxNet(sched_task_t *task) { - int rlen; + int rlen, stat; sock_cli_t *cli = TASK_ARG(task); sock_t *s = (sock_t*) cli->cli_parent; sockaddr_t sa; @@ -172,9 +172,16 @@ io_rxNet(sched_task_t *task) if (e_addrcmp(&cli->cli_addr, &sa, 42)) goto end; } - if (rlen < 1) + if (rlen < 1) { + if (!rlen) { + kill((pid_t) cli->cli_func, SIGTERM); + while (waitpid((pid_t) cli->cli_func, &stat, WNOHANG) > 0) { + usleep(1000); + kill((pid_t) cli->cli_func, SIGTERM); + } + } schedEvent(TASK_ROOT(task), io_closeClient, cli, 0, NULL, cli->cli_fd); - else + } else schedWrite(TASK_ROOT(task), io_txPty, cli, cli->cli_pty, AIT_GET_BUF(&cli->cli_buf[0]), rlen); end: @@ -185,13 +192,20 @@ end: static void * io_rxPty(sched_task_t *task) { - int rlen; + int rlen, stat; sock_cli_t *cli = TASK_ARG(task); rlen = read(TASK_FD(task), AIT_GET_BUF(&cli->cli_buf[1]), AIT_LEN(&cli->cli_buf[1])); - if (rlen < 1) + if (rlen < 1) { + if (!rlen) { + kill((pid_t) cli->cli_func, SIGTERM); + while (waitpid((pid_t) cli->cli_func, &stat, WNOHANG) > 0) { + usleep(1000); + kill((pid_t) cli->cli_func, SIGTERM); + } + } schedEvent(TASK_ROOT(task), io_closeClient, cli, 0, NULL, cli->cli_fd); - else + } else schedWrite(TASK_ROOT(task), io_txNet, cli, cli->cli_fd, AIT_GET_BUF(&cli->cli_buf[1]), rlen); @@ -259,6 +273,8 @@ io_bridgeClient(sched_task_t *task) execv(*argv, argv); break; default: + cli->cli_func = (sched_task_func_t) pid; + schedRead(TASK_ROOT(task), io_rxPty, cli, cli->cli_pty, TASK_ARG(task), 0); schedRead(TASK_ROOT(task), io_rxNet, cli, cli->cli_fd,