[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Xlib and file descriptors

Pierre Phaneuf wrote:
> Lutz Sammer wrote:
> > > Speaking of file descriptors, does anybody know of a way to get the fd
> > > of the connection to the X server or at least a "pseudo-select" (like
> > > Svgalib has)?
> > >
> > > I'd like my game to be totally blocking on the poll/select call, with
> > > everything expressed as file descriptors and with the timeout set for my
> > > timebase (if poll returns after a timeout, I send a timetick event and
> > > go back into the poll)...
> >
> > You can get it with ConnectionNumber. (man ConnectionNumber)
> Thanks a lot! Talk about documentation:
>         The ConnectionNumber macro returns a connection number for
>         the specified display.
> That's an fd? :-)

It is a fd, could be used for select/poll. But if this is correct for all
implementations I don't know.

> > To get a constant timing base, use setitimer. This is also works fine
> > combined with select/poll.
> Yes, but this introduces signals in the equation, with all the
> restrictions of what you can and can't do in the signal handler. I do
> extensive stuff upon getting the timetick event, so I'd have to set a
> flag somewhere and check it in my event loop anyway, which would be too
> late in this case.

It is always good only to set a flag. The signal interrupts your select/poll.
Than you can test the errno==EINTR and the flag.
If you want an exact time spend, you could also use the CPU tsc (time-stamp
counter) register. But this is only on alpha and 586 cpu's available.