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
|
= nng_socket(5)
//
// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This document 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.
//
== NAME
nng_socket - socket handle
== SYNOPSIS
[source, c]
----
#include <nng/nng.h>
typedef struct nng_socket_s nng_socket;
----
== DESCRIPTION
An `nng_socket`(((socket))) is a handle to an underlying "`socket`" object.
All communication between the application and remote Scalability Protocol
peers is done through sockets.
A given socket can have multiple dialers (`<<nng_dialer.5#,nng_dialer>>`)
and/or listeners (`<<nng_listener.5#,nng_listener>>`), and multiple
pipes (`<<nng_pipe.5#,nng_pipe>>`), and
may be connected to multiple transports at the same time.
However, a given socket will have exactly one "`protocol`" associated with it,
and is responsible for any state machines or other protocol-specific logic.
IMPORTANT: The `nng_socket` structure is always passed by value (both
for input parameters and return values), and should be treated opaquely.
Passing structures this way ensures gives the compiler a chance to perform
accurate type checks in functions passing values of this type.
Each `nng_socket` is created by a protocol-specific constructor, such as
`<<nng_rep_open.3#,nng_rep_open()>>`.
When the socket is no longer needed, it can be closed with
`<<nng_close.3#,nng_close()>>`.
[[NNG_SOCKET_INITIALIZER]]
=== Initialization
A socket may be initialized using the macro `NNG_SOCKET_INITIALIZER`
before it is opened, to prevent confusion with valid open sockets.
For example:
[source, c]
----
nng_socket s = NNG_SOCKET_INITIALIZER;
----
== SEE ALSO
<<libnng.3#,libnng(3)>>,
<<nng_close.3#,nng_close(3)>>,
<<nng_getopt.3#,nng_getopt(3)>>,
<<nng_setopt.3#,nng_setopt(3)>>,
<<nng_socket_id.3#,nng_socket_id(3)>>,
<<nng_dialer.5#,nng_dialer(5)>>,
<<nng_listener.5#,nng_listener(5)>>,
<<nng_options.5#,nng_options(5)>>,
<<nng.7#,nng(7)>>
|