| Home | Articles | JSAP | | Lab | Retired | Contact | About |
|
| Nailgun | News | Background | Quick Start | API | | Changelog | License | Download | |
|
|
|
Nailgun ProtocolOverviewNailgun includes both server and client implementations of the protocol, so this document serves mainly to satisfy the curious and to provide a guide to those who like to peer into code. The goal of the Nailgun protocol is to allow for remotely-hosted individual command line programs. To this end, it makes the following available to the server:
The server can read from the client's stdin, and can direct output to the client's stdout and stderr. The server can also specify an exit code which the client program will use to exit immediately. The initial implementation uses a TCP socket. There may be a performance benefit to using domain sockets on *nix systems sometime in the future. Communications proceed as follows (chunk descriptions are below):
after step 5, the following may happen, interleaved and in any order:
These steps repeat indefinitely until the server transmits an "exit" chunk. A "chunk" is a variable-length block of data beginning with a 5-byte chunk header and followed by an optional payload. The chunk header consists of:
Argument ChunksArgument chunks are the arguments available to the ng client via its argv[] array, with the following modifications:
Exactly one argument is sent in its entirety in each argument chunk. Environment ChunksEnvironment chunks are the environment variables available to the ng client via its env[] array, with no modifications. Exactly one environment variable is sent in its entirety in each environment chunk. Working Directory ChunkExactly one working directory chunk must be sent by the client, containing the working directory from which the client was launched. Command ChunkExactly one command chunk must be sent by the client, containing in its entirety the command to run. Stdin, Stdout, Stderr ChunksEach stream may consist of multiple chunks as necessary. For example, the client will probably buffer stdin before transmitting it to the server, so the payloads of Stdin chunks will always have a size less than or equal to the buffer size. The server may need to interleave stdout and stderr, resulting in some small chunks as well. No transformations are made on the data contained within the chunks. The data are the raw bytes read from stdin/to be sent to stdout/stderr. Stdin-eof ChunkThe server will need to know when there's no more input to read. This is signalled by the client using a Stdin-eof chunk with no payload. No more Stdin chunks may follow a Stdin-oef chunk. Exit ChunkThe server can instruct the client to exit with a code specified in an Exit chunk. The code is contained within the payload as a US-ASCII string representation of the exit code in decimal format. A c-based client would use atoi on the payload in order to determine the exit code. The client should gracefully close the socket to the server prior to exiting. |
|