starting compile server - advice needed

Per Bothner per@bothner.com
Fri Jul 11 21:59:00 GMT 2003


As I've mentioned before, I am working for Apple on a "gcc compile 
server", where cc1/cc1plus/... are started up in server mode, and wait 
on a socket for compilation requests.  (The primary goal is compilation 
speed, as the server can remember the declarations etc from previous 
header files.)

At the Gcc Summit in Ottawa I mentioned a problem for which I could use 
some help: How to have a client automatically start up a server if one 
isn't running already.

In the existing code, the server has to be started and stopped manually. 
  After it has been started, it creates a Unix domain socket (which is 
bound to ./.cc1-server in the case of cc1), and waits listening for 
compilation requests.  A client runs gcc in the normal manner, but if 
the --server option is pased to gcc, then gcc sends compilation requests 
to the server, instead of forking a fresh cc1.

What I would like is for --server to not fail if no server is running, 
but to automatically start a new server and use that.  The new server 
would hang around for a while, handling other compilation requests, 
exiting if there is no compilation request within a specified timeout 
(perhaps 10 minutes by default).

So my question is:  What is the recommended method for starting a server 
if one isn't running?  Note that what makes this non-obvious are various 
race conditions:  The client has to wait until the server has started, 
initialized itself, and is ready for a connection.  Furthermore, it is 
possible (but less likely) for some other client to have already started 
a server, but we don't see it because isn't yet listening for connections.

The "obvious" solution for at least the first problem is for the client 
to start up in "server mode", by doing the bind+listen+accept, start the 
server with a option telling it to use the client-created socket, and 
once the client and server and rendezvous'd switch the roles of client 
and server.

I could probably figure out how to get this working, but it would be 
easier if I look look at existing code that does something similar, 
since I'm sure there are various gotch's I need to know about, and I 
have very little experience with this sort of programming.  People at 
the Summit mentioned code I could look at, but I've forgotten their 
suggestions.

Any advice?  Perhaps having a client automatically start a server is the 
wrong thing to do?
-- 
	--Per Bothner
per@bothner.com   http://per.bothner.com/





More information about the Gcc mailing list