5 Other Features
5.7.2 UNIX (Linux/Mac)
The IPC communication channel is a Unix domain socket located on
/tmp
. For example, ”
nose --ipc-
server foo
” will create the socket
/tmp/too.socket
. (If the filesystem entry already exists, it will be
deleted, even if it’s a normal file.) Since host tool v1.3, the argument can be a full path too (if
/
or
\
appears in the argument, it’s considered a full path). For testing, the third party program
so cat
can be
used to interactively send commands:
socat /tmp/foo.socket -
--ipc-connect
takes a full path. Both sockets are supported (connect() is used) and other types of files
(open() is used).
5.7.3 Protocol
You can send commands in text or JSON form (the
help
command lists available commands and shows
the basic syntax). The protocol uses 1 JSON object per line (in both directions of communication). A line
is terminated with
\n
(ASCII line feed, byte 10). It is fairly self-describing:
IPC example
{"command":"mdio_read", "phy":1,"address":1,"id":1}
// client to host tool
{"id":1,"result":31049,"success":true}
// host tool to client
The
id
field is an arbitrary integer chosen by the client, and can be used to associate requests with replies.
The C-style comments are for illustration, and not part of the protocol.
For example, on the shell and with
socat
, you could do the above by:
Terminal 1
$ nose --ipc-server test
Terminal 2
$ echo '{"command":"mdio_read","phy":1,"address":1,"id":1}' | socat - /tmp/test.socket > /tmp/output.txt
$ cat /tmp/output.txt
{"id":1,"result":31081,"success":true}
A proper client can send multiple commands to the same connection. Replies are always sent immediately,
though certain conditions like USB communication failing will block replies until a timeout. Replies are
always sent back in order (it cannot happen that the reply for the first request comes after the reply for
the second request). Events (such as log messages) can appear at any time, even between request/reply
messages.
Log messages (such as output when PHY links change their state) are wrapped into special JSON mes-
sages:
Log message example
{"type":"log","msg":"PHY 1: link=up speed=1000MBit\n"}
18