--- libaitio/src/sock.c 2013/11/25 11:46:17 1.9 +++ libaitio/src/sock.c 2013/11/25 18:48:40 1.9.2.1 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: sock.c,v 1.9 2013/11/25 11:46:17 misho Exp $ +* $Id: sock.c,v 1.9.2.1 2013/11/25 18:48:40 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -135,19 +135,36 @@ end: static void * io_txNet(sched_task_t *task) { - int wlen; + int wlen, ret, len = TASK_DATLEN(task); sock_cli_t *cli = TASK_ARG(task); sock_t *s = (sock_t*) cli->cli_parent; + u_char *buf = TASK_DATA(task); + struct pollfd pfd[1]; - ioUpdTimerSocket(cli); + pfd->fd = TASK_FD(task); + pfd->events = POLLOUT; + pfd->revents = 0; + for(; len > 0; len -= wlen, buf += wlen) { + ioUpdTimerSocket(cli); - if (s->sock_type == SOCK_STREAM) - wlen = send(TASK_FD(task), TASK_DATA(task), TASK_DATLEN(task), 0); - else - wlen = sendto(TASK_FD(task), TASK_DATA(task), TASK_DATLEN(task), 0, - &cli->cli_addr.sa, cli->cli_addr.sa.sa_len); - if (wlen < 1) - schedEvent(TASK_ROOT(task), io_closeClient, cli, 0, NULL, 0); + if ((ret = poll(pfd, 1, s->sock_timeout.tv_sec * 1000)) < 1 || + pfd->revents & (POLLNVAL | POLLERR | POLLHUP)) { + if (!ret) + continue; + schedEvent(TASK_ROOT(task), io_closeClient, cli, 0, NULL, 0); + break; + } + + if (s->sock_type == SOCK_STREAM) + wlen = send(TASK_FD(task), buf, len, 0); + else + wlen = sendto(TASK_FD(task), buf, len, 0, + &cli->cli_addr.sa, cli->cli_addr.sa.sa_len); + if (wlen < 1) { + schedEvent(TASK_ROOT(task), io_closeClient, cli, 0, NULL, 0); + break; + } + } taskExit(task, NULL); }