Professional Documents
Culture Documents
Proceedings of the
XFree86 Technical Conference
2001 by The USENIX Association All Rights Reserved For more information about the USENIX Association:
Phone: 1 510 528 8649 FAX: 1 510 548 5738 Email: office@usenix.org WWW: http://www.usenix.org
Rights to individual papers remain with the author or the author's employer.
Permission is granted for noncommercial reproduction of the work for educational or research purposes.
This copyright notice must be included in the reproduced paper. USENIX acknowledges all trademarks herein.
XCB: An X Protocol C Binding
API Requests
Reply list
XCB Sequence #
Reply Record
API
Current Data
XCB Connection
Atom
Per-Connection Data Structures Cache
X Protocol
Output
Buffer
X Server
Creation functions for such things as connec- tricks as running X directly over a serial line, and
tions and XIDs. These functions return typed helps to isolate XCB from long-term changes in X
values. and networking environments and conventions.
Blocking requests, for example tional one: they are individually hand-coded in C.
XCB takes a metalevel approach: a stub descrip-
XCB_Window_Cookie tion processor implemented using the m4 [KR77]
XCB_GetInputFocus( macro preprocessor translates custom stub descrip-
XCB_Connection c) tions written in a specialized macro language into C
code automatically. This approach has several ad-
vantages: it helps reduce the likelihood of defects in
ing a reply cookie of type XCB Window Cookie 3 Xlib and XCB Compared
to the client. The upper layer of XCB delivers this
cookie by asking the lower layer to allocate a reply Having discussed both Xlib and XCB in some de-
record with the current sequence number. The re- tail, it is useful to summarize some of the com-
quest is also encoded at this time and placed in the parisons and contrasts between the two. XCB in-
lower layers output buffer for eventual delivery. Fi- troduces several novel features, borrows some nice
nally the cookie containing the sequence number is features from Xlib, and foregoes some Xlib func-
returned to the client. tionality.
Principal new features of XCB include latency hid-
The pending request is eventually shipped to the ing through reply cookies, amenability to use by
X server, when the buffer is flushed as described threaded clients and better static typechecking. Be-
in Section 2.2. By this time, the server may have cause of its extensive use of structure and union
generated and shipped several events, which are en- types, XCB interfaces are well protected against pa-
queued ahead of the server-generated reply. When rameter mismatches. In general, the syntactic and
the user calls XCB GetWindowID() with the reply semantic regularity of XCB, at least in contrast to
cookie as an argument, the lower layer uses the se- Xlib, should greatly ease its use.
quence number of the reply cookie to index the re- A variety of good ideas from Xlib were incorpo-
ply list, eventually finding the reply record. It then rated into XCB. The buffering of output to form
notes that no reply has yet been received from the large packets increases effective bandwidth and re-
server. Initiating a blocking read from the server to duces network load. Similarly, doing large reads on
obtain the data, the lower layer enqueues the events connection input when possible may greatly reduce
read from the connection, then reads the reply. The syscall overhead in the presence of large numbers
resulting reply buffer, together with the connection of events. XLibs sequence number management is
socket, is passed up to the XCB upper layer, which quite clever: in particular, the use of a dummy re-
assembles the requested window ID from the given quest requiring a reply to both skip a sequence num-
data. The result is placed in the reply cookie and ber and establish a synchronization point is imitated
the blocked request returns to the upper layer. The by XCB in sequence number management. XLibs
upper layer removes the relevant reply from the re- proviso for direct select() access to the con-
ply record, frees this record and returns the window nection file-descriptor has proven to be important
requested by the XCB GetWindowID() call. for single-threaded applications and was included
in XCB for this reason.
Alternatively, the reply may be received before Some features of Xlib, including some quite useful
the result is requested. In this case, the result is ones, were dropped on the theory that they could
nonetheless constructed as the reply is received, not carry their own weight in implementation size
and delivered to the client as requested. The reply and complexity. Notably, XCB is a fairly direct
record tracks the current state, recording whether a binding to the X protocol: it does not send multi-
reply has been received, and whether a result has ple requests for large inputs, directly marshal mul-
been requested. tiple results, or cache request or reply information
locally (with the exception of the atom cache). The [KR77] Brian W. Kerninghan and Dennis M.
complicated input processing of Xlib is not pro- Ritchie. The M4 Macro Processor.
vided, nor is any direct support for i18n features. AT&T Bell Laboratories, 1977. Unix
Programmers Manual Volume 2, 7th
Perhaps the most notable feature of Xlib missing in
Edition.
XCB is Xlib compatibility in the API: it would be
nice to be able to achieve some of the XCB gains [KR78] Brian W. Kerninghan and Dennis M.
by relinking existing applications. While, for the Ritchie. The C Programming Language.
reasons described immediately above this is not a Prentice Hall, 1978. ISBN 0-13-110163-
feasible goal for XCB itself, it is believed that with 3.
reasonable effort a lightweight Xlib compatibility
layer could be placed atop XCB. [Nag84] John Nagle. RFC896: Congestion con-
trol in IP/TCP internetworks. RFC
896, Ford Aerospace and Communica-
4 Status and Future Work tions Corporation, 1984.
An XCB code base is currently under development. [NBF96] Bradford Nichols, Dick Buttlar, and
Simple examples work, but much work remains to Jacqueline Proulx Farrell. Pthreads Pro-
complete the implementation. Once the implemen- gramming, A POSIX Standard for Better
tation of the core protocol is complete, work will Multiprocessing. OReilly & Associates,
commence on the implementation of many of the Inc., first edition, September 1996.
X Consortium and XFree86 extensions. Finally, [Pac01] Keith Packard. An LBX postmortem.
the longer-term goal of layering font and render- http://xfree86.org/keithp/
ing support atop XCB should eventually lead to an talks/lbxpost, January 2001.
Xlib compatibility library, a redesigned C interface
for standalone programs and a toolkit. [SG86] Robert W. Scheifler and Jim Gettys. The
X window system. ACM Transactions on
Graphics, 5(2):79109, April 1986.
Availability
[SG92] Robert W. Scheifler and James Gettys. X
When complete, the XCB implementation will be Window System. Digital Press, third edi-
made freely available under the XFree86 License. tion, 1992.
More information should appear on the web at
http://xcb.cs.pdx.edu in the near future.
Acknowledgments
References
[ANS] X3.159-1989.