Use unix sockets instead of pipes for posix daemon. (#10766)

Unlike pipes, unix sockets provide bi-directional
communication with each connected client.

- No need to generate a unique uuid per client anymore.

- The client doesn't have to create its own pipe anymore.

- Since there is no risk of multiple client's writes getting mixed up,
  messages don't need to fit in a single write anymore, removing the
  limit on command length.

- Since the server can detect a connection closing, the client no longer
  needs to handle signals. When the client is killed, the connection is
  automatically closed, which will cause the server to kill the related
  px4 thread.
  Since this does not rely on handling signals and the client sending an
  additional message, this is much more reliable.

- Client is no longer a singleton.

- The protocol is simplified. Standard output is directly written to the
  socket back to the client, without wrapping it in any protocol
  message.

- Because of the simple protocol, one could now even use netcat to run a
  px4 command:

    $ echo hello | netcat -UN /tmp/px4-sock-0

Also removes a few race conditions.
This commit is contained in:
Mara Bos
2018-11-13 14:31:22 -05:00
committed by Daniel Agar
parent 9379c010f1
commit 9594ebf72e
9 changed files with 270 additions and 638 deletions
-2
View File
@@ -173,8 +173,6 @@ int main(int argc, char **argv)
argv[0] += path_length + strlen(prefix);
px4_daemon::Client client(instance);
client.generate_uuid();
client.register_sig_handler();
return client.process_args(argc, (const char **)argv);
} else {