version 1.11.2.2, 2013/12/12 15:23:44
|
version 1.11.2.3, 2013/12/12 21:17:53
|
Line 61 io_closeClient(sched_task_t *task)
|
Line 61 io_closeClient(sched_task_t *task)
|
|
|
if (*cli->cli_name) |
if (*cli->cli_name) |
ioFreePTY(cli->cli_pty, cli->cli_name); |
ioFreePTY(cli->cli_pty, cli->cli_name); |
|
if (s->sock_prog) { |
|
io_progDetach(s->sock_prog, cli->cli_pty); |
|
cli->cli_pty ^= cli->cli_pty; |
|
} |
|
|
if (s->sock_type == SOCK_STREAM) { |
if (s->sock_type == SOCK_STREAM) { |
shutdown(cli->cli_fd, SHUT_RDWR); |
shutdown(cli->cli_fd, SHUT_RDWR); |
Line 311 end:
|
Line 315 end:
|
taskExit(task, NULL); |
taskExit(task, NULL); |
} |
} |
|
|
|
static void * |
|
io_bridgeClient2Pool(sched_task_t *task) |
|
{ |
|
int c, rlen; |
|
sockaddr_t sa; |
|
socklen_t salen = sizeof sa.ss; |
|
sock_cli_t *cli = NULL; |
|
sock_t *s = (sock_t*) TASK_ARG(task); |
|
|
|
if (s->sock_type == SOCK_STREAM) { |
|
if ((c = accept(TASK_FD(task), &sa.sa, &salen)) == -1) { |
|
LOGERR; |
|
goto end; |
|
} |
|
} else { |
|
if ((rlen = recvfrom(TASK_FD(task), |
|
AIT_GET_BUF(&s->sock_buf), AIT_LEN(&s->sock_buf), |
|
MSG_PEEK, &sa.sa, &salen)) == -1) { |
|
LOGERR; |
|
goto end; |
|
} else |
|
c = TASK_FD(task); |
|
} |
|
|
|
cli = e_malloc(sizeof(sock_cli_t)); |
|
if (!cli) { |
|
io_SetErr(elwix_GetErrno(), "%s", elwix_GetError()); |
|
if (s->sock_type == SOCK_STREAM) |
|
close(c); |
|
goto end; |
|
} else { |
|
memset(cli, 0, sizeof(sock_cli_t)); |
|
pthread_mutex_lock(&s->sock_mtx); |
|
TAILQ_INSERT_TAIL(&s->sock_cli, cli, cli_node); |
|
pthread_mutex_unlock(&s->sock_mtx); |
|
} |
|
|
|
cli->cli_parent = TASK_ARG(task); |
|
cli->cli_fd = c; |
|
cli->cli_pty = io_progAttach(s->sock_prog, 42); |
|
strlcpy(cli->cli_cmdline, TASK_DATA(task), sizeof cli->cli_cmdline); |
|
memcpy(&cli->cli_addr, &sa, sizeof cli->cli_addr); |
|
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), io_rxPty, cli, cli->cli_pty, TASK_ARG(task), 0); |
|
schedRead(TASK_ROOT(task), io_rxNet, cli, cli->cli_fd, TASK_ARG(task), 0); |
|
ioUpdTimerSocket(cli); |
|
end: |
|
schedReadSelf(task); |
|
taskExit(task, NULL); |
|
} |
|
|
|
|
/* |
/* |
* ioInitSocket() - Init socket and allocate resources |
* ioInitSocket() - Init socket and allocate resources |
* |
* |
Line 517 ioUpdTimerSocket(sock_cli_t * __restrict c)
|
Line 574 ioUpdTimerSocket(sock_cli_t * __restrict c)
|
else |
else |
s = c->cli_parent; |
s = c->cli_parent; |
|
|
|
if (s->sock_prog) |
|
io_progCheck(s->sock_prog, 42); |
|
|
schedCancelby(s->sock_root, taskTIMER, CRITERIA_ARG, c, NULL); |
schedCancelby(s->sock_root, taskTIMER, CRITERIA_ARG, c, NULL); |
schedTimer(s->sock_root, io_closeClient, c, s->sock_timeout, NULL, 0); |
schedTimer(s->sock_root, io_closeClient, c, s->sock_timeout, NULL, 0); |
} |
} |
Line 570 ioBridgeProg2Socket(sock_t * __restrict s, const char
|
Line 630 ioBridgeProg2Socket(sock_t * __restrict s, const char
|
if (!s || !prgname || s->sock_kill) |
if (!s || !prgname || s->sock_kill) |
return -1; |
return -1; |
|
|
schedRead(s->sock_root, io_bridgeClient, s, s->sock_fd, (void*) prgname, 0); | schedRead(s->sock_root, s->sock_prog ? io_bridgeClient2Pool : io_bridgeClient, |
| s, s->sock_fd, (void*) prgname, 0); |
return schedRun(s->sock_root, &s->sock_kill); |
return schedRun(s->sock_root, &s->sock_kill); |
} |
} |
|
|