/**
  * Accepts a new connection.
  *
  * @param resource $listenerStream The socket created by stream_socket_server
  */
 private function newConnection($listenerStream)
 {
     $stream = stream_socket_accept($listenerStream);
     // The first bit of data from the client should be a HTTP request.
     $req = HttpRequest::FromStream($stream, [$this, 'gotHeaders']);
     // Send the stream to the HTTP request handler.
     $this->streams->addStream($stream, null, $req);
 }