version 1.14, 2003/06/03 02:56:18 |
version 1.15, 2013/04/21 09:51:24 |
|
|
tin, /* Input file descriptor */ |
tin, /* Input file descriptor */ |
net; |
net; |
|
|
|
#define TELNET_FD_TOUT 0 |
|
#define TELNET_FD_TIN 1 |
|
#define TELNET_FD_NET 2 |
|
#define TELNET_FD_NUM 3 |
|
|
#ifndef USE_TERMIO |
#ifndef USE_TERMIO |
struct tchars otc = { 0 }, ntc = { 0 }; |
struct tchars otc = { 0 }, ntc = { 0 }; |
struct ltchars oltc = { 0 }, nltc = { 0 }; |
struct ltchars oltc = { 0 }, nltc = { 0 }; |
|
|
# endif |
# endif |
#endif /* USE_TERMIO */ |
#endif /* USE_TERMIO */ |
|
|
fd_set *ibitsp, *obitsp, *xbitsp; |
|
int fdsn; |
|
|
|
void |
void |
init_sys() |
init_sys() |
{ |
{ |
|
|
*/ |
*/ |
|
|
int |
int |
process_rings(netin, netout, netex, ttyin, ttyout, poll) |
process_rings(netin, netout, netex, ttyin, ttyout, dopoll) |
int poll; /* If 0, then block until something to do */ |
int dopoll; /* If 0, then block until something to do */ |
{ |
{ |
int c; |
int c; |
/* One wants to be a bit careful about setting returnValue |
/* One wants to be a bit careful about setting returnValue |
|
|
* time (TN3270 mode only). |
* time (TN3270 mode only). |
*/ |
*/ |
int returnValue = 0; |
int returnValue = 0; |
static struct timeval TimeValue = { 0 }; |
struct pollfd pfd[TELNET_FD_NUM]; |
int maxfd = -1; |
|
int tmp; |
|
|
|
if ((netout || netin || netex) && net > maxfd) |
if (ttyout) { |
maxfd = net; |
pfd[TELNET_FD_TOUT].fd = tout; |
if (ttyout && tout > maxfd) |
pfd[TELNET_FD_TOUT].events = POLLOUT; |
maxfd = tout; |
} else { |
if (ttyin && tin > maxfd) |
pfd[TELNET_FD_TOUT].fd = -1; |
maxfd = tin; |
|
tmp = howmany(maxfd+1, NFDBITS) * sizeof(fd_mask); |
|
if (tmp > fdsn) { |
|
if (ibitsp) |
|
free(ibitsp); |
|
if (obitsp) |
|
free(obitsp); |
|
if (xbitsp) |
|
free(xbitsp); |
|
fdsn = tmp; |
|
if ((ibitsp = (fd_set *)malloc(fdsn)) == NULL) |
|
err(1, "malloc"); |
|
if ((obitsp = (fd_set *)malloc(fdsn)) == NULL) |
|
err(1, "malloc"); |
|
if ((xbitsp = (fd_set *)malloc(fdsn)) == NULL) |
|
err(1, "malloc"); |
|
memset(ibitsp, 0, fdsn); |
|
memset(obitsp, 0, fdsn); |
|
memset(xbitsp, 0, fdsn); |
|
} |
} |
|
if (ttyin) { |
|
pfd[TELNET_FD_TIN].fd = tin; |
|
pfd[TELNET_FD_TIN].events = POLLIN; |
|
} else { |
|
pfd[TELNET_FD_TIN].fd = -1; |
|
} |
|
if (netout || netin || netex) { |
|
pfd[TELNET_FD_NET].fd = net; |
|
pfd[TELNET_FD_NET].events = 0; |
|
if (netout) |
|
pfd[TELNET_FD_NET].events |= POLLOUT; |
|
if (netin) |
|
pfd[TELNET_FD_NET].events |= POLLIN; |
|
if (netex) |
|
pfd[TELNET_FD_NET].events |= POLLRDBAND; |
|
} else { |
|
pfd[TELNET_FD_NET].fd = -1; |
|
} |
|
|
if (netout) |
if ((c = poll(pfd, TELNET_FD_NUM, dopoll ? 0 : -1)) < 0) { |
FD_SET(net, obitsp); |
|
if (ttyout) |
|
FD_SET(tout, obitsp); |
|
if (ttyin) |
|
FD_SET(tin, ibitsp); |
|
if (netin) |
|
FD_SET(net, ibitsp); |
|
if (netex) |
|
FD_SET(net, xbitsp); |
|
|
|
if ((c = select(maxfd+1, ibitsp, obitsp, xbitsp, |
|
(poll == 0)? (struct timeval *)0 : &TimeValue)) < 0) { |
|
if (c == -1) { |
if (c == -1) { |
/* |
/* |
* we can get EINTR if we are in line mode, |
* we can get EINTR if we are in line mode, |
|
|
* mode, and the transcom process died. |
* mode, and the transcom process died. |
*/ |
*/ |
if (errno == EBADF) { |
if (errno == EBADF) { |
/* |
|
* zero the bits (even though kernel does it) |
|
* to make sure we are selecting on the right |
|
* ones. |
|
*/ |
|
memset(ibitsp, 0, fdsn); |
|
memset(obitsp, 0, fdsn); |
|
memset(xbitsp, 0, fdsn); |
|
return 0; |
return 0; |
} |
} |
# endif /* defined(TN3270) */ |
# endif /* defined(TN3270) */ |
/* I don't like this, does it ever happen? */ |
/* I don't like this, does it ever happen? */ |
printf("sleep(5) from telnet, after select\r\n"); |
printf("sleep(5) from telnet, after poll\r\n"); |
sleep(5); |
sleep(5); |
} |
} |
return 0; |
return 0; |
|
|
/* |
/* |
* Any urgent data? |
* Any urgent data? |
*/ |
*/ |
if (FD_ISSET(net, xbitsp)) { |
if (pfd[TELNET_FD_NET].revents & POLLRDBAND) { |
FD_CLR(net, xbitsp); |
|
SYNCHing = 1; |
SYNCHing = 1; |
(void) ttyflush(1); /* flush already enqueued data */ |
(void) ttyflush(1); /* flush already enqueued data */ |
} |
} |
|
|
/* |
/* |
* Something to read from the network... |
* Something to read from the network... |
*/ |
*/ |
if (FD_ISSET(net, ibitsp)) { |
if (pfd[TELNET_FD_NET].revents & (POLLIN|POLLHUP)) { |
int canread; |
int canread; |
|
|
FD_CLR(net, ibitsp); |
|
canread = ring_empty_consecutive(&netiring); |
canread = ring_empty_consecutive(&netiring); |
#if !defined(SO_OOBINLINE) |
#if !defined(SO_OOBINLINE) |
/* |
/* |
|
|
/* |
/* |
* Something to read from the tty... |
* Something to read from the tty... |
*/ |
*/ |
if (FD_ISSET(tin, ibitsp)) { |
if (pfd[TELNET_FD_TIN].revents & (POLLIN|POLLHUP)) { |
FD_CLR(tin, ibitsp); |
|
c = TerminalRead(ttyiring.supply, ring_empty_consecutive(&ttyiring)); |
c = TerminalRead(ttyiring.supply, ring_empty_consecutive(&ttyiring)); |
if (c < 0 && errno == EIO) |
if (c < 0 && errno == EIO) |
c = 0; |
c = 0; |
|
|
returnValue = 1; /* did something useful */ |
returnValue = 1; /* did something useful */ |
} |
} |
|
|
if (FD_ISSET(net, obitsp)) { |
if (pfd[TELNET_FD_NET].revents & POLLOUT) { |
FD_CLR(net, obitsp); |
|
returnValue |= netflush(); |
returnValue |= netflush(); |
} |
} |
if (FD_ISSET(tout, obitsp)) { |
if (pfd[TELNET_FD_TOUT].revents & POLLOUT) { |
FD_CLR(tout, obitsp); |
|
returnValue |= (ttyflush(SYNCHing|flushout) > 0); |
returnValue |= (ttyflush(SYNCHing|flushout) > 0); |
} |
} |
|
|