version 1.5, 1998/03/12 04:57:40 |
version 1.6, 1998/12/28 11:13:51 |
|
|
# endif |
# endif |
#endif /* USE_TERMIO */ |
#endif /* USE_TERMIO */ |
|
|
static fd_set ibits, obits, xbits; |
fd_set *ibitsp, *obitsp, *xbitsp; |
|
int fdsn; |
|
|
|
|
void |
void |
init_sys() |
init_sys() |
{ |
{ |
tout = fileno(stdout); |
tout = fileno(stdout); |
tin = fileno(stdin); |
tin = fileno(stdin); |
FD_ZERO(&ibits); |
|
FD_ZERO(&obits); |
|
FD_ZERO(&xbits); |
|
|
|
errno = 0; |
errno = 0; |
} |
} |
|
|
*/ |
*/ |
int returnValue = 0; |
int returnValue = 0; |
static struct timeval TimeValue = { 0 }; |
static struct timeval TimeValue = { 0 }; |
|
int maxfd = -1; |
|
int tmp; |
|
|
if (netout) { |
if ((netout || netin || netex) && net > maxfd) |
FD_SET(net, &obits); |
maxfd = net; |
|
if (ttyout && tout > maxfd) |
|
maxfd = tout; |
|
if (ttyin && tin > maxfd) |
|
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 (ttyout) { |
|
FD_SET(tout, &obits); |
if (netout) |
} |
FD_SET(net, obitsp); |
#if defined(TN3270) |
if (ttyout) |
if (ttyin) { |
FD_SET(tout, obitsp); |
FD_SET(tin, &ibits); |
if (ttyin) |
} |
FD_SET(tin, ibitsp); |
#else /* defined(TN3270) */ |
if (netin) |
if (ttyin) { |
FD_SET(net, ibitsp); |
FD_SET(tin, &ibits); |
if (netex) |
} |
FD_SET(net, xbitsp); |
#endif /* defined(TN3270) */ |
|
#if defined(TN3270) |
if ((c = select(maxfd+1, ibitsp, obitsp, xbitsp, |
if (netin) { |
(poll == 0)? (struct timeval *)0 : &TimeValue)) < 0) { |
FD_SET(net, &ibits); |
|
} |
|
# else /* !defined(TN3270) */ |
|
if (netin) { |
|
FD_SET(net, &ibits); |
|
} |
|
# endif /* !defined(TN3270) */ |
|
if (netex) { |
|
FD_SET(net, &xbits); |
|
} |
|
if ((c = select(16, &ibits, &obits, &xbits, |
|
(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, |
|
|
* to make sure we are selecting on the right |
* to make sure we are selecting on the right |
* ones. |
* ones. |
*/ |
*/ |
FD_ZERO(&ibits); |
memset(ibitsp, 0, fdsn); |
FD_ZERO(&obits); |
memset(obitsp, 0, fdsn); |
FD_ZERO(&xbits); |
memset(xbitsp, 0, fdsn); |
return 0; |
return 0; |
} |
} |
# endif /* defined(TN3270) */ |
# endif /* defined(TN3270) */ |
|
|
/* |
/* |
* Any urgent data? |
* Any urgent data? |
*/ |
*/ |
if (FD_ISSET(net, &xbits)) { |
if (FD_ISSET(net, xbitsp)) { |
FD_CLR(net, &xbits); |
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, &ibits)) { |
if (FD_ISSET(net, ibitsp)) { |
int canread; |
int canread; |
|
|
FD_CLR(net, &ibits); |
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, &ibits)) { |
if (FD_ISSET(tin, ibitsp)) { |
FD_CLR(tin, &ibits); |
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, &obits)) { |
if (FD_ISSET(net, obitsp)) { |
FD_CLR(net, &obits); |
FD_CLR(net, obitsp); |
returnValue |= netflush(); |
returnValue |= netflush(); |
} |
} |
if (FD_ISSET(tout, &obits)) { |
if (FD_ISSET(tout, obitsp)) { |
FD_CLR(tout, &obits); |
FD_CLR(tout, obitsp); |
returnValue |= (ttyflush(SYNCHing|flushout) > 0); |
returnValue |= (ttyflush(SYNCHing|flushout) > 0); |
} |
} |
|
|