diff options
| author | Garrett D'Amore <garrett@damore.org> | 2017-01-04 18:30:33 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2017-01-04 18:30:33 -0800 |
| commit | 40da92f0fffc7b69f876ca060d9b4e6682e45a8c (patch) | |
| tree | 3147f840adc3815dd55693e440380992f76b1ba9 /src/core/platform.h | |
| parent | c1d11425846baf22e9a07b0f2bf2ad405e0b42e5 (diff) | |
| download | nng-40da92f0fffc7b69f876ca060d9b4e6682e45a8c.tar.gz nng-40da92f0fffc7b69f876ca060d9b4e6682e45a8c.tar.bz2 nng-40da92f0fffc7b69f876ca060d9b4e6682e45a8c.zip | |
Fix close related races (POSIX close is a PITA).
Diffstat (limited to 'src/core/platform.h')
| -rw-r--r-- | src/core/platform.h | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/src/core/platform.h b/src/core/platform.h index 3292d6f9..afc4c06c 100644 --- a/src/core/platform.h +++ b/src/core/platform.h @@ -60,10 +60,10 @@ extern void *nni_alloc(size_t); // Most implementations can just call free() here. extern void nni_free(void *, size_t); -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_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; // Mutex handling. @@ -174,8 +174,19 @@ extern const char *nni_plat_strerror(int); // returned on dual stack machines. extern int nni_plat_lookup_host(const char *, nni_sockaddr *, int); -// nni_plat_tcp_close just closes a TCP socket. -extern void nni_plat_tcp_close(nni_plat_tcpsock *); +// nni_plat_tcp_init initializes the socket, for example it can +// set underlying file descriptors to -1, etc. +extern void nni_plat_tcp_init(nni_plat_tcpsock *); + +// nni_plat_tcp_fini just closes a TCP socket, and releases any related +// resources. +extern void nni_plat_tcp_fini(nni_plat_tcpsock *); + +// nni_plat_tcp_shutdown performs a shutdown of the socket. For +// BSD sockets, this closes both sides of the TCP connection gracefully, +// but the underlying file descriptor is left open. (This part is critical +// to prevention of close() related races.) +extern void nni_plat_tcp_shutdown(nni_plat_tcpsock *); // nni_plat_tcp_listen creates a TCP socket in listening mode, bound // to the specified address. Note that nni_plat_tcpsock should be defined |
