--- libaitio/src/sock.c 2013/11/21 18:26:40 1.4.4.5 +++ libaitio/src/sock.c 2013/11/22 08:23:51 1.4.4.7 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: sock.c,v 1.4.4.5 2013/11/21 18:26:40 misho Exp $ +* $Id: sock.c,v 1.4.4.7 2013/11/22 08:23:51 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -57,6 +57,10 @@ io_closeClient(sched_task_t *task) TAILQ_REMOVE(&s->sock_cli, cli, cli_node); pthread_mutex_unlock(&s->sock_mtx); + schedCancelby(s->sock_root, taskTIMER, CRITERIA_DATLEN, + (void*) cli->cli_fd, NULL); + schedCancelby(s->sock_root, taskMAX, CRITERIA_ARG, cli, NULL); + if (s->sock_type == SOCK_STREAM) { shutdown(sock, SHUT_RDWR); close(sock); @@ -119,7 +123,13 @@ end: taskExit(task, NULL); } +static void * +io_bridgeSock(sched_task_t *task) +{ + taskExit(task, NULL); +} + /* * ioInitSocket() - Init socket and allocate resources * @@ -224,8 +234,7 @@ ioCloseSocket(sock_t ** __restrict s) schedCancelby((*s)->sock_root, taskTIMER, CRITERIA_DATLEN, (void*) cli->cli_fd, NULL); - schedCancelby((*s)->sock_root, taskMAX, CRITERIA_FD, - (void*) cli->cli_fd, NULL); + schedCancelby((*s)->sock_root, taskMAX, CRITERIA_ARG, cli, NULL); if ((*s)->sock_type == SOCK_STREAM) { shutdown(cli->cli_fd, SHUT_RDWR); @@ -323,6 +332,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 @@ -332,25 +360,25 @@ 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); + return ioLoopSocket(s, io_bridgeSock); }