blob: cb340184e6de53f31457ecfdddb2f28159f19ce5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
//
// Copyright 2016 Garrett D'Amore <garrett@damore.org>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
// file was obtained (LICENSE.txt). A copy of the license may also be
// found online at https://opensource.org/licenses/MIT.
//
#include "core/nng_impl.h"
// This file provides the "public" API. This is a thin wrapper around
// internal API functions. We use the public prefix instead of internal,
// to indicate that these interfaces are intended for applications to use
// directly.
//
// Anything not defined in this file, applications have no business using.
// Pretty much every function calls the nni_platform_init to check against
// fork related activity.
int
nng_socket_create(nng_socket **s, uint16_t proto)
{
int rv;
if ((rv = nni_init()) != 0) {
return (rv);
}
return (nni_socket_create(s, proto));
}
int
nng_socket_close(nng_socket *s)
{
int rv;
if ((rv = nni_init()) != 0) {
return (rv);
}
return (nni_socket_close(s));
}
uint16_t
nng_socket_protocol(nng_socket *s)
{
nni_init();
return (nni_socket_proto(s));
}
// Misc.
const char *
nng_strerror(int num)
{
nni_init();
switch (num) {
case 0:
return ("Hunky dory"); /* what did you expect? */
case NNG_EINTR:
return ("Interrupted");
case NNG_ENOMEM:
return ("Out of memory");
case NNG_EINVAL:
return ("Invalid argument");
case NNG_EBUSY:
return ("Resource busy");
case NNG_ETIMEDOUT:
return ("Timed out");
case NNG_ECONNREFUSED:
return ("Connection refused");
case NNG_ECLOSED:
return ("Object closed");
case NNG_EAGAIN:
return ("Try again");
case NNG_ENOTSUP:
return ("Not supported");
case NNG_EADDRINUSE:
return ("Address in use");
default:
return ("Unknown error");
}
}
// Message handling.
int
nng_msg_alloc(nng_msg **msgp, size_t size)
{
int rv;
if ((rv = nni_init()) != 0) {
return (rv);
}
return (nni_msg_alloc(msgp, size));
}
void
nng_msg_free(nng_msg *msg)
{
nni_init();
return (nni_msg_free(msg));
}
|