From d615c5e51268a23887e2d29b5828a0447ba5409b Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Wed, 11 Jan 2017 12:55:46 -0800 Subject: Add IPC (UNIX domain sockets) for POSIX, and test suite. --- src/core/platform.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'src/core/platform.h') diff --git a/src/core/platform.h b/src/core/platform.h index 5a504dec..2955215b 100644 --- a/src/core/platform.h +++ b/src/core/platform.h @@ -64,6 +64,7 @@ typedef struct nni_plat_mtx nni_plat_mtx; typedef struct nni_plat_cv nni_plat_cv; typedef struct nni_plat_thr nni_plat_thr; typedef struct nni_plat_tcpsock nni_plat_tcpsock; +typedef struct nni_plat_ipcsock nni_plat_ipcsock; // Mutex handling. @@ -208,6 +209,43 @@ extern int nni_plat_tcp_send(nni_plat_tcpsock *, nni_iov *, int); // full, or an error condition occurs. extern int nni_plat_tcp_recv(nni_plat_tcpsock *, nni_iov *, int); +// nni_plat_ipc_init initializes the socket, for example it can +// set underlying file descriptors to -1, etc. +extern void nni_plat_ipc_init(nni_plat_ipcsock *); + +// nni_plat_ipc_fini just closes an IPC socket, and releases any related +// resources. +extern void nni_plat_ipc_fini(nni_plat_ipcsock *); + +// nni_plat_ipc_shutdown performs a shutdown of the socket. For +// BSD sockets, this closes both sides of the IPC connection gracefully, +// but the underlying file descriptor is left open. (This part is critical +// to prevention of close() related races.) +extern void nni_plat_ipc_shutdown(nni_plat_ipcsock *); + +// nni_plat_tcp_listen creates an IPC socket in listening mode, bound +// to the specified path. Note that nni_plat_ipcsock should be defined +// to whatever your platform uses. For most systems its just "int". +extern int nni_plat_ipc_listen(nni_plat_ipcsock *, const char *); + +// nni_plat_ipc_accept does the accept to accept an inbound connection. +// The ipcsock used for the server will have been set up with the +// nni_plat_ipc_listen. +extern int nni_plat_ipc_accept(nni_plat_ipcsock *, nni_plat_ipcsock *); + +// nni_plat_ipc_connect is the client side. +extern int nni_plat_ipc_connect(nni_plat_ipcsock *, const char *); + +// nni_plat_ipc_send sends data to the peer. The platform is responsible +// for attempting to send all of the data. The iov count will never be +// larger than 4. The platform may modify the iovs. +extern int nni_plat_ipc_send(nni_plat_ipcsock *, nni_iov *, int); + +// nni_plat_ipc_recv recvs data into the buffers provided by the +// iovs. The implementation does not return until the iovs are completely +// full, or an error condition occurs. +extern int nni_plat_ipc_recv(nni_plat_ipcsock *, nni_iov *, int); + // nni_plat_seed_prng seeds the PRNG subsystem. The specified number // of bytes of entropy should be stashed. When possible, cryptographic // quality entropy sources should be used. Note that today we prefer -- cgit v1.2.3-70-g09d2