aboutsummaryrefslogtreecommitdiff
path: root/src/supplemental/tcp/tcp.c
blob: f880362b262e482dca56cf35f8c8e873fc6289da (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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
//
// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
// Copyright 2018 Devolutions <info@devolutions.net>
//
// 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 <stddef.h>
#include <stdint.h>

#include <nng/nng.h>
#include <nng/supplemental/tcp/tcp.h>

#include "core/nng_impl.h"

// This is our "public" TCP API.  This allows applications to access
// basic TCP functions, using our AIO framework.  Most applications will
// not need this.

// We treat nng_tcp as nni_tcp_conn, nng_tcp_dialer as nni_tcp_dialer,
// and nng_tcp_listener as nni_tcp_listener.  We cast through void to
// provide isolation of the names in a way that makes the compiler happy.
// It turns out we can pretty much just wrap the platform API for TCP that
// we have already created.

void
nng_tcp_close(nng_tcp *tcp)
{
	nni_tcp_conn_close((void *) tcp);
}

void
nng_tcp_free(nng_tcp *tcp)
{
	nni_tcp_conn_fini((void *) tcp);
}

void
nng_tcp_send(nng_tcp *tcp, nng_aio *aio)
{
	nni_tcp_conn_send((void *) tcp, aio);
}

void
nng_tcp_recv(nng_tcp *tcp, nng_aio *aio)
{
	nni_tcp_conn_recv((void *) tcp, aio);
}

int
nng_tcp_getopt(nng_tcp *tcp, const char *name, void *buf, size_t *szp)
{
	return (nni_tcp_conn_getopt(
	    (void *) tcp, name, buf, szp, NNI_TYPE_OPAQUE));
}

int
nng_tcp_setopt(nng_tcp *tcp, const char *name, const void *buf, size_t sz)
{
	return (
	    nni_tcp_conn_setopt((void *) tcp, name, buf, sz, NNI_TYPE_OPAQUE));
}

int
nng_tcp_dialer_alloc(nng_tcp_dialer **dp)
{
	nni_tcp_dialer *d;
	int             rv;

	if ((rv = nni_init()) != 0) {
		return (rv);
	}
	if ((rv = nni_tcp_dialer_init(&d)) == 0) {
		*dp = (void *) d;
	}
	return (rv);
}

void
nng_tcp_dialer_close(nng_tcp_dialer *d)
{
	nni_tcp_dialer_close((void *) d);
}

void
nng_tcp_dialer_free(nng_tcp_dialer *d)
{
	nni_tcp_dialer_fini((void *) d);
}

void
nng_tcp_dialer_dial(nng_tcp_dialer *d, const nng_sockaddr *sa, nng_aio *aio)
{
	nni_tcp_dialer_dial((void *) d, sa, aio);
}

int
nng_tcp_listener_alloc(nng_tcp_listener **lp)
{
	nni_tcp_listener *l;
	int               rv;

	if ((rv = nni_init()) != 0) {
		return (rv);
	}
	if ((rv = nni_tcp_listener_init(&l)) == 0) {
		*lp = (void *) l;
	}
	return (rv);
}

void
nng_tcp_listener_close(nng_tcp_listener *l)
{
	nni_tcp_listener_close((void *) l);
}

void
nng_tcp_listener_free(nng_tcp_listener *l)
{
	nni_tcp_listener_fini((void *) l);
}

int
nng_tcp_listener_listen(nng_tcp_listener *l, nng_sockaddr *sa)
{
	return (nni_tcp_listener_listen((void *) l, sa));
}

void
nng_tcp_listener_accept(nng_tcp_listener *l, nng_aio *aio)
{
	nni_tcp_listener_accept((void *) l, aio);
}

int
nng_tcp_listener_getopt(
    nng_tcp_listener *l, const char *name, void *buf, size_t *szp)
{
	return (nni_tcp_listener_getopt(
	    (void *) l, name, buf, szp, NNI_TYPE_OPAQUE));
}

int
nng_tcp_listener_setopt(
    nng_tcp_listener *l, const char *name, const void *buf, size_t sz)
{
	return (nni_tcp_listener_setopt(
	    (void *) l, name, buf, sz, NNI_TYPE_OPAQUE));
}