short ddmessage(short apid, short fd, short winid, short mx, short my, short kstate, short pipeid) { char c; short i, msg[8]; long fd_mask; /* AES-Message define and post */ msg[0] = AP_DRAGDROP; msg[1] = _AESapid; msg[2] = 0; msg[3] = winid; msg[4] = mx; msg[5] = my; msg[6] = kstate; msg[7] = pipeid; i = appl_write(apid, 16, msg); if (i == 0) { ddclose(fd); return(-3); } /* receiver reaction */ fd_mask = (1L << fd); i = Fselect(DD_TIMEOUT, &fd_mask, 0L, 0L); if (!i || !fd_mask) { /* Timeout eingetreten */ ddclose(fd); return(-2); } /* le recepteur refuse (lecture du pipe) */ if (Fread(fd, 1L, &c) != 1L) { ddclose(fd); return(-1); } if (c != DD_OK) { ddclose(fd); return(-1); } return(1); }
/* * Sleep for usec microSeconds * the actual suspension time can be arbitrarily longer * */ int usleep (__useconds_t __useconds) { long stop; int r = -ENOSYS; if (__useconds >= 1000) r = Fselect((unsigned)(__useconds/1000), 0L, 0L, 0L); if (r == -ENOSYS) { stop = _clock() + USEC_TO_CLOCK_TICKS(__useconds); while (_clock() < stop) ; r = 0; } if (r < 0) { __set_errno (-r); return -1; } return 0; }
int __poll (struct pollfd *fds, unsigned long int nfds, __int32_t __timeout) { long int retval; unsigned long timeout = (unsigned long) __timeout; #ifdef Fpoll static int must_emulate = 0; if (!must_emulate) { retval = Fpoll (fds, nfds, timeout); if (retval < 0) { if (retval != -ENOSYS) { __set_errno (-retval); return -1; } else must_emulate = 1; } } #endif /* not Fpoll. */ { /* We must emulate the call via Fselect (). First task is to set up the file descriptor masks. */ unsigned long rfds = 0; unsigned long wfds = 0; unsigned long xfds = 0; register unsigned long int i; register struct pollfd* pfds = fds; for (i = 0; i < nfds; i++) { if (pfds[i].fd > 31) { /* We lose. Any better idea than EINVAL? */ __set_errno (EINVAL); return -1; } #define LEGAL_FLAGS \ (POLLIN | POLLPRI | POLLOUT | POLLERR | POLLHUP | POLLNVAL | POLLRDNORM | POLLWRNORM | POLLRDBAND | POLLWRBAND) if ((pfds[i].events | LEGAL_FLAGS) != LEGAL_FLAGS) { /* Not supported. */ __set_errno (EINVAL); return -1; } if (pfds[i].events & (POLLIN | POLLRDNORM)) rfds |= (1L << (pfds[i].fd)); if (pfds[i].events & POLLPRI) xfds |= (1L << (pfds[i].fd)); if (pfds[i].events & (POLLOUT | POLLWRNORM)) wfds |= (1L << (pfds[i].fd)); } if (timeout == -1UL) { retval = Fselect (0L, &rfds, &wfds, &xfds); } else if (timeout == 0) { retval = Fselect (1L, &rfds, &wfds, &xfds); } else if (timeout < USHRT_MAX) { /* The manpage Fselect(2) says that timeout is signed. But it is really unsigned. */ retval = Fselect (timeout, &rfds, &wfds, &xfds); } else { /* Thanks to the former kernel hackers we have to loop in order to simulate longer timeouts than USHRT_MAX. */ unsigned long saved_rfds, saved_wfds, saved_xfds; unsigned short int this_timeout; int last_round = 0; saved_rfds = rfds; saved_wfds = wfds; saved_xfds = xfds; do { if ((unsigned long) timeout > USHRT_MAX) this_timeout = USHRT_MAX; else { this_timeout = timeout; last_round = 1; } retval = Fselect (this_timeout, &rfds, &wfds, &xfds); if (retval != 0) break; timeout -= this_timeout; /* I don't know whether we can rely on the masks not being clobbered on timeout. */ rfds = saved_rfds; wfds = saved_wfds; xfds = saved_xfds; } while (!last_round); } if (retval < 0) { __set_errno (-retval); return -1; } /* Now fill in the results in struct pollfd. */ for (i = 0; i < nfds; i++) { if (rfds & (1L << (pfds[i].fd))) pfds[i].revents = (pfds[i].events & (POLLIN | POLLRDNORM)); else pfds[i].revents = 0; if (xfds & (1L << (pfds[i].fd))) pfds[i].revents |= POLLPRI; if (wfds & (1L << (pfds[i].fd))) pfds[i].revents |= (pfds[i].events & (POLLOUT | POLLWRNORM)); } } /* must emulate. */ return retval; }