mirror of
https://github.com/X11Libre/xserver.git
synced 2026-11-01 03:03:58 +00:00
os: Implement support for NotifyFd X_NOTIFY_WRITE
This adds the ability to be notified when a file descriptor is available for writing. Reviewed-by: Adam Jackson <ajax@redhat.com> Signed-off-by: Keith Packard <keithp@keithp.com>
This commit is contained in:
parent
0c41b7af4a
commit
4020aacd1f
4 changed files with 59 additions and 24 deletions
|
|
@ -124,15 +124,18 @@ static int lastfdesc; /* maximum file descriptor */
|
|||
fd_set WellKnownConnections; /* Listener mask */
|
||||
fd_set EnabledDevices; /* mask for input devices that are on */
|
||||
fd_set NotifyReadFds; /* mask for other file descriptors */
|
||||
fd_set NotifyWriteFds; /* mask for other write file descriptors */
|
||||
fd_set AllSockets; /* select on this */
|
||||
fd_set AllClients; /* available clients */
|
||||
fd_set LastSelectMask; /* mask returned from last select call */
|
||||
fd_set LastSelectWriteMask; /* mask returned from last select call */
|
||||
fd_set ClientsWithInput; /* clients with FULL requests in buffer */
|
||||
fd_set ClientsWriteBlocked; /* clients who cannot receive output */
|
||||
fd_set OutputPending; /* clients with reply/event data ready to go */
|
||||
int MaxClients = 0;
|
||||
int NumNotifyWriteFd; /* Number of NotifyFd members with write set */
|
||||
Bool NewOutputPending; /* not yet attempted to write some new output */
|
||||
Bool AnyClientsWriteBlocked; /* true if some client blocked on write */
|
||||
Bool AnyWritesPending; /* true if some client blocked on write or NotifyFd with write */
|
||||
Bool NoListenAll; /* Don't establish any listening sockets */
|
||||
|
||||
static Bool RunFromSmartParent; /* send SIGUSR1 to parent process */
|
||||
|
|
@ -969,8 +972,8 @@ CloseDownFileDescriptor(OsCommPtr oc)
|
|||
FD_CLR(connection, &SavedClientsWithInput);
|
||||
}
|
||||
FD_CLR(connection, &ClientsWriteBlocked);
|
||||
if (!XFD_ANYSET(&ClientsWriteBlocked))
|
||||
AnyClientsWriteBlocked = FALSE;
|
||||
if (!XFD_ANYSET(&ClientsWriteBlocked) && NumNotifyWriteFd == 0)
|
||||
AnyWritesPending = FALSE;
|
||||
FD_CLR(connection, &OutputPending);
|
||||
}
|
||||
|
||||
|
|
@ -1112,6 +1115,7 @@ InitNotifyFds(void)
|
|||
RemoveNotifyFd(s->fd);
|
||||
|
||||
xorg_list_init(¬ify_fds);
|
||||
NumNotifyWriteFd = 0;
|
||||
been_here = 1;
|
||||
}
|
||||
|
||||
|
|
@ -1153,6 +1157,20 @@ SetNotifyFd(int fd, NotifyFdProcPtr notify, int mask, void *data)
|
|||
FD_CLR(fd, &NotifyReadFds);
|
||||
}
|
||||
}
|
||||
|
||||
if (changes & X_NOTIFY_WRITE) {
|
||||
if (mask & X_NOTIFY_WRITE) {
|
||||
FD_SET(fd, &NotifyWriteFds);
|
||||
if (!NumNotifyWriteFd++)
|
||||
AnyWritesPending = TRUE;
|
||||
} else {
|
||||
FD_CLR(fd, &NotifyWriteFds);
|
||||
if (!--NumNotifyWriteFd)
|
||||
if (!XFD_ANYSET(&ClientsWriteBlocked))
|
||||
AnyWritesPending = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if (mask == 0) {
|
||||
xorg_list_del(&n->list);
|
||||
free(n);
|
||||
|
|
@ -1174,12 +1192,16 @@ SetNotifyFd(int fd, NotifyFdProcPtr notify, int mask, void *data)
|
|||
void
|
||||
HandleNotifyFds(void)
|
||||
{
|
||||
struct notify_fd *s, *next;
|
||||
struct notify_fd *n, *next;
|
||||
|
||||
xorg_list_for_each_entry_safe(s, next, ¬ify_fds, list) {
|
||||
if (FD_ISSET(s->fd, &LastSelectMask)) {
|
||||
s->notify(s->fd, X_NOTIFY_READ, s->data);
|
||||
}
|
||||
xorg_list_for_each_entry_safe(n, next, ¬ify_fds, list) {
|
||||
int ready = 0;
|
||||
if ((n->mask & X_NOTIFY_READ) && FD_ISSET(n->fd, &LastSelectMask))
|
||||
ready |= X_NOTIFY_READ;
|
||||
if ((n->mask & X_NOTIFY_WRITE) & FD_ISSET(n->fd, &LastSelectWriteMask))
|
||||
ready |= X_NOTIFY_WRITE;
|
||||
if (ready != 0)
|
||||
n->notify(n->fd, ready, n->data);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue