--- libaitio/src/sock.c 2013/11/21 15:13:52 1.4.4.4 +++ libaitio/src/sock.c 2013/11/21 18:59:50 1.4.4.6 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: sock.c,v 1.4.4.4 2013/11/21 15:13:52 misho Exp $ +* $Id: sock.c,v 1.4.4.6 2013/11/21 18:59:50 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -61,7 +61,8 @@ io_closeClient(sched_task_t *task) shutdown(sock, SHUT_RDWR); close(sock); } - AIT_FREE_VAL(&cli->cli_buf); + AIT_FREE_VAL(&cli->cli_buf[1]); + AIT_FREE_VAL(&cli->cli_buf[0]); e_free(cli); taskExit(task, NULL); @@ -108,7 +109,8 @@ io_acceptClient(sched_task_t *task) cli->cli_fd = c; cli->cli_func = TASK_DATA(task); memcpy(&cli->cli_addr, &sa, sizeof cli->cli_addr); - AIT_SET_BUFSIZ(&cli->cli_buf, 0, AIT_LEN(&s->sock_buf)); + 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)); schedRead(TASK_ROOT(task), cli->cli_func, cli, cli->cli_fd, TASK_ARG(task), 0); ioUpdTimerSocket(cli); @@ -229,7 +231,8 @@ ioCloseSocket(sock_t ** __restrict s) shutdown(cli->cli_fd, SHUT_RDWR); close(cli->cli_fd); } - AIT_FREE_VAL(&cli->cli_buf); + AIT_FREE_VAL(&cli->cli_buf[1]); + AIT_FREE_VAL(&cli->cli_buf[0]); e_free(cli); } pthread_mutex_unlock(&(*s)->sock_mtx); @@ -320,6 +323,25 @@ ioUpdTimerSocket(sock_cli_t * __restrict c) } /* + * ioCloseClient() - Close client socket + * + * @c = Client socket + * return: 0 ok or !=0 error + */ +int +ioCloseClient(sock_cli_t * __restrict c) +{ + sock_t *s; + + if (!c) + return -1; + else + s = c->cli_parent; + + return !schedEvent(s->sock_root, io_closeClient, c, 0, NULL, c->cli_fd); +} + +/* * ioLoopSocket() - Start socket scheduler * * @s = Socket @@ -329,25 +351,26 @@ ioUpdTimerSocket(sock_cli_t * __restrict c) int ioLoopSocket(sock_t * __restrict s, sched_task_func_t rcb) { + if (!s || !rcb || s->sock_kill) + return -1; + schedRead(s->sock_root, io_acceptClient, s, s->sock_fd, rcb, 0); return schedRun(s->sock_root, &s->sock_kill); } /* - * ioCloseClient() - Close client socket + * ioBridgeProg2Socket() - Start socket scheduler and bridge program to socket * - * @c = Client socket + * @s = Socket + * @prgname = Program name * return: 0 ok or !=0 error */ int -ioCloseClient(sock_cli_t * __restrict c) +ioBridgeProg2Socket(sock_t * __restrict s, const char *prgname) { - sock_t *s; - - if (!c) + if (!s || !prgname || s->sock_kill) return -1; - else - s = c->cli_parent; - return !schedEvent(s->sock_root, io_closeClient, c, 0, NULL, c->cli_fd); + schedRead(s->sock_root, io_bridgeProg, s, s->sock_fd, prgname, 0); + return schedRun(s->sock_root, &s->sock_kill); }