Page MenuHomePhorge
Diviner libphutil Tech Docs ArcanistHgProxyServer

final class ArcanistHgProxyServer
libphutil Technical Documentation ()

Server which ArcanistHgProxyClient clients connect to. This server binds to a Mercurial working copy and creates a Mercurial process and a unix domain socket in that working copy. It listens for connections on the socket, reads commands from them, and forwards their requests to the Mercurial process. It then returns responses to the original clients.

Note that this server understands the underlying protocol and completely decodes messages from both the client and server before re-encoding them and relaying them to their final destinations. It must do this (at least in part) to determine where messages begin and end. Additionally, this proxy sends and receives the Mercurial cmdserver protocol exactly, without any extensions or sneakiness.

The advantage of this mechanism is that it avoids the overhead of starting a Mercurial process for each Mercurial command, which can exceed 100ms per invocation. This server can also accept connections from multiple clients and serve them from a single Mercurial server process.

Tasks

Construction

  • public function __construct($working_copy) — Build a new server. This server is bound to a working copy. The server is inactive until you @{method:start} it.

Configuration

  • public function setQuiet($quiet) — Disable status messages to stdout. Controlled with `--quiet`.
  • public function setClientLimit($limit) — Configure a client limit. After serving this many clients, the server will exit. Controlled with `--client-limit`.
  • public function setIdleLimit($limit) — Configure an idle time limit. After this many seconds idle, the server will exit. Controlled with `--idle-limit`.
  • public function setSkipHello($skip) — When clients connect, do not send the "capabilities" message expected by the Mercurial protocol. This deviates from the protocol and will only work if the clients are also configured not to expect the message, but slightly improves performance. Controlled with --skip-hello.
  • public function setDoNotDaemonize($do_not_daemonize) — Configure whether the server runs in the foreground or daemonizes. Controlled by --do-not-daemonize. Primarily useful for debugging.

Serving Requests

  • public function start() — Start the server. This method returns after the client limit or idle limit are exceeded. If neither limit is configured, this method does not exit.
  • private function updateClient($client, $hg) — Update one client, processing any commands it has sent us. We fully process all commands we've received here before returning to the main server loop.

Managing Clients

Managing Mercurial

  • private function startMercurialProcess() — Starts a Mercurial process which can actually handle requests.

Internals

  • public function __destruct() — Close and remove the unix domain socket in the working copy.

Other Methods

Methods

public function __get($name)
Inherited

This method is not documented.
Parameters
$name
Return
wild

public function __set($name, $value)
Inherited

This method is not documented.
Parameters
$name
$value
Return
wild

public function current()
Inherited

This method is not documented.
Return
wild

public function key()
Inherited

This method is not documented.
Return
wild

public function next()
Inherited

This method is not documented.
Return
wild

public function rewind()
Inherited

This method is not documented.
Return
wild

public function valid()
Inherited

This method is not documented.
Return
wild

private function throwOnAttemptedIteration()
Inherited

This method is not documented.
Return
wild

public function getPhobjectClassConstant($key, $byte_limit)
Inherited

Phobject

Read the value of a class constant.

This is the same as just typing self::CONSTANTNAME, but throws a more useful message if the constant is not defined and allows the constant to be limited to a maximum length.

Parameters
string$keyName of the constant.
int|null$byte_limitMaximum number of bytes permitted in the value.
Return
stringValue of the constant.

public function __construct($working_copy)

Build a new server. This server is bound to a working copy. The server is inactive until you start() it.

Parameters
string$working_copyPath to a Mercurial working copy.
Return
this//Implicit.//

public function setQuiet($quiet)

Disable status messages to stdout. Controlled with --quiet.

Parameters
bool$quietTrue to disable status messages.
Return
this

public function setClientLimit($limit)

Configure a client limit. After serving this many clients, the server will exit. Controlled with --client-limit.

You can use --client-limit 1 with --xprofile and --do-not-daemonize to profile the server.

Parameters
int$limitClient limit, or 0 to disable limit.
Return
this

public function setIdleLimit($limit)

Configure an idle time limit. After this many seconds idle, the server will exit. Controlled with --idle-limit.

Parameters
int$limitIdle limit, or 0 to disable limit.
Return
this

public function setSkipHello($skip)

When clients connect, do not send the "capabilities" message expected by the Mercurial protocol. This deviates from the protocol and will only work if the clients are also configured not to expect the message, but slightly improves performance. Controlled with --skip-hello.

Parameters
bool$skipTrue to skip the "capabilities" message.
Return
this

public function setDoNotDaemonize($do_not_daemonize)

Configure whether the server runs in the foreground or daemonizes. Controlled by --do-not-daemonize. Primarily useful for debugging.

Parameters
bool$do_not_daemonizeTrue to run in the foreground.
Return
this

public function start()

Start the server. This method returns after the client limit or idle limit are exceeded. If neither limit is configured, this method does not exit.

Return
null

private function updateClient($client, $hg)

Update one client, processing any commands it has sent us. We fully process all commands we've received here before returning to the main server loop.

Parameters
ArcanistHgClientChannel$clientThe client to update.
ArcanistHgServerChannel$hgThe Mercurial server.
Return
wild

public static function getPathToSocket($working_copy)

This method is not documented.
Parameters
$working_copy
Return
wild

private function startWorkingCopySocket()

This method is not documented.
Return
wild

private function acceptNewClient($socket)

This method is not documented.
Parameters
$socket
Return
wild

private function startMercurialProcess()

Starts a Mercurial process which can actually handle requests.

Return
ArcanistHgServerChannelChannel to the Mercurial server.

public function __destruct()

Close and remove the unix domain socket in the working copy.

Return
wild

private function closeSocket()

This method is not documented.
Return
wild

private function log($client, $message)

This method is not documented.
Parameters
$client
$message
Return
wild

private function daemonize()

This method is not documented.
Return
wild