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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
|
<!DOCTYPE HTML>
<html lang="en" class="light sidebar-visible" dir="ltr">
<head>
<!-- Book generated using mdBook -->
<meta charset="UTF-8">
<title>NNG Reference Manual (DRAFT)</title>
<meta name="robots" content="noindex">
<!-- Custom HTML head -->
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#ffffff">
<link rel="icon" href="favicon.svg">
<link rel="shortcut icon" href="favicon.png">
<link rel="stylesheet" href="css/variables.css">
<link rel="stylesheet" href="css/general.css">
<link rel="stylesheet" href="css/chrome.css">
<link rel="stylesheet" href="css/print.css" media="print">
<!-- Fonts -->
<link rel="stylesheet" href="FontAwesome/css/font-awesome.css">
<link rel="stylesheet" href="fonts/fonts.css">
<!-- Highlight.js Stylesheets -->
<link rel="stylesheet" href="highlight.css">
<link rel="stylesheet" href="tomorrow-night.css">
<link rel="stylesheet" href="ayu-highlight.css">
<!-- Custom theme stylesheets -->
<link rel="stylesheet" href="theme/pagetoc.css">
<!-- Provide site root to javascript -->
<script>
var path_to_root = "";
var default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "navy" : "light";
</script>
<!-- Start loading toc.js asap -->
<script src="toc.js"></script>
</head>
<body>
<div id="body-container">
<!-- Work around some values being stored in localStorage wrapped in quotes -->
<script>
try {
var theme = localStorage.getItem('mdbook-theme');
var sidebar = localStorage.getItem('mdbook-sidebar');
if (theme.startsWith('"') && theme.endsWith('"')) {
localStorage.setItem('mdbook-theme', theme.slice(1, theme.length - 1));
}
if (sidebar.startsWith('"') && sidebar.endsWith('"')) {
localStorage.setItem('mdbook-sidebar', sidebar.slice(1, sidebar.length - 1));
}
} catch (e) { }
</script>
<!-- Set the theme before any content is loaded, prevents flash -->
<script>
var theme;
try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
if (theme === null || theme === undefined) { theme = default_theme; }
const html = document.documentElement;
html.classList.remove('light')
html.classList.add(theme);
html.classList.add("js");
</script>
<input type="checkbox" id="sidebar-toggle-anchor" class="hidden">
<!-- Hide / unhide sidebar before it is displayed -->
<script>
var sidebar = null;
var sidebar_toggle = document.getElementById("sidebar-toggle-anchor");
if (document.body.clientWidth >= 1080) {
try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
sidebar = sidebar || 'visible';
} else {
sidebar = 'hidden';
}
sidebar_toggle.checked = sidebar === 'visible';
html.classList.remove('sidebar-visible');
html.classList.add("sidebar-" + sidebar);
</script>
<nav id="sidebar" class="sidebar" aria-label="Table of contents">
<!-- populated by js -->
<mdbook-sidebar-scrollbox class="sidebar-scrollbox"></mdbook-sidebar-scrollbox>
<noscript>
<iframe class="sidebar-iframe-outer" src="toc.html"></iframe>
</noscript>
<div id="sidebar-resize-handle" class="sidebar-resize-handle">
<div class="sidebar-resize-indicator"></div>
</div>
</nav>
<div id="page-wrapper" class="page-wrapper">
<div class="page">
<div id="menu-bar-hover-placeholder"></div>
<div id="menu-bar" class="menu-bar sticky">
<div class="left-buttons">
<label id="sidebar-toggle" class="icon-button" for="sidebar-toggle-anchor" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar">
<i class="fa fa-bars"></i>
</label>
<button id="theme-toggle" class="icon-button" type="button" title="Change theme" aria-label="Change theme" aria-haspopup="true" aria-expanded="false" aria-controls="theme-list">
<i class="fa fa-paint-brush"></i>
</button>
<ul id="theme-list" class="theme-popup" aria-label="Themes" role="menu">
<li role="none"><button role="menuitem" class="theme" id="light">Light</button></li>
<li role="none"><button role="menuitem" class="theme" id="rust">Rust</button></li>
<li role="none"><button role="menuitem" class="theme" id="coal">Coal</button></li>
<li role="none"><button role="menuitem" class="theme" id="navy">Navy</button></li>
<li role="none"><button role="menuitem" class="theme" id="ayu">Ayu</button></li>
</ul>
<button id="search-toggle" class="icon-button" type="button" title="Search. (Shortkey: s)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="S" aria-controls="searchbar">
<i class="fa fa-search"></i>
</button>
</div>
<h1 class="menu-title">NNG Reference Manual (DRAFT)</h1>
<div class="right-buttons">
<a href="print.html" title="Print this book" aria-label="Print this book">
<i id="print-button" class="fa fa-print"></i>
</a>
</div>
</div>
<div id="search-wrapper" class="hidden">
<form id="searchbar-outer" class="searchbar-outer">
<input type="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
</form>
<div id="searchresults-outer" class="searchresults-outer hidden">
<div id="searchresults-header" class="searchresults-header"></div>
<ul id="searchresults">
</ul>
</div>
</div>
<!-- Apply ARIA attributes after the sidebar and the sidebar toggle button are added to the DOM -->
<script>
document.getElementById('sidebar-toggle').setAttribute('aria-expanded', sidebar === 'visible');
document.getElementById('sidebar').setAttribute('aria-hidden', sidebar !== 'visible');
Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) {
link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1);
});
</script>
<div id="content" class="content">
<main>
<style>
.mdbook-alerts {
padding: 8px 16px;
margin-bottom: 16px;
border-left: 0.25em solid var(--mdbook-alerts-color);
}
.mdbook-alerts > *:first-child {
margin-top: 0;
}
.mdbook-alerts > *:last-child {
margin-bottom: 0;
}
.mdbook-alerts-title {
display: flex;
font-weight: 600;
align-items: center;
line-height: 1;
color: var(--mdbook-alerts-color);
text-transform: capitalize;
}
.mdbook-alerts-icon {
display: inline-block;
width: 1em;
height: 1em;
margin-right: 0.2em;
background-color: currentColor;
-webkit-mask: no-repeat center / 100%;
mask: no-repeat center / 100%;
-webkit-mask-image: var(--mdbook-alerts-icon);
mask-image: var(--mdbook-alerts-icon);
}
.mdbook-alerts-note {
--mdbook-alerts-color: rgb(9, 105, 218);
/* https://icon-sets.iconify.design/material-symbols/info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16v-4q0-.425-.288-.712T12 11q-.425 0-.712.288T11 12v4q0 .425.288.713T12 17m0-8q.425 0 .713-.288T13 8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8q0 .425.288.713T12 9m0 13q-2.075 0-3.9-.788t-3.175-2.137q-1.35-1.35-2.137-3.175T2 12q0-2.075.788-3.9t2.137-3.175q1.35-1.35 3.175-2.137T12 2q2.075 0 3.9.788t3.175 2.137q1.35 1.35 2.138 3.175T22 12q0 2.075-.788 3.9t-2.137 3.175q-1.35 1.35-3.175 2.138T12 22m0-2q3.35 0 5.675-2.325T20 12q0-3.35-2.325-5.675T12 4Q8.65 4 6.325 6.325T4 12q0 3.35 2.325 5.675T12 20m0-8"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-tip {
--mdbook-alerts-color: rgb(26, 127, 55);
/* https://icon-sets.iconify.design/material-symbols/lightbulb-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 22q-.825 0-1.412-.587T10 20h4q0 .825-.587 1.413T12 22m-3-3q-.425 0-.712-.288T8 18q0-.425.288-.712T9 17h6q.425 0 .713.288T16 18q0 .425-.288.713T15 19zm-.75-3q-1.725-1.025-2.738-2.75T4.5 9.5q0-3.125 2.188-5.312T12 2q3.125 0 5.313 2.188T19.5 9.5q0 2.025-1.012 3.75T15.75 16zm.6-2h6.3q1.125-.8 1.738-1.975T17.5 9.5q0-2.3-1.6-3.9T12 4Q9.7 4 8.1 5.6T6.5 9.5q0 1.35.613 2.525T8.85 14M12 14"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-important {
--mdbook-alerts-color: rgb(130, 80, 223);
/* https://icon-sets.iconify.design/material-symbols/chat-info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 7q.425 0 .713-.288T13 6q0-.425-.288-.712T12 5q-.425 0-.712.288T11 6q0 .425.288.713T12 7m0 8q.425 0 .713-.288T13 14v-4q0-.425-.288-.712T12 9q-.425 0-.712.288T11 10v4q0 .425.288.713T12 15m-6 3l-2.3 2.3q-.475.475-1.088.213T2 19.575V4q0-.825.588-1.412T4 2h16q.825 0 1.413.588T22 4v12q0 .825-.587 1.413T20 18zm-.85-2H20V4H4v13.125zM4 16V4z"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-warning {
--mdbook-alerts-color: rgb(154, 103, 0);
/* https://icon-sets.iconify.design/material-symbols/warning-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M2.725 21q-.275 0-.5-.137t-.35-.363q-.125-.225-.137-.488t.137-.512l9.25-16q.15-.25.388-.375T12 3q.25 0 .488.125t.387.375l9.25 16q.15.25.138.513t-.138.487q-.125.225-.35.363t-.5.137zm1.725-2h15.1L12 6zM12 18q.425 0 .713-.288T13 17q0-.425-.288-.712T12 16q-.425 0-.712.288T11 17q0 .425.288.713T12 18m0-3q.425 0 .713-.288T13 14v-3q0-.425-.288-.712T12 10q-.425 0-.712.288T11 11v3q0 .425.288.713T12 15m0-2.5"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-caution {
--mdbook-alerts-color: rgb(207, 34, 46);
/* https://icon-sets.iconify.design/material-symbols/brightness-alert-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16q0-.425-.288-.712T12 15q-.425 0-.712.288T11 16q0 .425.288.713T12 17m0-4q.425 0 .713-.288T13 12V8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8v4q0 .425.288.713T12 13m-3.35 7H6q-.825 0-1.412-.587T4 18v-2.65L2.075 13.4q-.275-.3-.425-.662T1.5 12q0-.375.15-.737t.425-.663L4 8.65V6q0-.825.588-1.412T6 4h2.65l1.95-1.925q.3-.275.663-.425T12 1.5q.375 0 .738.15t.662.425L15.35 4H18q.825 0 1.413.588T20 6v2.65l1.925 1.95q.275.3.425.663t.15.737q0 .375-.15.738t-.425.662L20 15.35V18q0 .825-.587 1.413T18 20h-2.65l-1.95 1.925q-.3.275-.662.425T12 22.5q-.375 0-.737-.15t-.663-.425zm.85-2l2.5 2.5l2.5-2.5H18v-3.5l2.5-2.5L18 9.5V6h-3.5L12 3.5L9.5 6H6v3.5L3.5 12L6 14.5V18zm2.5-6"%2F%3E%3C%2Fsvg%3E');
}
</style>
<img class="right" height="50px" src="./img/staysail-bw-trans.svg">
<p>Copyright © 2024 Staysail Systems, Inc.<br />
San Marcos, California, United States of America</p>
<blockquote>
<p>If you find this book or NNG useful, please consider sponsoring
the project.</p>
</blockquote>
<div class="mdbook-alerts mdbook-alerts-tip">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
tip
</p>
<p>This book is a work in progress, adapted from earlier sources
and updated for the current version of NNG.</p>
</div>
<div class="mdbook-alerts mdbook-alerts-note">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
note
</p>
<blockquote>
<p>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), and reproduced below.</p>
</blockquote>
<blockquote>
<p>Third party contributions to this document were made under the
same license terms, and may be covered under one of the following
copyrights:</p>
<ul>
<li>Copyright 2018 Capitar IT Group BV.</li>
<li>Copyright 2019 Devolutions.</li>
<li>Copyright 2020 Dirac Research.</li>
</ul>
</blockquote>
</div>
<h2 id="the-mit-license"><a class="header" href="#the-mit-license">The MIT License</a></h2>
<p>Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom
the Software is furnished to do so, subject to the following conditions:</p>
<p>The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.</p>
<p>THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.</p>
<div style="break-before: page; page-break-before: always;"></div><style>
.mdbook-alerts {
padding: 8px 16px;
margin-bottom: 16px;
border-left: 0.25em solid var(--mdbook-alerts-color);
}
.mdbook-alerts > *:first-child {
margin-top: 0;
}
.mdbook-alerts > *:last-child {
margin-bottom: 0;
}
.mdbook-alerts-title {
display: flex;
font-weight: 600;
align-items: center;
line-height: 1;
color: var(--mdbook-alerts-color);
text-transform: capitalize;
}
.mdbook-alerts-icon {
display: inline-block;
width: 1em;
height: 1em;
margin-right: 0.2em;
background-color: currentColor;
-webkit-mask: no-repeat center / 100%;
mask: no-repeat center / 100%;
-webkit-mask-image: var(--mdbook-alerts-icon);
mask-image: var(--mdbook-alerts-icon);
}
.mdbook-alerts-note {
--mdbook-alerts-color: rgb(9, 105, 218);
/* https://icon-sets.iconify.design/material-symbols/info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16v-4q0-.425-.288-.712T12 11q-.425 0-.712.288T11 12v4q0 .425.288.713T12 17m0-8q.425 0 .713-.288T13 8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8q0 .425.288.713T12 9m0 13q-2.075 0-3.9-.788t-3.175-2.137q-1.35-1.35-2.137-3.175T2 12q0-2.075.788-3.9t2.137-3.175q1.35-1.35 3.175-2.137T12 2q2.075 0 3.9.788t3.175 2.137q1.35 1.35 2.138 3.175T22 12q0 2.075-.788 3.9t-2.137 3.175q-1.35 1.35-3.175 2.138T12 22m0-2q3.35 0 5.675-2.325T20 12q0-3.35-2.325-5.675T12 4Q8.65 4 6.325 6.325T4 12q0 3.35 2.325 5.675T12 20m0-8"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-tip {
--mdbook-alerts-color: rgb(26, 127, 55);
/* https://icon-sets.iconify.design/material-symbols/lightbulb-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 22q-.825 0-1.412-.587T10 20h4q0 .825-.587 1.413T12 22m-3-3q-.425 0-.712-.288T8 18q0-.425.288-.712T9 17h6q.425 0 .713.288T16 18q0 .425-.288.713T15 19zm-.75-3q-1.725-1.025-2.738-2.75T4.5 9.5q0-3.125 2.188-5.312T12 2q3.125 0 5.313 2.188T19.5 9.5q0 2.025-1.012 3.75T15.75 16zm.6-2h6.3q1.125-.8 1.738-1.975T17.5 9.5q0-2.3-1.6-3.9T12 4Q9.7 4 8.1 5.6T6.5 9.5q0 1.35.613 2.525T8.85 14M12 14"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-important {
--mdbook-alerts-color: rgb(130, 80, 223);
/* https://icon-sets.iconify.design/material-symbols/chat-info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 7q.425 0 .713-.288T13 6q0-.425-.288-.712T12 5q-.425 0-.712.288T11 6q0 .425.288.713T12 7m0 8q.425 0 .713-.288T13 14v-4q0-.425-.288-.712T12 9q-.425 0-.712.288T11 10v4q0 .425.288.713T12 15m-6 3l-2.3 2.3q-.475.475-1.088.213T2 19.575V4q0-.825.588-1.412T4 2h16q.825 0 1.413.588T22 4v12q0 .825-.587 1.413T20 18zm-.85-2H20V4H4v13.125zM4 16V4z"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-warning {
--mdbook-alerts-color: rgb(154, 103, 0);
/* https://icon-sets.iconify.design/material-symbols/warning-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M2.725 21q-.275 0-.5-.137t-.35-.363q-.125-.225-.137-.488t.137-.512l9.25-16q.15-.25.388-.375T12 3q.25 0 .488.125t.387.375l9.25 16q.15.25.138.513t-.138.487q-.125.225-.35.363t-.5.137zm1.725-2h15.1L12 6zM12 18q.425 0 .713-.288T13 17q0-.425-.288-.712T12 16q-.425 0-.712.288T11 17q0 .425.288.713T12 18m0-3q.425 0 .713-.288T13 14v-3q0-.425-.288-.712T12 10q-.425 0-.712.288T11 11v3q0 .425.288.713T12 15m0-2.5"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-caution {
--mdbook-alerts-color: rgb(207, 34, 46);
/* https://icon-sets.iconify.design/material-symbols/brightness-alert-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16q0-.425-.288-.712T12 15q-.425 0-.712.288T11 16q0 .425.288.713T12 17m0-4q.425 0 .713-.288T13 12V8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8v4q0 .425.288.713T12 13m-3.35 7H6q-.825 0-1.412-.587T4 18v-2.65L2.075 13.4q-.275-.3-.425-.662T1.5 12q0-.375.15-.737t.425-.663L4 8.65V6q0-.825.588-1.412T6 4h2.65l1.95-1.925q.3-.275.663-.425T12 1.5q.375 0 .738.15t.662.425L15.35 4H18q.825 0 1.413.588T20 6v2.65l1.925 1.95q.275.3.425.663t.15.737q0 .375-.15.738t-.425.662L20 15.35V18q0 .825-.587 1.413T18 20h-2.65l-1.95 1.925q-.3.275-.662.425T12 22.5q-.375 0-.737-.15t-.663-.425zm.85-2l2.5 2.5l2.5-2.5H18v-3.5l2.5-2.5L18 9.5V6h-3.5L12 3.5L9.5 6H6v3.5L3.5 12L6 14.5V18zm2.5-6"%2F%3E%3C%2Fsvg%3E');
}
</style>
<h1 id="dedication"><a class="header" href="#dedication">Dedication</a></h1>
<p>— <em>For Jenichka</em></p>
<p><em>The sun always shines when you are home.</em></p>
<div style="break-before: page; page-break-before: always;"></div><style>
.mdbook-alerts {
padding: 8px 16px;
margin-bottom: 16px;
border-left: 0.25em solid var(--mdbook-alerts-color);
}
.mdbook-alerts > *:first-child {
margin-top: 0;
}
.mdbook-alerts > *:last-child {
margin-bottom: 0;
}
.mdbook-alerts-title {
display: flex;
font-weight: 600;
align-items: center;
line-height: 1;
color: var(--mdbook-alerts-color);
text-transform: capitalize;
}
.mdbook-alerts-icon {
display: inline-block;
width: 1em;
height: 1em;
margin-right: 0.2em;
background-color: currentColor;
-webkit-mask: no-repeat center / 100%;
mask: no-repeat center / 100%;
-webkit-mask-image: var(--mdbook-alerts-icon);
mask-image: var(--mdbook-alerts-icon);
}
.mdbook-alerts-note {
--mdbook-alerts-color: rgb(9, 105, 218);
/* https://icon-sets.iconify.design/material-symbols/info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16v-4q0-.425-.288-.712T12 11q-.425 0-.712.288T11 12v4q0 .425.288.713T12 17m0-8q.425 0 .713-.288T13 8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8q0 .425.288.713T12 9m0 13q-2.075 0-3.9-.788t-3.175-2.137q-1.35-1.35-2.137-3.175T2 12q0-2.075.788-3.9t2.137-3.175q1.35-1.35 3.175-2.137T12 2q2.075 0 3.9.788t3.175 2.137q1.35 1.35 2.138 3.175T22 12q0 2.075-.788 3.9t-2.137 3.175q-1.35 1.35-3.175 2.138T12 22m0-2q3.35 0 5.675-2.325T20 12q0-3.35-2.325-5.675T12 4Q8.65 4 6.325 6.325T4 12q0 3.35 2.325 5.675T12 20m0-8"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-tip {
--mdbook-alerts-color: rgb(26, 127, 55);
/* https://icon-sets.iconify.design/material-symbols/lightbulb-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 22q-.825 0-1.412-.587T10 20h4q0 .825-.587 1.413T12 22m-3-3q-.425 0-.712-.288T8 18q0-.425.288-.712T9 17h6q.425 0 .713.288T16 18q0 .425-.288.713T15 19zm-.75-3q-1.725-1.025-2.738-2.75T4.5 9.5q0-3.125 2.188-5.312T12 2q3.125 0 5.313 2.188T19.5 9.5q0 2.025-1.012 3.75T15.75 16zm.6-2h6.3q1.125-.8 1.738-1.975T17.5 9.5q0-2.3-1.6-3.9T12 4Q9.7 4 8.1 5.6T6.5 9.5q0 1.35.613 2.525T8.85 14M12 14"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-important {
--mdbook-alerts-color: rgb(130, 80, 223);
/* https://icon-sets.iconify.design/material-symbols/chat-info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 7q.425 0 .713-.288T13 6q0-.425-.288-.712T12 5q-.425 0-.712.288T11 6q0 .425.288.713T12 7m0 8q.425 0 .713-.288T13 14v-4q0-.425-.288-.712T12 9q-.425 0-.712.288T11 10v4q0 .425.288.713T12 15m-6 3l-2.3 2.3q-.475.475-1.088.213T2 19.575V4q0-.825.588-1.412T4 2h16q.825 0 1.413.588T22 4v12q0 .825-.587 1.413T20 18zm-.85-2H20V4H4v13.125zM4 16V4z"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-warning {
--mdbook-alerts-color: rgb(154, 103, 0);
/* https://icon-sets.iconify.design/material-symbols/warning-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M2.725 21q-.275 0-.5-.137t-.35-.363q-.125-.225-.137-.488t.137-.512l9.25-16q.15-.25.388-.375T12 3q.25 0 .488.125t.387.375l9.25 16q.15.25.138.513t-.138.487q-.125.225-.35.363t-.5.137zm1.725-2h15.1L12 6zM12 18q.425 0 .713-.288T13 17q0-.425-.288-.712T12 16q-.425 0-.712.288T11 17q0 .425.288.713T12 18m0-3q.425 0 .713-.288T13 14v-3q0-.425-.288-.712T12 10q-.425 0-.712.288T11 11v3q0 .425.288.713T12 15m0-2.5"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-caution {
--mdbook-alerts-color: rgb(207, 34, 46);
/* https://icon-sets.iconify.design/material-symbols/brightness-alert-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16q0-.425-.288-.712T12 15q-.425 0-.712.288T11 16q0 .425.288.713T12 17m0-4q.425 0 .713-.288T13 12V8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8v4q0 .425.288.713T12 13m-3.35 7H6q-.825 0-1.412-.587T4 18v-2.65L2.075 13.4q-.275-.3-.425-.662T1.5 12q0-.375.15-.737t.425-.663L4 8.65V6q0-.825.588-1.412T6 4h2.65l1.95-1.925q.3-.275.663-.425T12 1.5q.375 0 .738.15t.662.425L15.35 4H18q.825 0 1.413.588T20 6v2.65l1.925 1.95q.275.3.425.663t.15.737q0 .375-.15.738t-.425.662L20 15.35V18q0 .825-.587 1.413T18 20h-2.65l-1.95 1.925q-.3.275-.662.425T12 22.5q-.375 0-.737-.15t-.663-.425zm.85-2l2.5 2.5l2.5-2.5H18v-3.5l2.5-2.5L18 9.5V6h-3.5L12 3.5L9.5 6H6v3.5L3.5 12L6 14.5V18zm2.5-6"%2F%3E%3C%2Fsvg%3E');
}
</style>
<h1 id="preface"><a class="header" href="#preface">Preface</a></h1>
<div class="mdbook-alerts mdbook-alerts-important">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
important
</p>
<p>This is a <em>DRAFT</em> version of this reference manual,
and much is still in progress. There may be errors,
and large omissions as content is still be moved from
the previous ASCIIDOCTOR format and updated for NNG 2.0.</p>
</div>
<h2 id="preface-for-the-first-edition"><a class="header" href="#preface-for-the-first-edition">Preface for the First Edition</a></h2>
<p>At the time of this writing, we are wrapping up NNG for its formal
1.0.0 release.
It’s a good time for reflection on the road that we took to get here.
Like the road on the cover of this book, it was windy (if quite a bit longer),
but what we find at the end has made the journey worthwhile.</p>
<p>Originally the NNG project was conceived as a relatively modest effort
to rewrite nanomsg based on threads, with a more readily extensible
internal architecture so that we could more easily undertake projects like the
ZeroTier and TLS transports.</p>
<p>It would not be incorrect to say that the initial NNG effort was started
in “anger”, as we were frustrated with nanomsg’s very complex internal
state machines.
Looking back on it now, those complex state state machines don’t seem nearly
as insane as they did just a year ago.</p>
<p>The simple, naïve, approach we would have preferred, and the one we
originally started with, involved significant use of threads, inspired by the
work we did in mangos, which uses Go’s goroutines heavily.
Goroutines are excellent.
Threads, it turns out, are not.
Scalable, asynchronous, <em>portable</em> I/O is a lot harder than it looks.</p>
<blockquote>
<p>Our experience with in-kernel threads on illumos and Solaris
spoiled us, and left us utterly unprepared for cesspool that really is
large amounts of userspace programming.</p>
</blockquote>
<p>Instead, we have created our own, completely asynchronous core, giving
us advanced multiprocessing and concurrency capabilities, without either
sacrificing portability or settling for some unhappy least common denominator.
This core is a robust foundation for NNG and handling the
“Scalability Protocols”, but if we’re being completely honest, we think this
core has braod applicability for beyond just the Scalability Protocols.
It will be interesting to see if others come to the same conclusion.</p>
<p>Builting upon this robust foundation, we have engineered a substantial
project, with capabilities far in exceess of the original nanomsg, while
still preserving compatibility with the the network protocols that
form the backbone of the nanomsg ecosystem,
and even a compatible programming interface for nanomsg library users.
In addition to compatibility with nanomsg, we find that NNG has greatly
increased scalability, reliability, and usability (especially when developing
concurrent applications).</p>
<p>NNG also has complete HTTP server and client
implementations, support for TLS, and a plethora of other capabilities.
Much of this is made possible by a the aforementioned asynchronous I/O
framework.</p>
<p>We’ve tried to stay true to the core nanomsg goals about being light-weight,
liberally licensed, and implemented in C.
(After all, those were the things that drew us to nanomsg in the first place!)
In addition we added a couple of new ones.
Specifically, reliability, performance, and extensibility (in that order)
were added as core goals for the project.</p>
<p>We believe that NNG represents a substantial step forward over other
messaging frameworks, and have enjoyed creating it.
We hope you find it useful.
There is still a lot more we want to do, and future release of NNG
will continue to expand it’s capabilities.
We’re just getting started.</p>
<p><strong>— Garrett D’Amore</strong>, May 30, 2018</p>
<h2 id="acknowledgements"><a class="header" href="#acknowledgements">Acknowledgements</a></h2>
<p>We would like to thank Janjaap Bos, at Capitar IT Group BV.
Without his patronage, neither NNG nor this book would be possible.</p>
<p>We would also like thank Martin Sústrik for creating the original
nanomsg project, the foundation upon which all of this work is based.</p>
<p>And certainly not least of all, we would like to thank the various
members of the community who have followed
and supported the NNG project in so many different ways.</p>
<h3 id="conventions"><a class="header" href="#conventions">Conventions</a></h3>
<p>Throughout this book there are occasional warnings, notices, and tips.
These are visually distinguished as follows:</p>
<div class="mdbook-alerts mdbook-alerts-tip">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
tip
</p>
<p>Tips are things that the reader may find useful, such as suggestions
for use or tim saving hints.</p>
</div>
<div class="mdbook-alerts mdbook-alerts-note">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
note
</p>
<p>Notes are things that the reader should be aware of, and provide
additional information or context that may aid in the understanding
or use of the topic.</p>
</div>
<div class="mdbook-alerts mdbook-alerts-important">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
important
</p>
<p>Warnings are used to denote important cautionary advice,
which should be carefully heeded.
Ignoring such advice may lead to crashses, unexpected behavior,
loss of revenue, or other undesirable conditions.</p>
</div>
<div style="break-before: page; page-break-before: always;"></div><style>
.mdbook-alerts {
padding: 8px 16px;
margin-bottom: 16px;
border-left: 0.25em solid var(--mdbook-alerts-color);
}
.mdbook-alerts > *:first-child {
margin-top: 0;
}
.mdbook-alerts > *:last-child {
margin-bottom: 0;
}
.mdbook-alerts-title {
display: flex;
font-weight: 600;
align-items: center;
line-height: 1;
color: var(--mdbook-alerts-color);
text-transform: capitalize;
}
.mdbook-alerts-icon {
display: inline-block;
width: 1em;
height: 1em;
margin-right: 0.2em;
background-color: currentColor;
-webkit-mask: no-repeat center / 100%;
mask: no-repeat center / 100%;
-webkit-mask-image: var(--mdbook-alerts-icon);
mask-image: var(--mdbook-alerts-icon);
}
.mdbook-alerts-note {
--mdbook-alerts-color: rgb(9, 105, 218);
/* https://icon-sets.iconify.design/material-symbols/info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16v-4q0-.425-.288-.712T12 11q-.425 0-.712.288T11 12v4q0 .425.288.713T12 17m0-8q.425 0 .713-.288T13 8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8q0 .425.288.713T12 9m0 13q-2.075 0-3.9-.788t-3.175-2.137q-1.35-1.35-2.137-3.175T2 12q0-2.075.788-3.9t2.137-3.175q1.35-1.35 3.175-2.137T12 2q2.075 0 3.9.788t3.175 2.137q1.35 1.35 2.138 3.175T22 12q0 2.075-.788 3.9t-2.137 3.175q-1.35 1.35-3.175 2.138T12 22m0-2q3.35 0 5.675-2.325T20 12q0-3.35-2.325-5.675T12 4Q8.65 4 6.325 6.325T4 12q0 3.35 2.325 5.675T12 20m0-8"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-tip {
--mdbook-alerts-color: rgb(26, 127, 55);
/* https://icon-sets.iconify.design/material-symbols/lightbulb-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 22q-.825 0-1.412-.587T10 20h4q0 .825-.587 1.413T12 22m-3-3q-.425 0-.712-.288T8 18q0-.425.288-.712T9 17h6q.425 0 .713.288T16 18q0 .425-.288.713T15 19zm-.75-3q-1.725-1.025-2.738-2.75T4.5 9.5q0-3.125 2.188-5.312T12 2q3.125 0 5.313 2.188T19.5 9.5q0 2.025-1.012 3.75T15.75 16zm.6-2h6.3q1.125-.8 1.738-1.975T17.5 9.5q0-2.3-1.6-3.9T12 4Q9.7 4 8.1 5.6T6.5 9.5q0 1.35.613 2.525T8.85 14M12 14"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-important {
--mdbook-alerts-color: rgb(130, 80, 223);
/* https://icon-sets.iconify.design/material-symbols/chat-info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 7q.425 0 .713-.288T13 6q0-.425-.288-.712T12 5q-.425 0-.712.288T11 6q0 .425.288.713T12 7m0 8q.425 0 .713-.288T13 14v-4q0-.425-.288-.712T12 9q-.425 0-.712.288T11 10v4q0 .425.288.713T12 15m-6 3l-2.3 2.3q-.475.475-1.088.213T2 19.575V4q0-.825.588-1.412T4 2h16q.825 0 1.413.588T22 4v12q0 .825-.587 1.413T20 18zm-.85-2H20V4H4v13.125zM4 16V4z"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-warning {
--mdbook-alerts-color: rgb(154, 103, 0);
/* https://icon-sets.iconify.design/material-symbols/warning-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M2.725 21q-.275 0-.5-.137t-.35-.363q-.125-.225-.137-.488t.137-.512l9.25-16q.15-.25.388-.375T12 3q.25 0 .488.125t.387.375l9.25 16q.15.25.138.513t-.138.487q-.125.225-.35.363t-.5.137zm1.725-2h15.1L12 6zM12 18q.425 0 .713-.288T13 17q0-.425-.288-.712T12 16q-.425 0-.712.288T11 17q0 .425.288.713T12 18m0-3q.425 0 .713-.288T13 14v-3q0-.425-.288-.712T12 10q-.425 0-.712.288T11 11v3q0 .425.288.713T12 15m0-2.5"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-caution {
--mdbook-alerts-color: rgb(207, 34, 46);
/* https://icon-sets.iconify.design/material-symbols/brightness-alert-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16q0-.425-.288-.712T12 15q-.425 0-.712.288T11 16q0 .425.288.713T12 17m0-4q.425 0 .713-.288T13 12V8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8v4q0 .425.288.713T12 13m-3.35 7H6q-.825 0-1.412-.587T4 18v-2.65L2.075 13.4q-.275-.3-.425-.662T1.5 12q0-.375.15-.737t.425-.663L4 8.65V6q0-.825.588-1.412T6 4h2.65l1.95-1.925q.3-.275.663-.425T12 1.5q.375 0 .738.15t.662.425L15.35 4H18q.825 0 1.413.588T20 6v2.65l1.925 1.95q.275.3.425.663t.15.737q0 .375-.15.738t-.425.662L20 15.35V18q0 .825-.587 1.413T18 20h-2.65l-1.95 1.925q-.3.275-.662.425T12 22.5q-.375 0-.737-.15t-.663-.425zm.85-2l2.5 2.5l2.5-2.5H18v-3.5l2.5-2.5L18 9.5V6h-3.5L12 3.5L9.5 6H6v3.5L3.5 12L6 14.5V18zm2.5-6"%2F%3E%3C%2Fsvg%3E');
}
</style>
<h1 id="api-reference"><a class="header" href="#api-reference">API Reference</a></h1>
<p>This section is a reference guide for the <em>NNG</em> programming interfaces.
It is meant to serve as a refernce, rather than as a tutorial.</p>
<p>The material here is organized by major areas of functionality.</p>
<p>Note that unless indicated otherwise, consumers of these interfaces must
include the <code>nng/nng.h</code> header file like so:</p>
<pre><code class="language-c">#include <nng/nng.h>
</code></pre>
<h2 id="chapters"><a class="header" href="#chapters">Chapters</a></h2>
<ul>
<li><a href="api/msg/">Messages</a></li>
<li><a href="api/thr/">Threading and Synchronization</a></li>
<li><a href="api/logging.html">Logging</a></li>
<li><a href="api/util/">Utility Functions</a></li>
</ul>
<div style="break-before: page; page-break-before: always;"></div><style>
.mdbook-alerts {
padding: 8px 16px;
margin-bottom: 16px;
border-left: 0.25em solid var(--mdbook-alerts-color);
}
.mdbook-alerts > *:first-child {
margin-top: 0;
}
.mdbook-alerts > *:last-child {
margin-bottom: 0;
}
.mdbook-alerts-title {
display: flex;
font-weight: 600;
align-items: center;
line-height: 1;
color: var(--mdbook-alerts-color);
text-transform: capitalize;
}
.mdbook-alerts-icon {
display: inline-block;
width: 1em;
height: 1em;
margin-right: 0.2em;
background-color: currentColor;
-webkit-mask: no-repeat center / 100%;
mask: no-repeat center / 100%;
-webkit-mask-image: var(--mdbook-alerts-icon);
mask-image: var(--mdbook-alerts-icon);
}
.mdbook-alerts-note {
--mdbook-alerts-color: rgb(9, 105, 218);
/* https://icon-sets.iconify.design/material-symbols/info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16v-4q0-.425-.288-.712T12 11q-.425 0-.712.288T11 12v4q0 .425.288.713T12 17m0-8q.425 0 .713-.288T13 8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8q0 .425.288.713T12 9m0 13q-2.075 0-3.9-.788t-3.175-2.137q-1.35-1.35-2.137-3.175T2 12q0-2.075.788-3.9t2.137-3.175q1.35-1.35 3.175-2.137T12 2q2.075 0 3.9.788t3.175 2.137q1.35 1.35 2.138 3.175T22 12q0 2.075-.788 3.9t-2.137 3.175q-1.35 1.35-3.175 2.138T12 22m0-2q3.35 0 5.675-2.325T20 12q0-3.35-2.325-5.675T12 4Q8.65 4 6.325 6.325T4 12q0 3.35 2.325 5.675T12 20m0-8"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-tip {
--mdbook-alerts-color: rgb(26, 127, 55);
/* https://icon-sets.iconify.design/material-symbols/lightbulb-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 22q-.825 0-1.412-.587T10 20h4q0 .825-.587 1.413T12 22m-3-3q-.425 0-.712-.288T8 18q0-.425.288-.712T9 17h6q.425 0 .713.288T16 18q0 .425-.288.713T15 19zm-.75-3q-1.725-1.025-2.738-2.75T4.5 9.5q0-3.125 2.188-5.312T12 2q3.125 0 5.313 2.188T19.5 9.5q0 2.025-1.012 3.75T15.75 16zm.6-2h6.3q1.125-.8 1.738-1.975T17.5 9.5q0-2.3-1.6-3.9T12 4Q9.7 4 8.1 5.6T6.5 9.5q0 1.35.613 2.525T8.85 14M12 14"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-important {
--mdbook-alerts-color: rgb(130, 80, 223);
/* https://icon-sets.iconify.design/material-symbols/chat-info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 7q.425 0 .713-.288T13 6q0-.425-.288-.712T12 5q-.425 0-.712.288T11 6q0 .425.288.713T12 7m0 8q.425 0 .713-.288T13 14v-4q0-.425-.288-.712T12 9q-.425 0-.712.288T11 10v4q0 .425.288.713T12 15m-6 3l-2.3 2.3q-.475.475-1.088.213T2 19.575V4q0-.825.588-1.412T4 2h16q.825 0 1.413.588T22 4v12q0 .825-.587 1.413T20 18zm-.85-2H20V4H4v13.125zM4 16V4z"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-warning {
--mdbook-alerts-color: rgb(154, 103, 0);
/* https://icon-sets.iconify.design/material-symbols/warning-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M2.725 21q-.275 0-.5-.137t-.35-.363q-.125-.225-.137-.488t.137-.512l9.25-16q.15-.25.388-.375T12 3q.25 0 .488.125t.387.375l9.25 16q.15.25.138.513t-.138.487q-.125.225-.35.363t-.5.137zm1.725-2h15.1L12 6zM12 18q.425 0 .713-.288T13 17q0-.425-.288-.712T12 16q-.425 0-.712.288T11 17q0 .425.288.713T12 18m0-3q.425 0 .713-.288T13 14v-3q0-.425-.288-.712T12 10q-.425 0-.712.288T11 11v3q0 .425.288.713T12 15m0-2.5"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-caution {
--mdbook-alerts-color: rgb(207, 34, 46);
/* https://icon-sets.iconify.design/material-symbols/brightness-alert-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16q0-.425-.288-.712T12 15q-.425 0-.712.288T11 16q0 .425.288.713T12 17m0-4q.425 0 .713-.288T13 12V8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8v4q0 .425.288.713T12 13m-3.35 7H6q-.825 0-1.412-.587T4 18v-2.65L2.075 13.4q-.275-.3-.425-.662T1.5 12q0-.375.15-.737t.425-.663L4 8.65V6q0-.825.588-1.412T6 4h2.65l1.95-1.925q.3-.275.663-.425T12 1.5q.375 0 .738.15t.662.425L15.35 4H18q.825 0 1.413.588T20 6v2.65l1.925 1.95q.275.3.425.663t.15.737q0 .375-.15.738t-.425.662L20 15.35V18q0 .825-.587 1.413T18 20h-2.65l-1.95 1.925q-.3.275-.662.425T12 22.5q-.375 0-.737-.15t-.663-.425zm.85-2l2.5 2.5l2.5-2.5H18v-3.5l2.5-2.5L18 9.5V6h-3.5L12 3.5L9.5 6H6v3.5L3.5 12L6 14.5V18zm2.5-6"%2F%3E%3C%2Fsvg%3E');
}
</style>
<h1 id="initialization--finalization"><a class="header" href="#initialization--finalization">Initialization & Finalization</a></h1>
<p>This chapter details the function used to initialize
the library before first use, and the funtion used to
finalize the library and deallocate any resources used by the library.</p>
<h2 id="initialization"><a class="header" href="#initialization">Initialization</a></h2>
<pre><code class="language-c">typedef struct {
int16_t num_task_threads;
int16_t max_task_threads;
int16_t num_expire_threads;
int16_t max_expire_threads;
int16_t num_poller_threads;
int16_t max_poller_threads;
int16_t num_resolver_threads;
} nng_init_params;
extern int nng_init(nng_init_parms *params);
</code></pre>
<p>Before using other interfaces in this library, it is necessary to initialize
the library. The <a name="a001"></a><code>nng_init</code> function performs this initialization.</p>
<p>The function is idempotent, although on tear down, every call to <code>nng_init</code> must
be paired with a call to <a href="api//api/init.html#finalization"><code>nng_fini</code></a> or no resources will be released.
This allows for libraries consuming these interfaces to safely initialize and finalize
the library without disrupting other consumers in the same process.</p>
<p>Further, only the first call to this function may have a value of <em>params</em> other than <code>NULL</code>.
If <em>params</em> is not <code>NULL</code>, and the library has already been intiazed, then <code>nng_init</code> will
return <a href="api//api/errors.html#NNG_EBUSY"><code>NNG_EBUSY</code></a>.</p>
<p>In some cases it is desirable to tune certain runtime parameters for the library, which
can be done by supplying a non-<code>NULL</code> <em>params</em> argument.</p>
<h3 id="parameters"><a class="header" href="#parameters">Parameters</a></h3>
<p>The individual fields of the <code>nng_init_params</code> structure can be used to adjust certain
runtime tunables for the library. There is no guarantee that these tunables are implemented,
and applications should not depend upon them for correct operation.</p>
<p>Any member of <code>nng_init_params</code> that is set to zero will be ignored, and any built in default
will be used instead for that value.</p>
<div class="mdbook-alerts mdbook-alerts-note">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
note
</p>
<p>Applications should make sure that structure is zero initialized before calling <code>nng_init</code>.</p>
</div>
<p>The following parameters are present:</p>
<ul>
<li>
<p><code>num_task_threads</code> and <code>max_task_threads</code> <br />
Configures the number of threads to use for tasks, which are used principally for completion
callbacks. The maximum value can be used to provide an upper limit while still allowing
for a dynamically calculated value to be used, as long as it does not exceeed the maximum.</p>
</li>
<li>
<p><code>num_expire_threads</code> and <code>max_expire_threads</code> <br />
Configures the number of threads used for expiring operations. Using a larger value will
reduce contention on some common locks, and may improve performance.</p>
</li>
<li>
<p><code>num_poller_threads</code> and <code>max_poller_threads</code> <br />
Configures the number of threads to be used for performing I/O. Not all configurations support
changing these values.</p>
</li>
<li>
<p><code>num_resolver_threads</code> <br />
Changes the number of threads used for asynchronous DNS look ups.</p>
</li>
</ul>
<h2 id="finalization"><a class="header" href="#finalization">Finalization</a></h2>
<pre><code class="language-c">extern void nng_init(nng_init_parms *params);
</code></pre>
<p>When the consumer is ready to deallocate any resoures allocated by the library, it should call
the <a name="a002"></a><code>nng_fini</code> function. Each call to <code>nng_fini</code> should be paired with an earlier call to
<a href="api//api/init.html#initialization"><code>nng_init</code></a>.</p>
<p>After calling <code>nng_fini</code>, the consuming application must not make any other calls to NNG functions,
except that it may use <code>nng_init</code> to initialize the application for further use.</p>
<!-- Symbol cross reference -->
<!-- Macros -->
<!-- Protocols -->
<!-- Transports -->
<!-- Concept index -->
<div style="break-before: page; page-break-before: always;"></div><style>
.mdbook-alerts {
padding: 8px 16px;
margin-bottom: 16px;
border-left: 0.25em solid var(--mdbook-alerts-color);
}
.mdbook-alerts > *:first-child {
margin-top: 0;
}
.mdbook-alerts > *:last-child {
margin-bottom: 0;
}
.mdbook-alerts-title {
display: flex;
font-weight: 600;
align-items: center;
line-height: 1;
color: var(--mdbook-alerts-color);
text-transform: capitalize;
}
.mdbook-alerts-icon {
display: inline-block;
width: 1em;
height: 1em;
margin-right: 0.2em;
background-color: currentColor;
-webkit-mask: no-repeat center / 100%;
mask: no-repeat center / 100%;
-webkit-mask-image: var(--mdbook-alerts-icon);
mask-image: var(--mdbook-alerts-icon);
}
.mdbook-alerts-note {
--mdbook-alerts-color: rgb(9, 105, 218);
/* https://icon-sets.iconify.design/material-symbols/info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16v-4q0-.425-.288-.712T12 11q-.425 0-.712.288T11 12v4q0 .425.288.713T12 17m0-8q.425 0 .713-.288T13 8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8q0 .425.288.713T12 9m0 13q-2.075 0-3.9-.788t-3.175-2.137q-1.35-1.35-2.137-3.175T2 12q0-2.075.788-3.9t2.137-3.175q1.35-1.35 3.175-2.137T12 2q2.075 0 3.9.788t3.175 2.137q1.35 1.35 2.138 3.175T22 12q0 2.075-.788 3.9t-2.137 3.175q-1.35 1.35-3.175 2.138T12 22m0-2q3.35 0 5.675-2.325T20 12q0-3.35-2.325-5.675T12 4Q8.65 4 6.325 6.325T4 12q0 3.35 2.325 5.675T12 20m0-8"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-tip {
--mdbook-alerts-color: rgb(26, 127, 55);
/* https://icon-sets.iconify.design/material-symbols/lightbulb-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 22q-.825 0-1.412-.587T10 20h4q0 .825-.587 1.413T12 22m-3-3q-.425 0-.712-.288T8 18q0-.425.288-.712T9 17h6q.425 0 .713.288T16 18q0 .425-.288.713T15 19zm-.75-3q-1.725-1.025-2.738-2.75T4.5 9.5q0-3.125 2.188-5.312T12 2q3.125 0 5.313 2.188T19.5 9.5q0 2.025-1.012 3.75T15.75 16zm.6-2h6.3q1.125-.8 1.738-1.975T17.5 9.5q0-2.3-1.6-3.9T12 4Q9.7 4 8.1 5.6T6.5 9.5q0 1.35.613 2.525T8.85 14M12 14"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-important {
--mdbook-alerts-color: rgb(130, 80, 223);
/* https://icon-sets.iconify.design/material-symbols/chat-info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 7q.425 0 .713-.288T13 6q0-.425-.288-.712T12 5q-.425 0-.712.288T11 6q0 .425.288.713T12 7m0 8q.425 0 .713-.288T13 14v-4q0-.425-.288-.712T12 9q-.425 0-.712.288T11 10v4q0 .425.288.713T12 15m-6 3l-2.3 2.3q-.475.475-1.088.213T2 19.575V4q0-.825.588-1.412T4 2h16q.825 0 1.413.588T22 4v12q0 .825-.587 1.413T20 18zm-.85-2H20V4H4v13.125zM4 16V4z"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-warning {
--mdbook-alerts-color: rgb(154, 103, 0);
/* https://icon-sets.iconify.design/material-symbols/warning-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M2.725 21q-.275 0-.5-.137t-.35-.363q-.125-.225-.137-.488t.137-.512l9.25-16q.15-.25.388-.375T12 3q.25 0 .488.125t.387.375l9.25 16q.15.25.138.513t-.138.487q-.125.225-.35.363t-.5.137zm1.725-2h15.1L12 6zM12 18q.425 0 .713-.288T13 17q0-.425-.288-.712T12 16q-.425 0-.712.288T11 17q0 .425.288.713T12 18m0-3q.425 0 .713-.288T13 14v-3q0-.425-.288-.712T12 10q-.425 0-.712.288T11 11v3q0 .425.288.713T12 15m0-2.5"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-caution {
--mdbook-alerts-color: rgb(207, 34, 46);
/* https://icon-sets.iconify.design/material-symbols/brightness-alert-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16q0-.425-.288-.712T12 15q-.425 0-.712.288T11 16q0 .425.288.713T12 17m0-4q.425 0 .713-.288T13 12V8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8v4q0 .425.288.713T12 13m-3.35 7H6q-.825 0-1.412-.587T4 18v-2.65L2.075 13.4q-.275-.3-.425-.662T1.5 12q0-.375.15-.737t.425-.663L4 8.65V6q0-.825.588-1.412T6 4h2.65l1.95-1.925q.3-.275.663-.425T12 1.5q.375 0 .738.15t.662.425L15.35 4H18q.825 0 1.413.588T20 6v2.65l1.925 1.95q.275.3.425.663t.15.737q0 .375-.15.738t-.425.662L20 15.35V18q0 .825-.587 1.413T18 20h-2.65l-1.95 1.925q-.3.275-.662.425T12 22.5q-.375 0-.737-.15t-.663-.425zm.85-2l2.5 2.5l2.5-2.5H18v-3.5l2.5-2.5L18 9.5V6h-3.5L12 3.5L9.5 6H6v3.5L3.5 12L6 14.5V18zm2.5-6"%2F%3E%3C%2Fsvg%3E');
}
</style>
<h1 id="messages"><a class="header" href="#messages">Messages</a></h1>
<p>Messages <a name="a001"></a> in Scalability Protocols are the fundamental unit of
transmission and reception, as these protocols are fundamentally message-oriented.</p>
<p>Messages have a <a href="api//api/msg.html#message-body">body</a><a name="a002"></a>, containing the application-supplied
payload, and a <a href="api//api/msg.html#message-header">header</a><a name="a003"></a>, containing protocol specific routing and similar
related information.</p>
<div class="mdbook-alerts mdbook-alerts-tip">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
tip
</p>
<p>Only applications using <a href="api//TODO.html">raw mode</a> need to access the message header.
Very few <em>NNG</em> applications do this.</p>
</div>
<h2 id="message-structure"><a class="header" href="#message-structure">Message Structure</a></h2>
<pre><code class="language-c">typedef struct nng_msg nng_msg;
</code></pre>
<p>The <a name="a004"></a><code>nng_msg</code> structure represents a single message. It carries a body
and a header.</p>
<h3 id="create-a-message"><a class="header" href="#create-a-message">Create a Message</a></h3>
<pre><code class="language-c">int nng_msg_alloc(nng_msg **msgp, size_t size);
</code></pre>
<p>The <a name="a005"></a><code>nng_msg_alloc</code> function allocates a new message.
It takes a <em>size</em> argument, and returns a message
with a preallocated body of that size in the <em>msgp</em> parameter.</p>
<p>If it succeeds, it returns zero, otherwise this function may return <a href="api//api/errors.html#NNG_ENOMEM"><code>NNG_ENOMEM</code></a>,
indicating that insufficient memory is available to allocate a new message.</p>
<h3 id="destroy-a-message"><a class="header" href="#destroy-a-message">Destroy a Message</a></h3>
<pre><code class="language-c">void nng_msg_free(nng_msg *msg);
</code></pre>
<p>The <a name="a006"></a><code>nng_msg_free</code> function deallocates a message.</p>
<h3 id="duplicate-a-message"><a class="header" href="#duplicate-a-message">Duplicate a Message</a></h3>
<pre><code class="language-c">int nng_msg_dup(nng_msg **dup, nng_msg *msg);
</code></pre>
<p>The <a name="a007"></a><code>nng_msg_dup</code> function duplicates the message <em>msg</em>, storing a pointer
to the new duplicate in <em>dup</em>. This function also returns zero on succes, or <a href="api//api/errors.html#NNG_ENOMEM"><code>NNG_ENOMEM</code></a>
if memory is exhausted.</p>
<h2 id="message-size-and-capacity"><a class="header" href="#message-size-and-capacity">Message Size and Capacity</a></h2>
<pre><code class="language-c">size_t nng_msg_capacity(nng_msg *msg);
int nng_msg_realloc(nng_msg *msg, size_t size);
int nng_msg_reserve(nng_msg *msg, size_t capacity);
</code></pre>
<p>Messages have a certain amount of pre-reserved space, which may exceed the total
size of the message. This allows for content to be added to the message later,
without necessarily performing a reallocation.</p>
<p>The <a name="a008"></a><code>nng_msg_capacity</code> function returns the amount of prereserved space.
If a message size change is required, and the new size will fit within the capacity
reported by this function, then change will be done without a reallocation, and
likely without a data copy as well.</p>
<div class="mdbook-alerts mdbook-alerts-tip">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
tip
</p>
<p>The capacity reported by <code>nng_msg_capacity</code> may not include reserved headroom, which
is present to allow a very limited amount of content to be inserted in front of the
message without requiring the rest of the message to be copied.</p>
</div>
<p>The message size may be changed by use of the <a name="a009"></a><code>nng_msg_realloc</code> function. This
function will reallocate the underlying memory for the message <em>msg</em>,
preserving contents while doing so.
If the new size is smaller than the original message, it will
truncate the message, but not perform any allocations.
If reallocation fails due to insufficient memory, then the original is left intact.</p>
<p>The <a name="a010"></a><code>nng_msg_reserve</code> function ensures that the total message capacity
is at least <em>capacity</em> bytes. Use of this function to ensure the total anticipated
capacity is present in the message may help prevent many small allocations.</p>
<p>Both <code>nng_msg_realloc</code> and <code>nng_msg_reserve</code> return zero on success, or may return
<a href="api//api/errors.html#NNG_ENOMEM"><code>NNG_ENOMEM</code></a> if insufficient memory exists to preform allocation.</p>
<div class="mdbook-alerts mdbook-alerts-important">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
important
</p>
<p>Any pointers to message content obtained before a call to <code>nng_msg_realloc</code> or
<code>nng_msg_reserve</code> (or any other function that changes the message size) should be
treated as invalid, as the locations pointed to may be deallocated by these functions.</p>
</div>
<h2 id="message-body"><a class="header" href="#message-body">Message Body</a></h2>
<pre><code class="language-c">void *nng_msg_body(nng_msg *msg);
size_t nng_msg_len(nng_msg *msg);
</code></pre>
<p>The body and body length of <em>msg</em> are returned by <a name="a011"></a><code>nng_msg_body</code> and
<a name="a012"></a><code>nng_msg_len</code>, respectively.</p>
<h3 id="clear-the-body"><a class="header" href="#clear-the-body">Clear the Body</a></h3>
<pre><code class="language-c">void *nng_msg_clear(nng_msg *msg);
</code></pre>
<p>The <a name="a013"></a><code>nng_msg_clear</code> simply resets the total message body length to zero, but does
not affect the capacity. It does not change the underlying bytes of the message.</p>
<h3 id="add-to-body"><a class="header" href="#add-to-body">Add to Body</a></h3>
<pre><code class="language-c">int nng_msg_append(nng_msg *msg, const void *val, size_t size);
int nng_msg_append_u16(nng_msg *msg, uint16_t val16);
int nng_msg_append_u32(nng_msg *msg, uint32_t val32);
int nng_msg_append_u64(nng_msg *msg, uint64_t val64);
int nng_msg_insert(nng_msg *msg, const void *val, size_t size);
int nng_msg_insert_u16(nng_msg *msg, uint16_t val16);
int nng_msg_insert_u32(nng_msg *msg, uint32_t val32);
int nng_msg_insert_u64(nng_msg *msg, uint64_t val64);
</code></pre>
<p>Appending data to a message body is done by using the <a name="a014"></a><code>nng_msg_append</code> functions.
The base <code>nng_msg_append</code> function appends <em>size</em> bytes of untyped data to the end of the
message.</p>
<p>Use of the typed versions, ending in suffixes <code>_u16</code>, <code>_u32</code>, and <code>_u64</code> allows
for unsigned integers to be appended directly. The integers are encoded in network byte order, with
the most significant byte appearing first. The message body will by two, four, or eight
bytes accordingly.</p>
<p>Data may inserted before the rest of the message body by using the <a name="a015"></a><code>nng_msg_insert</code> functions.
This will attempt to use “headroom” in the message to avoid a data copy.
Otherwise they are like the <code>nng_msg_append</code> functions except that the put the data in front
of the messages instead of at the end.</p>
<div class="mdbook-alerts mdbook-alerts-tip">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
tip
</p>
<p>Message headroom is limited, so <code>nng_msg_insert</code> is best used sparingly.
It is much more efficient to build the message content from start to end
using <code>nng_msg_append</code>.</p>
</div>
<h3 id="consume-from-body"><a class="header" href="#consume-from-body">Consume From Body</a></h3>
<pre><code class="language-c">int nng_msg_chop(nng_msg *msg, size_t size);
int nng_msg_chop_u16(nng_msg *msg, uint16_t *val16);
int nng_msg_chop_u32(nng_msg *msg, uint32_t *val32);
int nng_msg_chop_u64(nng_msg *msg, uint64_t *val64);
int nng_msg_trim(nng_msg *msg, size_t size);
int nng_msg_trim_u16(nng_msg *msg, uint16_t *val16);
int nng_msg_trim_u32(nng_msg *msg, uint32_t *val32);
int nng_msg_trim_u64(nng_msg *msg, uint64_t *val64);
</code></pre>
<p>The <a name="a016"></a><code>nng_msg_chop</code> functions remove data from the end of the body of message <em>msg</em>,
reducing the message length by either <em>size</em>, or the appropriate value size.</p>
<p>The <a name="a017"></a><code>nng_msg_trim</code> functions remove data from the beginning of the message body of <em>msg</em>.
but are otherwise just like the <code>nng_msg_chop</code> functions.</p>
<p>If the message is not big enough to remove requisite amount of bytes, these functions
return <code>NNG_EINVAL</code>. Otherwise they return zero.</p>
<p>Additionally, functions with typed suffixes (<code>_u16</code>, <code>_u32</code>, <code>_u64</code>) decode the data and return it
through the appropriate <em>val</em> pointer.</p>
<p>The data is assumed to have been in network byte order in the message, but is returned in
the native machine byte order. The appropriate number of bytes is consumed for each of these types,
so two bytes for <code>_u16</code>, four bytes for <code>_u32</code>, and eight bytes for <code>_u64</code>.</p>
<h2 id="message-header"><a class="header" href="#message-header">Message Header</a></h2>
<pre><code class="language-c">void *nng_msg_header(nng_msg *msg);
size_t nng_msg_header_len(nng_msg *msg);
</code></pre>
<p>The header and header length of <em>msg</em> are returned by <a name="a018"></a><code>nng_msg_header</code> and
<a name="a019"></a><code>nng_msg_header_len</code>, respectively.</p>
<p>The message headers are generally intended for limited use, to store protocol headers.</p>
<div class="mdbook-alerts mdbook-alerts-important">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
important
</p>
<p>The message headers are for protocol and transport headers, and not for general
application payloads. Misuse of the header may prevent the application from functioning
properly.</p>
</div>
<h3 id="clear-the-header"><a class="header" href="#clear-the-header">Clear the Header</a></h3>
<pre><code class="language-c">void *nng_msg_header_clear(nng_msg *msg);
</code></pre>
<p>The <a name="a020"></a><code>nng_msg_header_clear</code> simply resets the total message header length to zero.</p>
<h3 id="append-or-insert-header"><a class="header" href="#append-or-insert-header">Append or Insert Header</a></h3>
<p>Appending data to a message header is done by using the <a name="a021"></a><code>nng_msg_header_append</code> functions,
and inserting data in the header is done using the <a name="a022"></a><code>nng_msg_header_insert</code> functions.</p>
<p>These functions act just like the <a href="api//api/msg.html#add-to-body"><code>nng_msg_append</code></a> and <a href="api//api/msg.html#add-to-body"><code>nng_msg_insert</code></a> functions,
except that they operate on the message header rather than the message body.</p>
<h3 id="consume-from-header"><a class="header" href="#consume-from-header">Consume from Header</a></h3>
<p>The <a name="a023"></a><code>nng_msg_header_trim</code> functions remove data from the beginning of the message header,
and the <a name="a024"></a><code>nng_msg_header_chop</code> functions remove data from the end of the message header.</p>
<p>These functions act just like the <a href="api//api/msg.html#consume-from-body"><code>nng_msg_trim</code></a> and <a href="api//api/msg.html#consume-from-body"><code>nng_msg_chop</code></a> functions,
except that they operate the message header rather than the message body.</p>
<h2 id="message-pipe"><a class="header" href="#message-pipe">Message Pipe</a></h2>
<pre><code class="language-c">nng_pipe nng_msg_get_pipe(nng_msg *msg);
void nng_msg_get_pipe(nng_msg *msg, nng_pipe p);
</code></pre>
<p>The <a name="a025"></a><code>nng_msg_set_pipe</code> function sets the <a href="api//TODO.html">pipe</a> associated with <em>msg</em> to <em>p</em>.
This is most often useful when used with protocols that support directing
a message to a specific peer.
For example the <a href="api//proto/pair.html"><em>PAIR</em></a> version 1 protocol can do
this when <code>NNG_OPT_PAIR1_POLY</code> mode is set.</p>
<p>The <a name="a026"></a><code>nng_msg_get_pipe</code> function returns the pipe that was previously set on the message <em>m</em>,
either directly by the application, or when the message was received by the protocol.</p>
<div class="mdbook-alerts mdbook-alerts-note">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
note
</p>
<p>Not all protocols support overriding the destination pipe.</p>
</div>
<h2 id="examples"><a class="header" href="#examples">Examples</a></h2>
<h3 id="example-1-preparing-a-message-for-use"><a class="header" href="#example-1-preparing-a-message-for-use">Example 1: Preparing a message for use</a></h3>
<pre><code class="language-c"> #include <nng/nng.h>
nng_msg *m;
if (nng_msg_alloc(&m, strlen("content") + 1) != 0) {
// handle error
}
strcpy(nng_msg_body(m), "content");
</code></pre>
<h3 id="example-2-preallocating-message-content"><a class="header" href="#example-2-preallocating-message-content">Example 2: Preallocating message content</a></h3>
<pre><code class="language-c"> if (nng_msg_alloc(&m, 1024) != 0) {
// handle error
}
while ((val64 = next_datum()) != 0) P
if (nng_msg_append_u64(m, val64) != 0) {
// handle error
}
}
</code></pre>
<!-- Symbol cross reference -->
<!-- Macros -->
<!-- Protocols -->
<!-- Transports -->
<!-- Concept index -->
<div style="break-before: page; page-break-before: always;"></div><style>
.mdbook-alerts {
padding: 8px 16px;
margin-bottom: 16px;
border-left: 0.25em solid var(--mdbook-alerts-color);
}
.mdbook-alerts > *:first-child {
margin-top: 0;
}
.mdbook-alerts > *:last-child {
margin-bottom: 0;
}
.mdbook-alerts-title {
display: flex;
font-weight: 600;
align-items: center;
line-height: 1;
color: var(--mdbook-alerts-color);
text-transform: capitalize;
}
.mdbook-alerts-icon {
display: inline-block;
width: 1em;
height: 1em;
margin-right: 0.2em;
background-color: currentColor;
-webkit-mask: no-repeat center / 100%;
mask: no-repeat center / 100%;
-webkit-mask-image: var(--mdbook-alerts-icon);
mask-image: var(--mdbook-alerts-icon);
}
.mdbook-alerts-note {
--mdbook-alerts-color: rgb(9, 105, 218);
/* https://icon-sets.iconify.design/material-symbols/info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16v-4q0-.425-.288-.712T12 11q-.425 0-.712.288T11 12v4q0 .425.288.713T12 17m0-8q.425 0 .713-.288T13 8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8q0 .425.288.713T12 9m0 13q-2.075 0-3.9-.788t-3.175-2.137q-1.35-1.35-2.137-3.175T2 12q0-2.075.788-3.9t2.137-3.175q1.35-1.35 3.175-2.137T12 2q2.075 0 3.9.788t3.175 2.137q1.35 1.35 2.138 3.175T22 12q0 2.075-.788 3.9t-2.137 3.175q-1.35 1.35-3.175 2.138T12 22m0-2q3.35 0 5.675-2.325T20 12q0-3.35-2.325-5.675T12 4Q8.65 4 6.325 6.325T4 12q0 3.35 2.325 5.675T12 20m0-8"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-tip {
--mdbook-alerts-color: rgb(26, 127, 55);
/* https://icon-sets.iconify.design/material-symbols/lightbulb-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 22q-.825 0-1.412-.587T10 20h4q0 .825-.587 1.413T12 22m-3-3q-.425 0-.712-.288T8 18q0-.425.288-.712T9 17h6q.425 0 .713.288T16 18q0 .425-.288.713T15 19zm-.75-3q-1.725-1.025-2.738-2.75T4.5 9.5q0-3.125 2.188-5.312T12 2q3.125 0 5.313 2.188T19.5 9.5q0 2.025-1.012 3.75T15.75 16zm.6-2h6.3q1.125-.8 1.738-1.975T17.5 9.5q0-2.3-1.6-3.9T12 4Q9.7 4 8.1 5.6T6.5 9.5q0 1.35.613 2.525T8.85 14M12 14"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-important {
--mdbook-alerts-color: rgb(130, 80, 223);
/* https://icon-sets.iconify.design/material-symbols/chat-info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 7q.425 0 .713-.288T13 6q0-.425-.288-.712T12 5q-.425 0-.712.288T11 6q0 .425.288.713T12 7m0 8q.425 0 .713-.288T13 14v-4q0-.425-.288-.712T12 9q-.425 0-.712.288T11 10v4q0 .425.288.713T12 15m-6 3l-2.3 2.3q-.475.475-1.088.213T2 19.575V4q0-.825.588-1.412T4 2h16q.825 0 1.413.588T22 4v12q0 .825-.587 1.413T20 18zm-.85-2H20V4H4v13.125zM4 16V4z"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-warning {
--mdbook-alerts-color: rgb(154, 103, 0);
/* https://icon-sets.iconify.design/material-symbols/warning-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M2.725 21q-.275 0-.5-.137t-.35-.363q-.125-.225-.137-.488t.137-.512l9.25-16q.15-.25.388-.375T12 3q.25 0 .488.125t.387.375l9.25 16q.15.25.138.513t-.138.487q-.125.225-.35.363t-.5.137zm1.725-2h15.1L12 6zM12 18q.425 0 .713-.288T13 17q0-.425-.288-.712T12 16q-.425 0-.712.288T11 17q0 .425.288.713T12 18m0-3q.425 0 .713-.288T13 14v-3q0-.425-.288-.712T12 10q-.425 0-.712.288T11 11v3q0 .425.288.713T12 15m0-2.5"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-caution {
--mdbook-alerts-color: rgb(207, 34, 46);
/* https://icon-sets.iconify.design/material-symbols/brightness-alert-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16q0-.425-.288-.712T12 15q-.425 0-.712.288T11 16q0 .425.288.713T12 17m0-4q.425 0 .713-.288T13 12V8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8v4q0 .425.288.713T12 13m-3.35 7H6q-.825 0-1.412-.587T4 18v-2.65L2.075 13.4q-.275-.3-.425-.662T1.5 12q0-.375.15-.737t.425-.663L4 8.65V6q0-.825.588-1.412T6 4h2.65l1.95-1.925q.3-.275.663-.425T12 1.5q.375 0 .738.15t.662.425L15.35 4H18q.825 0 1.413.588T20 6v2.65l1.925 1.95q.275.3.425.663t.15.737q0 .375-.15.738t-.425.662L20 15.35V18q0 .825-.587 1.413T18 20h-2.65l-1.95 1.925q-.3.275-.662.425T12 22.5q-.375 0-.737-.15t-.663-.425zm.85-2l2.5 2.5l2.5-2.5H18v-3.5l2.5-2.5L18 9.5V6h-3.5L12 3.5L9.5 6H6v3.5L3.5 12L6 14.5V18zm2.5-6"%2F%3E%3C%2Fsvg%3E');
}
</style>
<h1 id="sockets"><a class="header" href="#sockets">Sockets</a></h1>
<p>Sockets <a name="a001"></a> in Scalability Protocols provide the handle for communication
between peers. Sockets also encapsulate protocol specific semantics, such as
filtering subscriptions, or automatically retrying requests.</p>
<h2 id="socket-structure"><a class="header" href="#socket-structure">Socket Structure</a></h2>
<pre><code class="language-c">#define NNG_SOCKET_INITIALIZER // opaque value
typedef struct nng_socket_s nng_socket;
</code></pre>
<p>The <a name="a002"></a><code>nng_socket</code> structure represents socket. This is a handle, and
the members of it are opaque. However, unlike a pointer, it is usually
passed by value.</p>
<p>A socket may be initialized statically with the <code>NNG_SOCKET_INITIALIZER</code> macro,
to ensure that it cannot be confused with a valid open socket.</p>
<h2 id="socket-identity"><a class="header" href="#socket-identity">Socket Identity</a></h2>
<pre><code class="language-c">int nng_socket_id(nng_socket s);
int nng_socket_raw(nng_socket s, bool *raw);
int nng_socket_proto_id(nng_socket s, uint16_t *proto);
int nng_socket_peer_id(nng_socket s, uint16_t *proto);
int nng_socket_proto_name(nng_socket s, const char **name);
int nng_socket_peer_name(nng_socket s, const char **name);
</code></pre>
<p>These functions are used to provide fundamental information about the socket <em>s</em>.
Most applications will not need to use these functions.</p>
<p>The <a name="a003"></a><code>nng_socket_id</code> function returns the numeric id, which will be a non-negative
value, associated with the socket. If the socket is uninitialized (has never been opened),
then the return value may be <code>-1</code>.</p>
<p>The <a name="a004"></a><code>nng_socket_proto_id</code> and <a name="a005"></a><code>nng_socket_peer_id</code> functions provide the 16-bit
protocol identifier for the socket’s protocol, and of the protocol peers will use when
communicating with the socket.</p>
<p>The <a name="a006"></a><code>nng_socket_proto_name</code> and <a name="a007"></a><code>nng_socket_peer_name</code> functions provide the ASCII
names of the socket’s protocol, and of the protocol peers of the socket use.
The value stored in <em>name</em> is a fixed string located in program text, and must not be freed
or altered. It is guaranteed to remain valid while this library is present.</p>
<p>The <a name="a008"></a><code>nng_socket_raw</code> function determines whether the socket is in
<a href="api//TODO.html">raw mode</a> or not, storing <code>true</code> in <em>raw</em> if it is, or <code>false</code> if it is not.</p>
<h2 id="polling-socket-events"><a class="header" href="#polling-socket-events">Polling Socket Events</a></h2>
<pre><code class="language-c">int nng_socket_get_recv_poll_fd(nng_socket s, int *fdp);
int nng_socket_get_send_poll_fd(nng_socket s, int *fdp);
</code></pre>
<p>Sometimes it is necessary to integrate a socket into a <code>poll</code> or <code>select</code> driven
<a name="a009"></a>event loop. (Or, on Linux, <code>epoll</code>, or on BSD derived systems like macOS <code>kqueue</code>).</p>
<p>For these occasions, a suitable file descriptor for polling is provided
by these two functions.</p>
<p>The <a name="a010"></a><code>nng_socket_get_recv_poll_fd</code> function obtains a file descriptor
that will poll as readable when a message is ready for receiving for the socket.</p>
<p>The <a name="a011"></a><code>nng_socket_get_send_poll_fd</code> function obtains a file descriptor
that will poll as readable when the socket can accept a message for sending.</p>
<p>These file descriptors should only be polled for readability, and no
other operation performed on them. The socket will read from, or write to,
these file descriptors to provide a level-signaled behavior automatically.</p>
<p>Additionally the socket will close these file descriptors when the socket itself is closed.</p>
<p>These functions replace the <code>NNG_OPT_SENDFD</code> and <code>NNG_OPT_RECVFD</code> socket options that
were available in previous versions of NNG.</p>
<div class="mdbook-alerts mdbook-alerts-note">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
note
</p>
<p>These functions are not compatible with <a href="api//TODO.html">contexts</a>.</p>
</div>
<div class="mdbook-alerts mdbook-alerts-note">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
note
</p>
<p>The file descriptors supplied by these functions is not used for transporting message data.
The only valid use of these file descriptors is for polling for the ability to send or receive
messages on the socket.</p>
</div>
<div class="mdbook-alerts mdbook-alerts-tip">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
tip
</p>
<p>Using these functions will force the socket to perform extra system calls, and thus
have a negative impact on performance and latency. It is preferable to use <a href="api//api/aio.html">asynchronous I/O</a>
when possible.</p>
</div>
<h2 id="examples-1"><a class="header" href="#examples-1">Examples</a></h2>
<h3 id="example-1-initializing-a-socket"><a class="header" href="#example-1-initializing-a-socket">Example 1: Initializing a Socket</a></h3>
<pre><code class="language-c">nng_socket s = NNG_SOCKET_INITIALIZER;
</code></pre>
<!-- Symbol cross reference -->
<!-- Macros -->
<!-- Protocols -->
<!-- Transports -->
<!-- Concept index -->
<div style="break-before: page; page-break-before: always;"></div><style>
.mdbook-alerts {
padding: 8px 16px;
margin-bottom: 16px;
border-left: 0.25em solid var(--mdbook-alerts-color);
}
.mdbook-alerts > *:first-child {
margin-top: 0;
}
.mdbook-alerts > *:last-child {
margin-bottom: 0;
}
.mdbook-alerts-title {
display: flex;
font-weight: 600;
align-items: center;
line-height: 1;
color: var(--mdbook-alerts-color);
text-transform: capitalize;
}
.mdbook-alerts-icon {
display: inline-block;
width: 1em;
height: 1em;
margin-right: 0.2em;
background-color: currentColor;
-webkit-mask: no-repeat center / 100%;
mask: no-repeat center / 100%;
-webkit-mask-image: var(--mdbook-alerts-icon);
mask-image: var(--mdbook-alerts-icon);
}
.mdbook-alerts-note {
--mdbook-alerts-color: rgb(9, 105, 218);
/* https://icon-sets.iconify.design/material-symbols/info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16v-4q0-.425-.288-.712T12 11q-.425 0-.712.288T11 12v4q0 .425.288.713T12 17m0-8q.425 0 .713-.288T13 8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8q0 .425.288.713T12 9m0 13q-2.075 0-3.9-.788t-3.175-2.137q-1.35-1.35-2.137-3.175T2 12q0-2.075.788-3.9t2.137-3.175q1.35-1.35 3.175-2.137T12 2q2.075 0 3.9.788t3.175 2.137q1.35 1.35 2.138 3.175T22 12q0 2.075-.788 3.9t-2.137 3.175q-1.35 1.35-3.175 2.138T12 22m0-2q3.35 0 5.675-2.325T20 12q0-3.35-2.325-5.675T12 4Q8.65 4 6.325 6.325T4 12q0 3.35 2.325 5.675T12 20m0-8"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-tip {
--mdbook-alerts-color: rgb(26, 127, 55);
/* https://icon-sets.iconify.design/material-symbols/lightbulb-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 22q-.825 0-1.412-.587T10 20h4q0 .825-.587 1.413T12 22m-3-3q-.425 0-.712-.288T8 18q0-.425.288-.712T9 17h6q.425 0 .713.288T16 18q0 .425-.288.713T15 19zm-.75-3q-1.725-1.025-2.738-2.75T4.5 9.5q0-3.125 2.188-5.312T12 2q3.125 0 5.313 2.188T19.5 9.5q0 2.025-1.012 3.75T15.75 16zm.6-2h6.3q1.125-.8 1.738-1.975T17.5 9.5q0-2.3-1.6-3.9T12 4Q9.7 4 8.1 5.6T6.5 9.5q0 1.35.613 2.525T8.85 14M12 14"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-important {
--mdbook-alerts-color: rgb(130, 80, 223);
/* https://icon-sets.iconify.design/material-symbols/chat-info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 7q.425 0 .713-.288T13 6q0-.425-.288-.712T12 5q-.425 0-.712.288T11 6q0 .425.288.713T12 7m0 8q.425 0 .713-.288T13 14v-4q0-.425-.288-.712T12 9q-.425 0-.712.288T11 10v4q0 .425.288.713T12 15m-6 3l-2.3 2.3q-.475.475-1.088.213T2 19.575V4q0-.825.588-1.412T4 2h16q.825 0 1.413.588T22 4v12q0 .825-.587 1.413T20 18zm-.85-2H20V4H4v13.125zM4 16V4z"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-warning {
--mdbook-alerts-color: rgb(154, 103, 0);
/* https://icon-sets.iconify.design/material-symbols/warning-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M2.725 21q-.275 0-.5-.137t-.35-.363q-.125-.225-.137-.488t.137-.512l9.25-16q.15-.25.388-.375T12 3q.25 0 .488.125t.387.375l9.25 16q.15.25.138.513t-.138.487q-.125.225-.35.363t-.5.137zm1.725-2h15.1L12 6zM12 18q.425 0 .713-.288T13 17q0-.425-.288-.712T12 16q-.425 0-.712.288T11 17q0 .425.288.713T12 18m0-3q.425 0 .713-.288T13 14v-3q0-.425-.288-.712T12 10q-.425 0-.712.288T11 11v3q0 .425.288.713T12 15m0-2.5"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-caution {
--mdbook-alerts-color: rgb(207, 34, 46);
/* https://icon-sets.iconify.design/material-symbols/brightness-alert-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16q0-.425-.288-.712T12 15q-.425 0-.712.288T11 16q0 .425.288.713T12 17m0-4q.425 0 .713-.288T13 12V8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8v4q0 .425.288.713T12 13m-3.35 7H6q-.825 0-1.412-.587T4 18v-2.65L2.075 13.4q-.275-.3-.425-.662T1.5 12q0-.375.15-.737t.425-.663L4 8.65V6q0-.825.588-1.412T6 4h2.65l1.95-1.925q.3-.275.663-.425T12 1.5q.375 0 .738.15t.662.425L15.35 4H18q.825 0 1.413.588T20 6v2.65l1.925 1.95q.275.3.425.663t.15.737q0 .375-.15.738t-.425.662L20 15.35V18q0 .825-.587 1.413T18 20h-2.65l-1.95 1.925q-.3.275-.662.425T12 22.5q-.375 0-.737-.15t-.663-.425zm.85-2l2.5 2.5l2.5-2.5H18v-3.5l2.5-2.5L18 9.5V6h-3.5L12 3.5L9.5 6H6v3.5L3.5 12L6 14.5V18zm2.5-6"%2F%3E%3C%2Fsvg%3E');
}
</style>
<h1 id="memory"><a class="header" href="#memory">Memory</a></h1>
<p>Managing <a name="a001"></a>memory and <a name="a002"></a>allocations is something that every C program has to deal with.
In the case of <em>NNG</em>, it can be more complicated because the underlying platform
code can provide different allocators that might not be compatible with the use
system allocator used by <code>malloc</code> and <code>free</code>.</p>
<h2 id="allocate-memory"><a class="header" href="#allocate-memory">Allocate Memory</a></h2>
<pre><code class="language-c">void *nng_alloc(size_t size);
</code></pre>
<p>The <a name="a003"></a><code>nng_alloc</code> function allocates a contiguous memory region of
at least <em>size</em> bytes, and returns a pointer to it.
The memory will be 64-bit aligned.
Note that the memory may have random data in it, just like with <code>malloc</code>.</p>
<p>If memory cannot be allocated for any reason, then <code>NULL</code> will be returned.
Applications that experience this should treat this like <a href="api//api/errors.html#NNG_ENOMEM"><code>NNG_ENOMEM</code></a>.</p>
<p>Memory returned by <code>nng_alloc</code> can be used to hold message buffers, in which
case it can be directly passed to <a href="api//TODO.html"><code>nng_send</code></a> using the flag <code>NNG_FLAG_ALLOC</code>.
Alternatively, it can be freed when no longer needed using <a href="api//api/memory.html#deallocate-memory"><code>nng_free</code></a>.</p>
<div class="mdbook-alerts mdbook-alerts-important">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
important
</p>
<p>Do not use the system <code>free</code> function (or the C++ <code>delete</code> operator) to release this memory.
On some configurations this may work, but on others it will lead to a crash or
other unpredictable behavior.</p>
</div>
<h2 id="deallocate-memory"><a class="header" href="#deallocate-memory">Deallocate Memory</a></h2>
<pre><code class="language-c">void nng_free(void *ptr, size_t size);
</code></pre>
<p>The <a name="a004"></a><code>nng_free</code> function deallocates memory previously allocated by <a href="api//api/memory.html#allocate-memory"><code>nng_alloc</code></a>.</p>
<p>The <em>size</em> argument must exactly match the <em>size</em> argument that was supplied to
<a href="api//api/memory.html#allocate-memory"><code>nng_alloc</code></a> when the memory was allocated.</p>
<h2 id="duplicate-string"><a class="header" href="#duplicate-string">Duplicate String</a></h2>
<pre><code class="language-c">char *nng_strdup(const char *src);
</code></pre>
<p>The <a name="a005"></a><code>nng_strdup</code> duplicates the string <em>src</em> and returns it.</p>
<p>This is logically equivalent to using <a href="api//api/memory.html#allocate-memory"><code>nng_alloc</code></a>
to allocate a region of memory of <code>strlen(s) + 1</code> bytes, and then
using <code>strcpy</code> to copy the string into the destination before
returning it.</p>
<p>The returned string should be deallocated with
<a href="api//api/memory.html#free-string"><code>nng_strfree</code></a>, or may be deallocated using the
<a href="api//api/memory.html#deallocate-memory"><code>nng_free</code></a> using the length of the returned string plus
one (for the <code>NUL</code> terminating byte).</p>
<h2 id="free-string"><a class="header" href="#free-string">Free String</a></h2>
<pre><code class="language-c">void nng_strfree(char *str);
</code></pre>
<p>The <a name="a006"></a><code>nng_strfree</code> function is a convenience function that
can be used to deallocate strings allocated with <a href="api//api/memory.html#duplicate-string"><code>nng_strdup</code></a>.</p>
<p>It is effectively the same as <code>nng_free(strlen(str) + 1)</code>.</p>
<!-- Symbol cross reference -->
<!-- Macros -->
<!-- Protocols -->
<!-- Transports -->
<!-- Concept index -->
<div style="break-before: page; page-break-before: always;"></div><style>
.mdbook-alerts {
padding: 8px 16px;
margin-bottom: 16px;
border-left: 0.25em solid var(--mdbook-alerts-color);
}
.mdbook-alerts > *:first-child {
margin-top: 0;
}
.mdbook-alerts > *:last-child {
margin-bottom: 0;
}
.mdbook-alerts-title {
display: flex;
font-weight: 600;
align-items: center;
line-height: 1;
color: var(--mdbook-alerts-color);
text-transform: capitalize;
}
.mdbook-alerts-icon {
display: inline-block;
width: 1em;
height: 1em;
margin-right: 0.2em;
background-color: currentColor;
-webkit-mask: no-repeat center / 100%;
mask: no-repeat center / 100%;
-webkit-mask-image: var(--mdbook-alerts-icon);
mask-image: var(--mdbook-alerts-icon);
}
.mdbook-alerts-note {
--mdbook-alerts-color: rgb(9, 105, 218);
/* https://icon-sets.iconify.design/material-symbols/info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16v-4q0-.425-.288-.712T12 11q-.425 0-.712.288T11 12v4q0 .425.288.713T12 17m0-8q.425 0 .713-.288T13 8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8q0 .425.288.713T12 9m0 13q-2.075 0-3.9-.788t-3.175-2.137q-1.35-1.35-2.137-3.175T2 12q0-2.075.788-3.9t2.137-3.175q1.35-1.35 3.175-2.137T12 2q2.075 0 3.9.788t3.175 2.137q1.35 1.35 2.138 3.175T22 12q0 2.075-.788 3.9t-2.137 3.175q-1.35 1.35-3.175 2.138T12 22m0-2q3.35 0 5.675-2.325T20 12q0-3.35-2.325-5.675T12 4Q8.65 4 6.325 6.325T4 12q0 3.35 2.325 5.675T12 20m0-8"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-tip {
--mdbook-alerts-color: rgb(26, 127, 55);
/* https://icon-sets.iconify.design/material-symbols/lightbulb-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 22q-.825 0-1.412-.587T10 20h4q0 .825-.587 1.413T12 22m-3-3q-.425 0-.712-.288T8 18q0-.425.288-.712T9 17h6q.425 0 .713.288T16 18q0 .425-.288.713T15 19zm-.75-3q-1.725-1.025-2.738-2.75T4.5 9.5q0-3.125 2.188-5.312T12 2q3.125 0 5.313 2.188T19.5 9.5q0 2.025-1.012 3.75T15.75 16zm.6-2h6.3q1.125-.8 1.738-1.975T17.5 9.5q0-2.3-1.6-3.9T12 4Q9.7 4 8.1 5.6T6.5 9.5q0 1.35.613 2.525T8.85 14M12 14"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-important {
--mdbook-alerts-color: rgb(130, 80, 223);
/* https://icon-sets.iconify.design/material-symbols/chat-info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 7q.425 0 .713-.288T13 6q0-.425-.288-.712T12 5q-.425 0-.712.288T11 6q0 .425.288.713T12 7m0 8q.425 0 .713-.288T13 14v-4q0-.425-.288-.712T12 9q-.425 0-.712.288T11 10v4q0 .425.288.713T12 15m-6 3l-2.3 2.3q-.475.475-1.088.213T2 19.575V4q0-.825.588-1.412T4 2h16q.825 0 1.413.588T22 4v12q0 .825-.587 1.413T20 18zm-.85-2H20V4H4v13.125zM4 16V4z"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-warning {
--mdbook-alerts-color: rgb(154, 103, 0);
/* https://icon-sets.iconify.design/material-symbols/warning-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M2.725 21q-.275 0-.5-.137t-.35-.363q-.125-.225-.137-.488t.137-.512l9.25-16q.15-.25.388-.375T12 3q.25 0 .488.125t.387.375l9.25 16q.15.25.138.513t-.138.487q-.125.225-.35.363t-.5.137zm1.725-2h15.1L12 6zM12 18q.425 0 .713-.288T13 17q0-.425-.288-.712T12 16q-.425 0-.712.288T11 17q0 .425.288.713T12 18m0-3q.425 0 .713-.288T13 14v-3q0-.425-.288-.712T12 10q-.425 0-.712.288T11 11v3q0 .425.288.713T12 15m0-2.5"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-caution {
--mdbook-alerts-color: rgb(207, 34, 46);
/* https://icon-sets.iconify.design/material-symbols/brightness-alert-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16q0-.425-.288-.712T12 15q-.425 0-.712.288T11 16q0 .425.288.713T12 17m0-4q.425 0 .713-.288T13 12V8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8v4q0 .425.288.713T12 13m-3.35 7H6q-.825 0-1.412-.587T4 18v-2.65L2.075 13.4q-.275-.3-.425-.662T1.5 12q0-.375.15-.737t.425-.663L4 8.65V6q0-.825.588-1.412T6 4h2.65l1.95-1.925q.3-.275.663-.425T12 1.5q.375 0 .738.15t.662.425L15.35 4H18q.825 0 1.413.588T20 6v2.65l1.925 1.95q.275.3.425.663t.15.737q0 .375-.15.738t-.425.662L20 15.35V18q0 .825-.587 1.413T18 20h-2.65l-1.95 1.925q-.3.275-.662.425T12 22.5q-.375 0-.737-.15t-.663-.425zm.85-2l2.5 2.5l2.5-2.5H18v-3.5l2.5-2.5L18 9.5V6h-3.5L12 3.5L9.5 6H6v3.5L3.5 12L6 14.5V18zm2.5-6"%2F%3E%3C%2Fsvg%3E');
}
</style>
<h1 id="time"><a class="header" href="#time">Time</a></h1>
<p><em>NNG</em> supports has support for time in the form of access to a
system clock, and supporting timeouts for certain operations.</p>
<h2 id="time-type"><a class="header" href="#time-type">Time Type</a></h2>
<pre><code class="language-c">typedef uint64_t nng_time;
</code></pre>
<p>The <a name="a001"></a><code>nng_time</code> type is used to represent a clock offset from a common base time,
measured in milliseconds.</p>
<p>The reference, or zero value, is some arbitrary point in time, most often sytem boot, but can
be process start time or any other convenient reference.</p>
<p>All threads within a process will use the same reference time, but be aware that different processes
may use a different reference time.</p>
<h2 id="duration-type"><a class="header" href="#duration-type">Duration Type</a></h2>
<pre><code class="language-c">typedef int64_t nng_duration;
#define NNG_DURATION_INFINITE (-1)
#define NNG_DURATION_DEFAULT (-2)
#define NNG_DURATION_ZERO (0)
</code></pre>
<p>The <a name="a002"></a><code>nng_duration</code> time measures a time <a name="a003"></a>duration in milliseconds.
Normally durations are positive, but some specific negative values are reserved.</p>
<ul>
<li>
<p><a name="a004"></a><code>NNG_DURATION_INFINITE</code>: The duration essentially means forever.
This is most often used with a timeout to indicate that there is no timeout, the
operation should wait until it is complete, even forever.</p>
</li>
<li>
<p><a name="a005"></a><code>NNG_DURATION_DEFAULT</code>: This special value is used in some circumstances to
prevent overriding a default timeout. Some operations have a default maximum time,
and this value means that the previously established default should be used.
The precise meaning is context-specific.</p>
</li>
<li>
<p><a name="a006"></a><code>NNG_DURATION_ZERO</code>: A zero length duration is used to performan an immediate
poll.</p>
</li>
</ul>
<h2 id="get-the-current-time"><a class="header" href="#get-the-current-time">Get the Current Time</a></h2>
<pre><code class="language-c">nng_time nng_clock(void);
</code></pre>
<p>The <a name="a007"></a><code>nng_clock</code><a name="a008"></a> function returns the number of elapsed
milliseconds since some arbitrary time in the past.
The resolution of the clock depends on the underlying timing facilities of the system.
This function may be used for timing, but applications should not expect
very fine-grained values.</p>
<h2 id="wait-for-duration"><a class="header" href="#wait-for-duration">Wait for Duration</a></h2>
<pre><code class="language-c">void nng_msleep(nng_duration msec);
</code></pre>
<p>The <a name="a009"></a><code>nng_msleep</code> function blocks the calling thread for at least the specified
number of milliseconds.</p>
<div class="mdbook-alerts mdbook-alerts-tip">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
tip
</p>
<p>This function may block for longer than requested.
The actual wait time is determined by the capabilities of the
underlying system.</p>
</div>
<h2 id="wait-asynchronously"><a class="header" href="#wait-asynchronously">Wait Asynchronously</a></h2>
<pre><code class="language-c">void nng_sleep_aio(nng_duration msec, nng_aio *aio);
</code></pre>
<p>It is possible to wait as the action on an <a href="api//api/aio.html#asynchronous-io-handle"><code>nng_aio</code></a>, which in effect
acts like <a name="a010"></a>scheduling a callback to run after a specified period of time.</p>
<p>The <a name="a011"></a><code>nng_sleep_aio</code> function provides this capability.
After <em>msec</em> milliseconds have passed, then <em>aio</em>’s callback will be executed.
If this sleep waits without interruption, and then completes, the result from
<a href="api//api/aio.html#result-of-operation"><code>nng_aio_result</code></a> will be zero.</p>
<div class="mdbook-alerts mdbook-alerts-note">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
note
</p>
<p>If a timeout shorter than <em>msec</em> is set on <em>aio</em> using <a href="api//api/aio.html#set-timeout"><code>nng_aio_set_timeout</code></a>,
then the sleep will wake up early, with a result code of <a href="api//api/errors.html#NNG_ETIMEDOUT"><code>NNG_ETIMEDOUT</code></a>.</p>
</div>
<h2 id="see-also"><a class="header" href="#see-also">See Also</a></h2>
<p><a href="api//api/aio.html">Asynchronous Operations</a>,
<a href="api//api/synch.html">Synchronization</a></p>
<!-- Symbol cross reference -->
<!-- Macros -->
<!-- Protocols -->
<!-- Transports -->
<!-- Concept index -->
<div style="break-before: page; page-break-before: always;"></div><style>
.mdbook-alerts {
padding: 8px 16px;
margin-bottom: 16px;
border-left: 0.25em solid var(--mdbook-alerts-color);
}
.mdbook-alerts > *:first-child {
margin-top: 0;
}
.mdbook-alerts > *:last-child {
margin-bottom: 0;
}
.mdbook-alerts-title {
display: flex;
font-weight: 600;
align-items: center;
line-height: 1;
color: var(--mdbook-alerts-color);
text-transform: capitalize;
}
.mdbook-alerts-icon {
display: inline-block;
width: 1em;
height: 1em;
margin-right: 0.2em;
background-color: currentColor;
-webkit-mask: no-repeat center / 100%;
mask: no-repeat center / 100%;
-webkit-mask-image: var(--mdbook-alerts-icon);
mask-image: var(--mdbook-alerts-icon);
}
.mdbook-alerts-note {
--mdbook-alerts-color: rgb(9, 105, 218);
/* https://icon-sets.iconify.design/material-symbols/info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16v-4q0-.425-.288-.712T12 11q-.425 0-.712.288T11 12v4q0 .425.288.713T12 17m0-8q.425 0 .713-.288T13 8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8q0 .425.288.713T12 9m0 13q-2.075 0-3.9-.788t-3.175-2.137q-1.35-1.35-2.137-3.175T2 12q0-2.075.788-3.9t2.137-3.175q1.35-1.35 3.175-2.137T12 2q2.075 0 3.9.788t3.175 2.137q1.35 1.35 2.138 3.175T22 12q0 2.075-.788 3.9t-2.137 3.175q-1.35 1.35-3.175 2.138T12 22m0-2q3.35 0 5.675-2.325T20 12q0-3.35-2.325-5.675T12 4Q8.65 4 6.325 6.325T4 12q0 3.35 2.325 5.675T12 20m0-8"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-tip {
--mdbook-alerts-color: rgb(26, 127, 55);
/* https://icon-sets.iconify.design/material-symbols/lightbulb-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 22q-.825 0-1.412-.587T10 20h4q0 .825-.587 1.413T12 22m-3-3q-.425 0-.712-.288T8 18q0-.425.288-.712T9 17h6q.425 0 .713.288T16 18q0 .425-.288.713T15 19zm-.75-3q-1.725-1.025-2.738-2.75T4.5 9.5q0-3.125 2.188-5.312T12 2q3.125 0 5.313 2.188T19.5 9.5q0 2.025-1.012 3.75T15.75 16zm.6-2h6.3q1.125-.8 1.738-1.975T17.5 9.5q0-2.3-1.6-3.9T12 4Q9.7 4 8.1 5.6T6.5 9.5q0 1.35.613 2.525T8.85 14M12 14"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-important {
--mdbook-alerts-color: rgb(130, 80, 223);
/* https://icon-sets.iconify.design/material-symbols/chat-info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 7q.425 0 .713-.288T13 6q0-.425-.288-.712T12 5q-.425 0-.712.288T11 6q0 .425.288.713T12 7m0 8q.425 0 .713-.288T13 14v-4q0-.425-.288-.712T12 9q-.425 0-.712.288T11 10v4q0 .425.288.713T12 15m-6 3l-2.3 2.3q-.475.475-1.088.213T2 19.575V4q0-.825.588-1.412T4 2h16q.825 0 1.413.588T22 4v12q0 .825-.587 1.413T20 18zm-.85-2H20V4H4v13.125zM4 16V4z"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-warning {
--mdbook-alerts-color: rgb(154, 103, 0);
/* https://icon-sets.iconify.design/material-symbols/warning-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M2.725 21q-.275 0-.5-.137t-.35-.363q-.125-.225-.137-.488t.137-.512l9.25-16q.15-.25.388-.375T12 3q.25 0 .488.125t.387.375l9.25 16q.15.25.138.513t-.138.487q-.125.225-.35.363t-.5.137zm1.725-2h15.1L12 6zM12 18q.425 0 .713-.288T13 17q0-.425-.288-.712T12 16q-.425 0-.712.288T11 17q0 .425.288.713T12 18m0-3q.425 0 .713-.288T13 14v-3q0-.425-.288-.712T12 10q-.425 0-.712.288T11 11v3q0 .425.288.713T12 15m0-2.5"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-caution {
--mdbook-alerts-color: rgb(207, 34, 46);
/* https://icon-sets.iconify.design/material-symbols/brightness-alert-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16q0-.425-.288-.712T12 15q-.425 0-.712.288T11 16q0 .425.288.713T12 17m0-4q.425 0 .713-.288T13 12V8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8v4q0 .425.288.713T12 13m-3.35 7H6q-.825 0-1.412-.587T4 18v-2.65L2.075 13.4q-.275-.3-.425-.662T1.5 12q0-.375.15-.737t.425-.663L4 8.65V6q0-.825.588-1.412T6 4h2.65l1.95-1.925q.3-.275.663-.425T12 1.5q.375 0 .738.15t.662.425L15.35 4H18q.825 0 1.413.588T20 6v2.65l1.925 1.95q.275.3.425.663t.15.737q0 .375-.15.738t-.425.662L20 15.35V18q0 .825-.587 1.413T18 20h-2.65l-1.95 1.925q-.3.275-.662.425T12 22.5q-.375 0-.737-.15t-.663-.425zm.85-2l2.5 2.5l2.5-2.5H18v-3.5l2.5-2.5L18 9.5V6h-3.5L12 3.5L9.5 6H6v3.5L3.5 12L6 14.5V18zm2.5-6"%2F%3E%3C%2Fsvg%3E');
}
</style>
<h1 id="urls"><a class="header" href="#urls">URLs</a></h1>
<p><a name="a001"></a>Universal Resource Locators, or <a name="a002"></a>URLs for short, are a standardized
way of representing a network resource,
defined in <a href="https://datatracker.ietf.org/doc/html/rfc1738">RFC 1738</a>,
and <a href="https://datatracker.ietf.org/doc/html/rfc3986">RFC 3968</a>.</p>
<p>In Scalability Protocols, this concept is extended, although it includes schemes
that are not part of the IETF standards.</p>
<h2 id="url-structure"><a class="header" href="#url-structure">URL Structure</a></h2>
<pre><code class="language-c">typedef struct nng_url {
const char *u_scheme;
char *u_userinfo;
char *u_hostname;
uint16_t u_port;
char *u_path;
char *u_query;
char *u_fragment;
} nng_url;
const char *nng_url_scheme(const nng_url *url);
const char *nng_url_userinfo(const nng_url *url);
const char *nng_url_hostname(const nng_url *url);
uint16_t nng_url_port(const nng_url *url);
const char *nng_url_path(const nng_url *url);
const char *nng_url_query(const nng_url *url);
const char *nng_url_fragment(const nng_url *url):
</code></pre>
<h3 id="url-fields"><a class="header" href="#url-fields">URL Fields</a></h3>
<p>The <a name="a003"></a><code>nng_url_scheme</code> function returns the scheme,
without any colons or slashes. Values are lower case
strings, like “http” or “inproc” or “tls+tcp4”.</p>
<p>The <a name="a004"></a><code>nng_url_userinfo</code> function returns a string corresponding
to the user component of a URL (the part before any <code>@</code> sign) if such
a component is present, otherwise it returns <code>NULL</code>.</p>
<p>The <a name="a005"></a><code>nng_url_hostname</code> function returns a hostname (which might
actually be an IP address) from the URL, if the URL corresponds to a scheme
that uses hostnames (like “http” or “tcp”). If the URL does not (for example
“inproc” or “ipc” URLs) then it returns <code>NULL</code>.</p>
<p>The <a name="a006"></a><code>nng_url_port</code> function returns the TCP or UDP port number if the URL
corresponds to a protocol based on TCP or UDP. It returns zero otherwise.
Note that the port number might not have been explicitly specified in the URL.
For example, the port number associated with “http://www.example.com” is 80,
which is the standard port number for HTTP.</p>
<div class="mdbook-alerts mdbook-alerts-tip">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
tip
</p>
<p>The port number returned by this is in the native machine byte order.
Be careful when using this with other network-oriented APIs.</p>
</div>
<p>The <a name="a007"></a><code>nng_url_path</code> function returns the path component of the URL.
This will always be non-<code>NULL</code>, but it may be empty.</p>
<p>The <a name="a008"></a><code>nng_url_query</code> and <a name="a009"></a><code>nng_url_fragment</code> functions return
the query-information (the part following a ‘?’) and fragment
(the part following a ‘#’) if those components are present, or <code>NULL</code>
if they are not. The returned string will not include the leading ‘?’ or ‘#’
characters.</p>
<p>Note that any strings returned by these functions are only valid until
<em>url</em> is freed with <a href="api//api/url.html#destroy-a-url"><code>nng_url_free</code></a>.</p>
<h2 id="format-a-url"><a class="header" href="#format-a-url">Format a URL</a></h2>
<pre><code class="language-c">int nng_url_sprintf(char *buf, size_t bufsz, const nng_url *url);
</code></pre>
<p>The <a name="a010"></a><code>nng_url_sprintf</code> function formats the <em>url</em> to the <em>buf</em>,
which must have <code>bufsz</code> bytes of free space associated with it.</p>
<p>This function returns the number of bytes formatted to <em>buf</em>, excludng
the terminating zero byte, or if <em>bufsz</em> is too small, then it returns
the number of bytes that would have been formatted if there was sufficient
space. The semantics are similar to the <code>snprintf</code> function from C99.</p>
<div class="mdbook-alerts mdbook-alerts-tip">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
tip
</p>
<p>If <em>bufsz</em> is 0, then <em>buf</em> can be <code>NULL</code>, and the return value
can be used to determine the amount of space to allocate for a dynamically
sized buffer.</p>
</div>
<h2 id="parse-a-url"><a class="header" href="#parse-a-url">Parse a URL</a></h2>
<pre><code class="language-c">int nng_url_parse(nng_url **urlp, const char *str);
</code></pre>
<p>The <a name="a011"></a><code>nng_url_parse</code> function parses a URL string (in <em>str</em>),
and creates a dynamically allocated <code>nng_url</code>, returning it in <em>urlp</em>.</p>
<div class="mdbook-alerts mdbook-alerts-important">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
important
</p>
<p>Only <a href="api//api/url.html#destroy-a-url"><code>nng_url_free</code></a> should be used to deallocate <code>nng_url</code> objects.</p>
</div>
<h2 id="clone-a-url"><a class="header" href="#clone-a-url">Clone a URL</a></h2>
<pre><code class="language-c">int nng_url_clone(nng_url **dup, nng_url *url);
</code></pre>
<p>The <a name="a012"></a><code>nng_url_clone</code> function creates a copy of <em>url</em>, and returns it in <em>dup</em>.</p>
<h2 id="destroy-a-url"><a class="header" href="#destroy-a-url">Destroy a URL</a></h2>
<pre><code class="language-c">void nng_url_free(nng_url *url);
</code></pre>
<p>The <a name="a013"></a><code>nng_url_free</code> function destroy an <code>nng_url</code> object created with
either <a href="api//api/url.html#parse-a-url"><code>nng_url_parse</code></a> or <a href="api//api/url.html#destroy-a-url"><code>nng_url_free</code></a>.</p>
<p>This is the only correct way to destroy an <a href="api//api/url.html#url-structure"><code>nng_url</code></a> object.</p>
<h2 id="see-also-1"><a class="header" href="#see-also-1">See Also</a></h2>
<p>More information about Universal Resource Locators can be found in
<a href="https://tools.ietf.org/html/rfc3986">RFC 3986</a>.</p>
<!-- Symbol cross reference -->
<!-- Macros -->
<!-- Protocols -->
<!-- Transports -->
<!-- Concept index -->
<div style="break-before: page; page-break-before: always;"></div><style>
.mdbook-alerts {
padding: 8px 16px;
margin-bottom: 16px;
border-left: 0.25em solid var(--mdbook-alerts-color);
}
.mdbook-alerts > *:first-child {
margin-top: 0;
}
.mdbook-alerts > *:last-child {
margin-bottom: 0;
}
.mdbook-alerts-title {
display: flex;
font-weight: 600;
align-items: center;
line-height: 1;
color: var(--mdbook-alerts-color);
text-transform: capitalize;
}
.mdbook-alerts-icon {
display: inline-block;
width: 1em;
height: 1em;
margin-right: 0.2em;
background-color: currentColor;
-webkit-mask: no-repeat center / 100%;
mask: no-repeat center / 100%;
-webkit-mask-image: var(--mdbook-alerts-icon);
mask-image: var(--mdbook-alerts-icon);
}
.mdbook-alerts-note {
--mdbook-alerts-color: rgb(9, 105, 218);
/* https://icon-sets.iconify.design/material-symbols/info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16v-4q0-.425-.288-.712T12 11q-.425 0-.712.288T11 12v4q0 .425.288.713T12 17m0-8q.425 0 .713-.288T13 8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8q0 .425.288.713T12 9m0 13q-2.075 0-3.9-.788t-3.175-2.137q-1.35-1.35-2.137-3.175T2 12q0-2.075.788-3.9t2.137-3.175q1.35-1.35 3.175-2.137T12 2q2.075 0 3.9.788t3.175 2.137q1.35 1.35 2.138 3.175T22 12q0 2.075-.788 3.9t-2.137 3.175q-1.35 1.35-3.175 2.138T12 22m0-2q3.35 0 5.675-2.325T20 12q0-3.35-2.325-5.675T12 4Q8.65 4 6.325 6.325T4 12q0 3.35 2.325 5.675T12 20m0-8"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-tip {
--mdbook-alerts-color: rgb(26, 127, 55);
/* https://icon-sets.iconify.design/material-symbols/lightbulb-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 22q-.825 0-1.412-.587T10 20h4q0 .825-.587 1.413T12 22m-3-3q-.425 0-.712-.288T8 18q0-.425.288-.712T9 17h6q.425 0 .713.288T16 18q0 .425-.288.713T15 19zm-.75-3q-1.725-1.025-2.738-2.75T4.5 9.5q0-3.125 2.188-5.312T12 2q3.125 0 5.313 2.188T19.5 9.5q0 2.025-1.012 3.75T15.75 16zm.6-2h6.3q1.125-.8 1.738-1.975T17.5 9.5q0-2.3-1.6-3.9T12 4Q9.7 4 8.1 5.6T6.5 9.5q0 1.35.613 2.525T8.85 14M12 14"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-important {
--mdbook-alerts-color: rgb(130, 80, 223);
/* https://icon-sets.iconify.design/material-symbols/chat-info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 7q.425 0 .713-.288T13 6q0-.425-.288-.712T12 5q-.425 0-.712.288T11 6q0 .425.288.713T12 7m0 8q.425 0 .713-.288T13 14v-4q0-.425-.288-.712T12 9q-.425 0-.712.288T11 10v4q0 .425.288.713T12 15m-6 3l-2.3 2.3q-.475.475-1.088.213T2 19.575V4q0-.825.588-1.412T4 2h16q.825 0 1.413.588T22 4v12q0 .825-.587 1.413T20 18zm-.85-2H20V4H4v13.125zM4 16V4z"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-warning {
--mdbook-alerts-color: rgb(154, 103, 0);
/* https://icon-sets.iconify.design/material-symbols/warning-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M2.725 21q-.275 0-.5-.137t-.35-.363q-.125-.225-.137-.488t.137-.512l9.25-16q.15-.25.388-.375T12 3q.25 0 .488.125t.387.375l9.25 16q.15.25.138.513t-.138.487q-.125.225-.35.363t-.5.137zm1.725-2h15.1L12 6zM12 18q.425 0 .713-.288T13 17q0-.425-.288-.712T12 16q-.425 0-.712.288T11 17q0 .425.288.713T12 18m0-3q.425 0 .713-.288T13 14v-3q0-.425-.288-.712T12 10q-.425 0-.712.288T11 11v3q0 .425.288.713T12 15m0-2.5"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-caution {
--mdbook-alerts-color: rgb(207, 34, 46);
/* https://icon-sets.iconify.design/material-symbols/brightness-alert-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16q0-.425-.288-.712T12 15q-.425 0-.712.288T11 16q0 .425.288.713T12 17m0-4q.425 0 .713-.288T13 12V8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8v4q0 .425.288.713T12 13m-3.35 7H6q-.825 0-1.412-.587T4 18v-2.65L2.075 13.4q-.275-.3-.425-.662T1.5 12q0-.375.15-.737t.425-.663L4 8.65V6q0-.825.588-1.412T6 4h2.65l1.95-1.925q.3-.275.663-.425T12 1.5q.375 0 .738.15t.662.425L15.35 4H18q.825 0 1.413.588T20 6v2.65l1.925 1.95q.275.3.425.663t.15.737q0 .375-.15.738t-.425.662L20 15.35V18q0 .825-.587 1.413T18 20h-2.65l-1.95 1.925q-.3.275-.662.425T12 22.5q-.375 0-.737-.15t-.663-.425zm.85-2l2.5 2.5l2.5-2.5H18v-3.5l2.5-2.5L18 9.5V6h-3.5L12 3.5L9.5 6H6v3.5L3.5 12L6 14.5V18zm2.5-6"%2F%3E%3C%2Fsvg%3E');
}
</style>
<h1 id="asynchronous-operations"><a class="header" href="#asynchronous-operations">Asynchronous Operations</a></h1>
<p>In order to obtain significant scalability, with low-latency, and minimal
overheads, <em>NNG</em> supports performing operations asynchronously.</p>
<p>One way that applications can perform work asynchronously and concurrently
is by using <a href="api//api/thread.html">threads</a>, but threads carry significant resource overheads
and frequently there are limits on the number that can easily be created.</p>
<p>Additionally, with most network applications, the flow of execution will spend
the bulk of its time waiting for traffic from a peer.</p>
<p>For these kinds of applications, it is far more efficient to use asynchronous operations
using the mechanisms described in this chapter.</p>
<div class="mdbook-alerts mdbook-alerts-tip">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
tip
</p>
<p>To get the highest performance with the least overhead, applications should use
asynchronous operations described in this chapter whenever possible.</p>
</div>
<h2 id="asynchronous-io-handle"><a class="header" href="#asynchronous-io-handle">Asynchronous I/O Handle</a></h2>
<pre><code class="language-c">typedef struct nng_aio nng_aio;
</code></pre>
<p>An <a name="a001"></a><code>nng_aio</code><a name="a002"></a> is an opaque structure used in conjunction with
<a name="a003"></a>asynchronous I/O operations.
Every asynchronous operation uses one of these structures, each of which
can only be used with a single operation at a time.</p>
<p>Asynchronous operations are performed without blocking calling application threads.
Instead the application registers a callback function to be executed
when the operation is complete (whether successfully or not).
This callback will be executed exactly once.</p>
<p>The asynchronous I/O framework also supports <a href="api//api/aio.html#cancellation">cancellation</a> of
operations that are already in progress as well setting a maximum
<a href="api//api/aio.html#set-timeout">timeout</a> for them to complete.</p>
<p>It is also possible to initiate an asynchronous operation, and <a href="api//api/aio.html#wait-for-completion">wait</a> for it to
complete, creating a synchronous flow from an asynchronous one.</p>
<h2 id="create-handle"><a class="header" href="#create-handle">Create Handle</a></h2>
<pre><code class="language-c">int nng_aio_alloc(nng_aio **aiop, void (*callb)(void *), void *arg);
</code></pre>
<p>The <a name="a004"></a><code>nng_aio_alloc</code> function creates an <a href="api//api/aio.html#asynchronous-io-handle"><code>nng_aio</code></a> object, with the
<a name="a005"></a>callback <em>callb</em> taking the argument <em>arg</em>, and returns it in <em>aiop</em>.</p>
<p>If this succeeds, the function returns zero. Otherwise it may return <a href="api//api/errors.html#NNG_ENOMEM"><code>NNG_ENOMEM</code></a>.</p>
<div class="mdbook-alerts mdbook-alerts-tip">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
tip
</p>
<p>The <em>arg</em> should normally be a structure that contains a pointer to the <em>aiop</em>,
or from which it can be located. This allows <em>callb</em> to check the handle for
success using <a href="api//api/aio.html#result-of-operation"><code>nng_aio_result</code></a>, as well access other properties of <em>aiop</em>.</p>
</div>
<div class="mdbook-alerts mdbook-alerts-tip">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
tip
</p>
<p>The <em>callb</em> may be executed on another <a href="api//api/thread.html">thread</a>, so it may be necessary to use
<a href="api//api/synch.html">synchronization</a> methods in <em>callb</em> to avoid data races.</p>
</div>
<h2 id="destroy-handle"><a class="header" href="#destroy-handle">Destroy Handle</a></h2>
<pre><code class="language-c">void nng_aio_free(nng_aio *aio);
void nng_aio_reap(nng_aio *aio);
</code></pre>
<p>The <a name="a006"></a><code>nng_aio_free</code> handle destroys the handle <em>aio</em>, waiting for any operations
and associated callbacks to complete before doing so.</p>
<p>The <a name="a007"></a><code>nng_aio_reap</code> handle destroys the handle <em>aio</em> asynchronously, using a <em>reaper</em>
<a href="api//api/thread.html">thread</a> to do so. It does not wait for the object to be destroyed. Thus this function
is safe to call from <em>aio</em>’s own callback.</p>
<div class="mdbook-alerts mdbook-alerts-note">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
note
</p>
<p>The <code>nng_aio_free</code> function must never be called from an <em>aio</em> callback.
Use <code>nng_aio_reap</code> instead if an object must be destroyed from a callback.</p>
</div>
<h2 id="cancellation"><a class="header" href="#cancellation">Cancellation</a></h2>
<pre><code class="language-c">void nng_aio_abort(nng_aio *aio, int err);
void nng_aio_cancel(nng_aio *aio);
void nng_aio_stop(nng_aio *aio);
</code></pre>
<p>These functions are used to stop a previously submitted asynchronous
I/O operation. The operation may be canceled, or may continue to
completion. If no operation is in progress (perhaps because it has
already completed), then these operations have no effect.
If the operation is successfully canceled or aborted, then the callback
will still be called.</p>
<p>The <a name="a008"></a><code>nng_aio_abort</code> function aborts the operation associated with <em>aio</em>
and returns immediately without waiting. If cancellation was successful,
then <a href="api//api/aio.html#result-of-operation"><code>nng_aio_result</code></a> will return <em>err</em>.</p>
<p>The <a name="a009"></a><code>nng_aio_cancel</code> function acts like <code>nng_aio_abort</code>, but uses the error code
<a href="api//api/errors.html#NNG_ECANCELED"><code>NNG_ECANCELED</code></a><a name="a010"></a>.</p>
<p>The <a name="a011"></a><code>nng_aio_stop</code> function aborts the <em>aio</em> operation with <a href="api//api/errors.html#NNG_ECANCELED"><code>NNG_ECANCELED</code></a>,
and then waits the operation and any associated callback to complete.
This function also marks <em>aio</em> itself permanently stopped, so that any
new operations scheduled by I/O providers using <a href="api//TODO.html"><code>nng_aio_begin</code></a>
return false. Thus this function should be used to teardown operations.</p>
<div class="mdbook-alerts mdbook-alerts-tip">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
tip
</p>
<p>When multiple asynchronous I/O handles are in use and need to be
deallocated, it is safest to stop all of them using <code>nng_aio_stop</code>,
before deallocating any of them with <a href="api//api/aio.html#destroy-handle"><code>nng_aio_free</code></a>,
particularly if the callbacks might attempt to reschedule further operations.</p>
</div>
<h2 id="set-timeout"><a class="header" href="#set-timeout">Set Timeout</a></h2>
<pre><code class="language-c">void nng_aio_set_timeout(nng_aio *aio, nng_duration timeout);
void nng_aio_set_expire(nng_aio *aio, nng_time expiration);
</code></pre>
<p>The <code>nng_aio_set_timeout</code> function sets a <a name="a012"></a><em>timeout</em>
for the asynchronous operation associated with <em>aio</em>.
This causes a timer to be started when the operation is actually started.
If the timer expires before the operation is completed, then it is
<a href="api//api/aio.html#cancellation">aborted</a> with an error of <code>NNG_ETIMEDOUT</code>.
The <em>timeout</em> <a href="api//api/time.html">duration</a> is specified as a relative number of milliseconds.</p>
<p>If the timeout is <a href="api//api/time.html#duration-type"><code>NNG_DURATION_INFINITE</code></a>, then no timeout is used.
If the timeout is <a href="api//api/time.html#duration-type"><code>NNG_DURATION_DEFAULT</code></a>, then a “default” or socket-specific
timeout is used.
(This is frequently the same as <a href="api//api/time.html#duration-type"><code>NNG_DURATION_INFINITE</code></a>.)</p>
<p>The <a name="a013"></a><code>nng_aio_set_expire</code> function is similar to <code>nng_aio_set_timeout</code>, but sets
an expiration time based on the system clock. The <em>expiration</em>
<a href="api//api/time.html">time</a> is a clock timestamp, such as would be returned by <a href="api//api/time.html#get-the-current-time"><code>nng_clock</code></a>.</p>
<h2 id="wait-for-completion"><a class="header" href="#wait-for-completion">Wait for Completion</a></h2>
<pre><code class="language-c">void nng_aio_wait(nng_aio *aio);
</code></pre>
<p>The <a name="a014"></a><code>nng_aio_wait</code> function waits for an asynchronous I/O operation to complete.
If the operation has not been started, or has already completed, then it returns immediately.</p>
<p>If a callback was set with <em>aio</em> when it was allocated, then this
function will not be called until the callback has completed.</p>
<div class="mdbook-alerts mdbook-alerts-important">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
important
</p>
<p>The <code>nng_aio_wait</code> function should never be called from a function that itself
is a callback of an <a href="api//api/aio.html#asynchronous-io-handle"><code>nng_aio</code></a>, either this one or any other.
Doing so may result in a deadlock.</p>
</div>
<h2 id="test-for-completion"><a class="header" href="#test-for-completion">Test for Completion</a></h2>
<pre><code class="language-c">bool nng_aio_busy(nng_aio *aio);
</code></pre>
<p>The <a name="a015"></a><code>nng_aio_busy</code> function returns <code>true</code> if the <em>aio</em> is currently busy performing an
operation or is executing a completion callback. Otherwise it return <code>false</code>.
This is the same test used internally by <a href="api//api/aio.html#wait-for-completion"><code>nng_aio_wait</code></a>.</p>
<div class="mdbook-alerts mdbook-alerts-important">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
important
</p>
<p>The caller is responsible for coordinating any use of this with any reuse of the <em>aio</em>.
Because the <em>aio</em> can be reused use of this function can be racy.</p>
</div>
<h2 id="result-of-operation"><a class="header" href="#result-of-operation">Result of Operation</a></h2>
<pre><code class="language-c">int nng_aio_result(nng_aio *aio);
size_t nng_aio_count(nng_aio *aio);
</code></pre>
<p>The <a name="a016"></a><code>nng_aio_result</code> function returns the result of the operation associated
with the handle <em>aio</em>.
If the operation was successful, then 0 is returned.
Otherwise a non-zero <a href="api//api/errors.html">error</a> code, such as <a href="api//api/errors.html#NNG_ECANCELED"><code>NNG_ECANCELED</code></a> or <a href="api//api/errors.html#NNG_ETIMEDOUT"><code>NNG_ETIMEDOUT</code></a>, is returned.</p>
<p>For operations that transfer data, <a name="a017"></a><code>nng_aio_count</code> returns the
number of bytes transferred by the operation associated with the handle <em>aio</em>.
Operations that do not transfer data, or do not keep a count, may return zero for this function.</p>
<div class="mdbook-alerts mdbook-alerts-note">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
note
</p>
<p>The return value from these functions is undefined if the operation has not completed yet.
Either call these from the handle’s completion callback, or after waiting for the
operation to complete with <a href="api//api/aio.html#wait-for-completion"><code>nng_aio_wait</code></a>.</p>
</div>
<h2 id="messages-1"><a class="header" href="#messages-1">Messages</a></h2>
<pre><code class="language-c">nng_msg *nng_aio_get_msg(nng_aio *aio);
void nng_aio_set_msg(nng_aio *aio, nng_msg *msg);
</code></pre>
<p>The <a name="a018"></a><code>nng_aio_get_msg</code> and <a name="a019"></a><code>nng_aio_set_msg</code> functions retrieve and store a <a href="api//api/msg.html">message</a>
in <em>aio</em>.
For example, if a function to receive data is called, that function can generally be expected
to store a message on the asssociated <em>aio</em>, for the application to retrieve with
<code>nng_aio_get_msg</code>.
Conversely an application desiring to send a message <em>msg</em> will store it in the <em>aio</em> using
<code>nng_aio_set_msg</code>. The function implementing the send operation will retrieve the message
and arrange for it to be sent.</p>
<h3 id="message-ownership"><a class="header" href="#message-ownership">Message Ownership</a></h3>
<p>For send or transmit operations, the rule of thumb is that implementation of the operation
is responsible for taking ownership of the message (and releasing resources when it is complete),
if it will return success. If the operation will end in error, then the message will be
retained and it is the consuming application’s responsibility to dispose of the message.
This allows an application the opportunity to reuse the message to try again, if it so desires.</p>
<p>For receive operations, the implementation of the operation will set the message on the <em>aio</em>
on success, and the consuming application hasa responsibility to retrieve and dispose of the
message. Failure to do so will leak the message. If the operation does not complete successfully,
then no message is stored on the <em>aio</em>.</p>
<h2 id="io-vector"><a class="header" href="#io-vector">I/O Vector</a></h2>
<pre><code class="language-c">typedef struct nng_iov {
void * iov_buf;
size_t iov_len;
};
int nng_aio_set_iov(nng_aio *aio, unsigned int niov, nng_iov *iov);
</code></pre>
<p>For some operations, the unit of data transferred is not a <a href="api//api/msg.html">message</a>, but
rather a stream of bytes.</p>
<p>For these operations, an array of <em>niov</em> <a name="a020"></a><code>nng_iov</code> structures can be passed to
the <a name="a021"></a><code>nng_aio_set_iov</code> function to provide a scatter/gather array of
elements describing the location (<code>iov_buf</code>) and length (<code>iov_len</code>) of data,
to transfer.</p>
<p>The <em>iov</em> vector is copied into storage in the <em>aio</em> itself, so that callers may use stack allocated <code>nng_iov</code> structures.
The values pointed to by the <code>iov_buf</code> members are <em>not</em> copied by this function though.</p>
<p>A maximum of four (4) <code>nng_iov</code> members may be supplied.</p>
<div class="mdbook-alerts mdbook-alerts-tip">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
tip
</p>
<p>Most functions using <code>nng_iov</code> do not guarantee to transfer all of the data that they
are requested to. To be sure that correct amount of data is transferred, as well as to
start an attempt to complete any partial transfer, check the amount of data transferred by
calling <a href="api//api/aio.html#result-of-operation"><code>nng_aio_count</code></a>.</p>
</div>
<h2 id="inputs-and-outputs"><a class="header" href="#inputs-and-outputs">Inputs and Outputs</a></h2>
<pre><code class="language-c">void nng_aio_set_input(nng_aio *aio, unsigned int index, void *param);
void *nng_aio_get_output(nng_aio *aio, unsigned int index);
</code></pre>
<p>Asynchronous operations can take additional input parameters, and
provide additional result outputs besides the <a href="api//api/aio.html#result-of-operation">result</a> code.</p>
<p>The <code>nng_aio_set_input</code> function sets the input parameter at <em>index</em>
to <em>param</em> for the operation associated with <em>aio</em>.</p>
<p>The <code>nng_aio_get_output</code> function returns the output result at <em>index</em>
for the operation associated with <em>aio</em>.</p>
<p>The type and semantics of input parameters and output results are determined by specific
operations. The documentation for the operation should provide details.</p>
<p>The valid values of <em>index</em> range from zero (0) to three (3), as no operation
currently defined can accept more than four parameters or return more than four additional
results.</p>
<div class="mdbook-alerts mdbook-alerts-note">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
note
</p>
<p>If the <em>index</em> does not correspond to a defined input for the operation,
then <code>nng_aio_set_input</code> will have no effect, and <code>nng_aio_get_output</code> will
return <code>NULL</code>.</p>
</div>
<div class="mdbook-alerts mdbook-alerts-important">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
important
</p>
<p>It is an error to call this function while the <em>aio</em> is currently
in use by an active asynchronous operation.</p>
</div>
<h2 id="see-also-2"><a class="header" href="#see-also-2">See Also</a></h2>
<p><a href="api//api/synch.html">Synchronization</a>,
<a href="api//api/thread.html">Threads</a>,
<a href="api//api/time.html">Time</a></p>
<!-- Symbol cross reference -->
<!-- Macros -->
<!-- Protocols -->
<!-- Transports -->
<!-- Concept index -->
<div style="break-before: page; page-break-before: always;"></div><style>
.mdbook-alerts {
padding: 8px 16px;
margin-bottom: 16px;
border-left: 0.25em solid var(--mdbook-alerts-color);
}
.mdbook-alerts > *:first-child {
margin-top: 0;
}
.mdbook-alerts > *:last-child {
margin-bottom: 0;
}
.mdbook-alerts-title {
display: flex;
font-weight: 600;
align-items: center;
line-height: 1;
color: var(--mdbook-alerts-color);
text-transform: capitalize;
}
.mdbook-alerts-icon {
display: inline-block;
width: 1em;
height: 1em;
margin-right: 0.2em;
background-color: currentColor;
-webkit-mask: no-repeat center / 100%;
mask: no-repeat center / 100%;
-webkit-mask-image: var(--mdbook-alerts-icon);
mask-image: var(--mdbook-alerts-icon);
}
.mdbook-alerts-note {
--mdbook-alerts-color: rgb(9, 105, 218);
/* https://icon-sets.iconify.design/material-symbols/info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16v-4q0-.425-.288-.712T12 11q-.425 0-.712.288T11 12v4q0 .425.288.713T12 17m0-8q.425 0 .713-.288T13 8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8q0 .425.288.713T12 9m0 13q-2.075 0-3.9-.788t-3.175-2.137q-1.35-1.35-2.137-3.175T2 12q0-2.075.788-3.9t2.137-3.175q1.35-1.35 3.175-2.137T12 2q2.075 0 3.9.788t3.175 2.137q1.35 1.35 2.138 3.175T22 12q0 2.075-.788 3.9t-2.137 3.175q-1.35 1.35-3.175 2.138T12 22m0-2q3.35 0 5.675-2.325T20 12q0-3.35-2.325-5.675T12 4Q8.65 4 6.325 6.325T4 12q0 3.35 2.325 5.675T12 20m0-8"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-tip {
--mdbook-alerts-color: rgb(26, 127, 55);
/* https://icon-sets.iconify.design/material-symbols/lightbulb-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 22q-.825 0-1.412-.587T10 20h4q0 .825-.587 1.413T12 22m-3-3q-.425 0-.712-.288T8 18q0-.425.288-.712T9 17h6q.425 0 .713.288T16 18q0 .425-.288.713T15 19zm-.75-3q-1.725-1.025-2.738-2.75T4.5 9.5q0-3.125 2.188-5.312T12 2q3.125 0 5.313 2.188T19.5 9.5q0 2.025-1.012 3.75T15.75 16zm.6-2h6.3q1.125-.8 1.738-1.975T17.5 9.5q0-2.3-1.6-3.9T12 4Q9.7 4 8.1 5.6T6.5 9.5q0 1.35.613 2.525T8.85 14M12 14"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-important {
--mdbook-alerts-color: rgb(130, 80, 223);
/* https://icon-sets.iconify.design/material-symbols/chat-info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 7q.425 0 .713-.288T13 6q0-.425-.288-.712T12 5q-.425 0-.712.288T11 6q0 .425.288.713T12 7m0 8q.425 0 .713-.288T13 14v-4q0-.425-.288-.712T12 9q-.425 0-.712.288T11 10v4q0 .425.288.713T12 15m-6 3l-2.3 2.3q-.475.475-1.088.213T2 19.575V4q0-.825.588-1.412T4 2h16q.825 0 1.413.588T22 4v12q0 .825-.587 1.413T20 18zm-.85-2H20V4H4v13.125zM4 16V4z"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-warning {
--mdbook-alerts-color: rgb(154, 103, 0);
/* https://icon-sets.iconify.design/material-symbols/warning-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M2.725 21q-.275 0-.5-.137t-.35-.363q-.125-.225-.137-.488t.137-.512l9.25-16q.15-.25.388-.375T12 3q.25 0 .488.125t.387.375l9.25 16q.15.25.138.513t-.138.487q-.125.225-.35.363t-.5.137zm1.725-2h15.1L12 6zM12 18q.425 0 .713-.288T13 17q0-.425-.288-.712T12 16q-.425 0-.712.288T11 17q0 .425.288.713T12 18m0-3q.425 0 .713-.288T13 14v-3q0-.425-.288-.712T12 10q-.425 0-.712.288T11 11v3q0 .425.288.713T12 15m0-2.5"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-caution {
--mdbook-alerts-color: rgb(207, 34, 46);
/* https://icon-sets.iconify.design/material-symbols/brightness-alert-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16q0-.425-.288-.712T12 15q-.425 0-.712.288T11 16q0 .425.288.713T12 17m0-4q.425 0 .713-.288T13 12V8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8v4q0 .425.288.713T12 13m-3.35 7H6q-.825 0-1.412-.587T4 18v-2.65L2.075 13.4q-.275-.3-.425-.662T1.5 12q0-.375.15-.737t.425-.663L4 8.65V6q0-.825.588-1.412T6 4h2.65l1.95-1.925q.3-.275.663-.425T12 1.5q.375 0 .738.15t.662.425L15.35 4H18q.825 0 1.413.588T20 6v2.65l1.925 1.95q.275.3.425.663t.15.737q0 .375-.15.738t-.425.662L20 15.35V18q0 .825-.587 1.413T18 20h-2.65l-1.95 1.925q-.3.275-.662.425T12 22.5q-.375 0-.737-.15t-.663-.425zm.85-2l2.5 2.5l2.5-2.5H18v-3.5l2.5-2.5L18 9.5V6h-3.5L12 3.5L9.5 6H6v3.5L3.5 12L6 14.5V18zm2.5-6"%2F%3E%3C%2Fsvg%3E');
}
</style>
<h1 id="synchronization-primitives"><a class="header" href="#synchronization-primitives">Synchronization Primitives</a></h1>
<p>In order to allow safely accessing shared state, or to allow coordination between
different <a href="api//api/thread.html">threads</a>, <em>NNG</em> provides <a name="a001"></a>synchronization primitives in the
form of mutual exclusion locks and condition variables.</p>
<p>Correct use of these primitives will be needed when accessing shared state from
threads, or from callback functions associated with <a href="api//api/aio.html">asynchronous operations</a>.
(The need to do this in callbacks is because the callback may be executed under
a task thread other than the submitting thread.)</p>
<h2 id="mutual-exclusion-lock"><a class="header" href="#mutual-exclusion-lock">Mutual Exclusion Lock</a></h2>
<pre><code class="language-c">typedef struct nng_mtx nng_mtx;
</code></pre>
<p>Mutual exclusion locks, or <a name="a002"></a>mutex locks, represented by the <a name="a003"></a><code>nng_mtx</code> structure,
allow only a single <a href="api//api/thread.html">thread</a> to lock “own” the lock, acquired by <a href="api//api/synch.html#acquiring-a-mutex"><code>nng_mtx_lock</code></a>.
Any other thread trying to acquire the same mutex will wait until the owner has released the mutex
by calling <a href="api//api/synch.html#releasing-a-mutex"><code>nng_mtx_unlock</code></a>.</p>
<h3 id="creating-a-mutex"><a class="header" href="#creating-a-mutex">Creating a Mutex</a></h3>
<pre><code class="language-c">int nng_mutx_alloc(nng_mt **mtxp);
</code></pre>
<p>A mutex can be created by allocating one with <a name="a004"></a><code>nng_mtx_lock</code>.
On success, a pointer to the mutex is returned through <em>mtxp</em>.
This function can fail due to insufficient memory or resources, in which
case it will return <a href="api//api/errors.html#NNG_ENOMEM"><code>NNG_ENOMEM</code></a>. Otherwise it will succceed and return zero.</p>
<h3 id="destroying-a-mutex"><a class="header" href="#destroying-a-mutex">Destroying a Mutex</a></h3>
<pre><code class="language-c">void nng_mtx_free(nng_mtx *mtx);
</code></pre>
<p>When no longer needed, a mutex can be deallocated and its resources returned
to the caller, by calling <a name="a005"></a><code>nng_mtx_free</code>. The mutex must not be locked
by any <a href="api//api/thread.html">thread</a> when calling this function.</p>
<h3 id="acquiring-a-mutex"><a class="header" href="#acquiring-a-mutex">Acquiring a Mutex</a></h3>
<pre><code class="language-c">void nng_mtx_lock(nng_mtx *mtx);
</code></pre>
<p>The <a name="a006"></a><code>nng_mtx_lock</code> function acquires ownership of a mutex, waiting for it to
unowned by any other threads if necessary.</p>
<div class="mdbook-alerts mdbook-alerts-important">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
important
</p>
<p>A thread must not attempt to reqacuire the same mutex while it already “owns” the mutex.
If it does attempt to do so, the result will be a single party deadlock.</p>
</div>
<h3 id="releasing-a-mutex"><a class="header" href="#releasing-a-mutex">Releasing a Mutex</a></h3>
<pre><code class="language-c">void nng_mtx_unlock(nng_mtx *mtx);
</code></pre>
<p>The <a name="a007"></a><code>nng_mtx_unlock</code> function releases a mutex that the calling thread has previously
acquired with <a href="api//api/synch.html#acquiring-a-mutex"><code>nng_mtx_lock</code></a>.</p>
<div class="mdbook-alerts mdbook-alerts-important">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
important
</p>
<p>A thread must not attempt to release (unlock) a mutex if it was not the thread
that acquired the mutex to begin with.</p>
</div>
<h2 id="condition-variable"><a class="header" href="#condition-variable">Condition Variable</a></h2>
<pre><code class="language-c">typedef struct nng_cv nng_cv;
</code></pre>
<p>The <a name="a008"></a><code>nng_cv</code> structure implements a <a name="a009"></a>condition variable, associated with the
the <a href="api//api/synch.html#mutual-exclusion-lock">mutex</a> <em>mtx</em> which was supplied when it was created.</p>
<p>Condition variables provide for a way to wait on an arbitrary condition, and to be woken
when the condition is signaled.
The mutex is dropped while the caller is asleep, and reacquired atomically when the caller
is woken.</p>
<div class="mdbook-alerts mdbook-alerts-important">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
important
</p>
<p>The caller of <code>nng_cv_until</code>, <code>nng_cv_wait</code>, <code>nng_cv_wake</code>, and <code>nng_cv_wake1</code> <em>must</em>
have ownership of the mutex <em>mtx</em> when calling these functions.</p>
</div>
<h3 id="creating-a-condition-variable"><a class="header" href="#creating-a-condition-variable">Creating a Condition Variable</a></h3>
<pre><code class="language-c">int nng_cv_alloc(nng_cv **cvp, nng_mtx *mtx);
</code></pre>
<p>The <a name="a010"></a><code>nng_cv_alloc</code> function allocates a condition variable, and associated with the mutex <em>mtx</em>,
and returns a pointer to it in <em>cvp</em>.</p>
<h3 id="destroy-a-condition-variable"><a class="header" href="#destroy-a-condition-variable">Destroy a Condition Variable</a></h3>
<pre><code class="language-c">void nng_cv_free(nng_cv *cv);
</code></pre>
<p>The <a name="a011"></a><code>nng_cv_free</code> function deallocates the condition variable <em>cv</em>.</p>
<h3 id="waiting-for-the-condition"><a class="header" href="#waiting-for-the-condition">Waiting for the Condition</a></h3>
<pre><code class="language-c">int nng_cv_until(nng_cv *cv, nng_time when);
void nng_cv_wait(nng_cv *cv);
</code></pre>
<p>The <a name="a012"></a><code>nng_cv_until</code> and <a name="a013"></a><code>nng_cv_wait</code> functions put the caller to sleep until the condition
variable <em>cv</em> is signaled, or (in the case of <code>nng_cv_until</code>), the specified time <em>when</em>
(as determined by <a href="api//api/time.html#get-the-current-time"><code>nng_clock</code></a> is reached.</p>
<p>While <code>nng_cv_wait</code> never fails and so has no return value, the <code>nng_cv_until</code> function can
return <a href="api//api/errors.html#NNG_ETIMEDOUT"><code>NNG_ETIMEDOUT</code></a> if the time is reached before condition <em>cv</em> is signaled by
either <a href="api//api/synch.html#signaling-the-condition"><code>nng_cv_wake</code></a> or <a href="api//api/synch.html#signaling-the-condition"><code>nng_cv_wake1</code></a>.</p>
<h3 id="signaling-the-condition"><a class="header" href="#signaling-the-condition">Signaling the Condition</a></h3>
<pre><code class="language-c">void nng_cv_wake(nng_cv *cv);
void nng_cv_wake1(nng_cv *cv);
</code></pre>
<p>The <a name="a014"></a><code>nng_cv_wake</code> and <a name="a015"></a><code>nng_cv_wake1</code> functions wake threads waiting in
<a href="api//api/synch.html#waiting-for-the-condition"><code>nng_cv_until</code></a> or <a href="api//api/synch.html#waiting-for-the-condition"><code>nng_cv_wait</code></a>.
The difference between these functions is that
<code>nng_cv_wake</code> will wake <em>every</em> thread, whereas <code>nng_cv_wake1</code> will wake up exactly
one thread (which may be chosen randomly).</p>
<div class="mdbook-alerts mdbook-alerts-tip">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
tip
</p>
<p>Use of <code>nng_cv_wake1</code> may be used to reduce the “<a name="a016"></a>thundering herd” syndrom of waking
all threads concurrently, but should only be used in circumstances where the application
does not depend on <em>which</em> thread will be woken. When in doubt, <code>nng_cv_wake</code> is safer.</p>
</div>
<h2 id="examples-2"><a class="header" href="#examples-2">Examples</a></h2>
<h3 id="example-1-allocating-the-condition-variable"><a class="header" href="#example-1-allocating-the-condition-variable">Example 1: Allocating the condition variable</a></h3>
<pre><code class="language-c">nng_mtx *m;
nng_cv *cv;
nng_mtx_alloc(&m); // error checks elided
nng_cv_alloc(&cv, m);
</code></pre>
<h3 id="example-2-waiting-for-the-condition"><a class="header" href="#example-2-waiting-for-the-condition">Example 2: Waiting for the condition</a></h3>
<pre><code class="language-c">expire = nng_clock() + 1000; // 1 second in the future
nng_mtx_lock(m); // assume cv was allocated using m
while (!condition_true) {
if (nng_cv_until(cv, expire) == NNG_ETIMEDOUT) {
printf("Time out reached!\n");
break;
}
}
// condition_true is true
nng_mtx_unlock(m);
</code></pre>
<h3 id="example-3-signaling-the-condition"><a class="header" href="#example-3-signaling-the-condition">Example 3: Signaling the condition</a></h3>
<pre><code class="language-c">nng_mtx_lock(m);
condition_true = true;
nng_cv_wake(cv);
nng_mtx_unlock(m);
</code></pre>
<!-- Symbol cross reference -->
<!-- Macros -->
<!-- Protocols -->
<!-- Transports -->
<!-- Concept index -->
<h2 id="see-also-3"><a class="header" href="#see-also-3">See Also</a></h2>
<p><a href="api//api/thread.html">Threads</a>,
<a href="api//api/time.html">Time</a>,
<a href="api//api/aio.html">Asynchronous I/O</a></p>
<div style="break-before: page; page-break-before: always;"></div><style>
.mdbook-alerts {
padding: 8px 16px;
margin-bottom: 16px;
border-left: 0.25em solid var(--mdbook-alerts-color);
}
.mdbook-alerts > *:first-child {
margin-top: 0;
}
.mdbook-alerts > *:last-child {
margin-bottom: 0;
}
.mdbook-alerts-title {
display: flex;
font-weight: 600;
align-items: center;
line-height: 1;
color: var(--mdbook-alerts-color);
text-transform: capitalize;
}
.mdbook-alerts-icon {
display: inline-block;
width: 1em;
height: 1em;
margin-right: 0.2em;
background-color: currentColor;
-webkit-mask: no-repeat center / 100%;
mask: no-repeat center / 100%;
-webkit-mask-image: var(--mdbook-alerts-icon);
mask-image: var(--mdbook-alerts-icon);
}
.mdbook-alerts-note {
--mdbook-alerts-color: rgb(9, 105, 218);
/* https://icon-sets.iconify.design/material-symbols/info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16v-4q0-.425-.288-.712T12 11q-.425 0-.712.288T11 12v4q0 .425.288.713T12 17m0-8q.425 0 .713-.288T13 8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8q0 .425.288.713T12 9m0 13q-2.075 0-3.9-.788t-3.175-2.137q-1.35-1.35-2.137-3.175T2 12q0-2.075.788-3.9t2.137-3.175q1.35-1.35 3.175-2.137T12 2q2.075 0 3.9.788t3.175 2.137q1.35 1.35 2.138 3.175T22 12q0 2.075-.788 3.9t-2.137 3.175q-1.35 1.35-3.175 2.138T12 22m0-2q3.35 0 5.675-2.325T20 12q0-3.35-2.325-5.675T12 4Q8.65 4 6.325 6.325T4 12q0 3.35 2.325 5.675T12 20m0-8"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-tip {
--mdbook-alerts-color: rgb(26, 127, 55);
/* https://icon-sets.iconify.design/material-symbols/lightbulb-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 22q-.825 0-1.412-.587T10 20h4q0 .825-.587 1.413T12 22m-3-3q-.425 0-.712-.288T8 18q0-.425.288-.712T9 17h6q.425 0 .713.288T16 18q0 .425-.288.713T15 19zm-.75-3q-1.725-1.025-2.738-2.75T4.5 9.5q0-3.125 2.188-5.312T12 2q3.125 0 5.313 2.188T19.5 9.5q0 2.025-1.012 3.75T15.75 16zm.6-2h6.3q1.125-.8 1.738-1.975T17.5 9.5q0-2.3-1.6-3.9T12 4Q9.7 4 8.1 5.6T6.5 9.5q0 1.35.613 2.525T8.85 14M12 14"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-important {
--mdbook-alerts-color: rgb(130, 80, 223);
/* https://icon-sets.iconify.design/material-symbols/chat-info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 7q.425 0 .713-.288T13 6q0-.425-.288-.712T12 5q-.425 0-.712.288T11 6q0 .425.288.713T12 7m0 8q.425 0 .713-.288T13 14v-4q0-.425-.288-.712T12 9q-.425 0-.712.288T11 10v4q0 .425.288.713T12 15m-6 3l-2.3 2.3q-.475.475-1.088.213T2 19.575V4q0-.825.588-1.412T4 2h16q.825 0 1.413.588T22 4v12q0 .825-.587 1.413T20 18zm-.85-2H20V4H4v13.125zM4 16V4z"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-warning {
--mdbook-alerts-color: rgb(154, 103, 0);
/* https://icon-sets.iconify.design/material-symbols/warning-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M2.725 21q-.275 0-.5-.137t-.35-.363q-.125-.225-.137-.488t.137-.512l9.25-16q.15-.25.388-.375T12 3q.25 0 .488.125t.387.375l9.25 16q.15.25.138.513t-.138.487q-.125.225-.35.363t-.5.137zm1.725-2h15.1L12 6zM12 18q.425 0 .713-.288T13 17q0-.425-.288-.712T12 16q-.425 0-.712.288T11 17q0 .425.288.713T12 18m0-3q.425 0 .713-.288T13 14v-3q0-.425-.288-.712T12 10q-.425 0-.712.288T11 11v3q0 .425.288.713T12 15m0-2.5"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-caution {
--mdbook-alerts-color: rgb(207, 34, 46);
/* https://icon-sets.iconify.design/material-symbols/brightness-alert-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16q0-.425-.288-.712T12 15q-.425 0-.712.288T11 16q0 .425.288.713T12 17m0-4q.425 0 .713-.288T13 12V8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8v4q0 .425.288.713T12 13m-3.35 7H6q-.825 0-1.412-.587T4 18v-2.65L2.075 13.4q-.275-.3-.425-.662T1.5 12q0-.375.15-.737t.425-.663L4 8.65V6q0-.825.588-1.412T6 4h2.65l1.95-1.925q.3-.275.663-.425T12 1.5q.375 0 .738.15t.662.425L15.35 4H18q.825 0 1.413.588T20 6v2.65l1.925 1.95q.275.3.425.663t.15.737q0 .375-.15.738t-.425.662L20 15.35V18q0 .825-.587 1.413T18 20h-2.65l-1.95 1.925q-.3.275-.662.425T12 22.5q-.375 0-.737-.15t-.663-.425zm.85-2l2.5 2.5l2.5-2.5H18v-3.5l2.5-2.5L18 9.5V6h-3.5L12 3.5L9.5 6H6v3.5L3.5 12L6 14.5V18zm2.5-6"%2F%3E%3C%2Fsvg%3E');
}
</style>
<h1 id="threads"><a class="header" href="#threads">Threads</a></h1>
<p>Threads <a name="a001"></a> provide a means of representing multiple parallel execution contexts.
<em>NNG</em> makes use of this concept internally, but also provides for user applications
to utilize the same thread facilities. This allows one form of <a name="a002"></a>concurrency for
applications.</p>
<div class="mdbook-alerts mdbook-alerts-note">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
note
</p>
<p>Threads in <em>NNG</em> are built upon platform support, which may be based upon operating
system supplied threads, process, or coroutines. The appearance of concurrency does
not guarantee true concurrency, and scheduling between threads may not necessarily be
pre-emptive. While this will not adversely impact applications that use this facility
for I/O bound concurrency, it may not provide good results for purely <a name="a003"></a>CPU-bound operations.</p>
</div>
<div class="mdbook-alerts mdbook-alerts-important">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
important
</p>
<p>Thread objects created by this function may not be real system-level
threads capable of performing blocking I/O operations using normal blocking system calls.
If use of blocking system calls is required (not including APIs provided
by the <em>NNG</em> library itself of course), then real OS-specific threads
should be created instead (such as with <code>pthread_create</code> or similar functions.)
Blocking <em>NNG</em> library calls can however be made safely from <em>NNG</em> threads.</p>
</div>
<div class="mdbook-alerts mdbook-alerts-tip">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
tip
</p>
<p>The system may impose limits on the number of threads that can be created.
Typically applications should not create more than a dozen of these.
If greater concurrency or scalability is needed, consider instead using
an asynchronous model using <a href="api//api/aio.html#asynchronous-io-handle"><code>nng_aio</code></a> structures.</p>
</div>
<h2 id="thread-structure"><a class="header" href="#thread-structure">Thread Structure</a></h2>
<pre><code class="language-c">typedef struct nng_thread nng_thread;
</code></pre>
<p>The <a name="a004"></a><code>nng_thread</code> structure represnts a thread, which is a single execution context.
A given thread will have its own stack, and CPU registers. However global state, as well
as values allocated on the heap, will be shared and accessible to all threads in the system
(See the <a href="api//api/synch.html">Synchronization</a> chapter for functions to help with data sharing between different threads.)</p>
<p>Multiple threads can be thought of as running concurrently, even though
they might not actually do so.</p>
<p>I/O operations that block (i.e. wait for completion) will block the
thread, while allowing other threads to proceed.</p>
<h2 id="creating-a-thread"><a class="header" href="#creating-a-thread">Creating a Thread</a></h2>
<pre><code class="language-c">int nng_thread_create(nng_thread **thrp, void (*func)(void *), void *arg);
</code></pre>
<p>The <a name="a005"></a><code>nng_thread_create</code> function creates a thread, which will execute <em>func</em>, with
the given argument <em>arg</em>, and returns a pointer to it in <em>thrp</em>.</p>
<p>The thread may begin execution immediately.</p>
<p>The thread will persist until <em>func</em> returns.</p>
<p>This function returns zero on success, but may return <code>NNG_ENOMEM</code> if insufficient
resources to create a thread are available.</p>
<h2 id="destroying-a-thread"><a class="header" href="#destroying-a-thread">Destroying a Thread</a></h2>
<pre><code class="language-c">void nng_thread_destroy(nng_thread *thr);
</code></pre>
<p>The <a name="a006"></a><code>nng_thread_destroy</code> function waits for the thread <em>thr</em> to finish execution.
This function should be called to reclaim any resources associated with the thread when done.
It also has the effect of blocking execution in the caller until <em>thr</em> has completed executing.</p>
<h2 id="thread-names"><a class="header" href="#thread-names">Thread Names</a></h2>
<pre><code class="language-c">void nng_thread_set_name(nng_thread *thr, const char *name);
</code></pre>
<p>In order to facilitate debugging, <a name="a007"></a><code>nng_thread_set_name</code> may be called
to provide a name for the thread. This may change how the thread is represented
in debuggers. Not all platforms support setting the thread name.</p>
<h2 id="see-also-4"><a class="header" href="#see-also-4">See Also</a></h2>
<p><a href="api//api/synch.html">Synchronization</a>,
<a href="api//api/aio.html">Asynchronous Operations</a></p>
<!-- Symbol cross reference -->
<!-- Macros -->
<!-- Protocols -->
<!-- Transports -->
<!-- Concept index -->
<div style="break-before: page; page-break-before: always;"></div><style>
.mdbook-alerts {
padding: 8px 16px;
margin-bottom: 16px;
border-left: 0.25em solid var(--mdbook-alerts-color);
}
.mdbook-alerts > *:first-child {
margin-top: 0;
}
.mdbook-alerts > *:last-child {
margin-bottom: 0;
}
.mdbook-alerts-title {
display: flex;
font-weight: 600;
align-items: center;
line-height: 1;
color: var(--mdbook-alerts-color);
text-transform: capitalize;
}
.mdbook-alerts-icon {
display: inline-block;
width: 1em;
height: 1em;
margin-right: 0.2em;
background-color: currentColor;
-webkit-mask: no-repeat center / 100%;
mask: no-repeat center / 100%;
-webkit-mask-image: var(--mdbook-alerts-icon);
mask-image: var(--mdbook-alerts-icon);
}
.mdbook-alerts-note {
--mdbook-alerts-color: rgb(9, 105, 218);
/* https://icon-sets.iconify.design/material-symbols/info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16v-4q0-.425-.288-.712T12 11q-.425 0-.712.288T11 12v4q0 .425.288.713T12 17m0-8q.425 0 .713-.288T13 8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8q0 .425.288.713T12 9m0 13q-2.075 0-3.9-.788t-3.175-2.137q-1.35-1.35-2.137-3.175T2 12q0-2.075.788-3.9t2.137-3.175q1.35-1.35 3.175-2.137T12 2q2.075 0 3.9.788t3.175 2.137q1.35 1.35 2.138 3.175T22 12q0 2.075-.788 3.9t-2.137 3.175q-1.35 1.35-3.175 2.138T12 22m0-2q3.35 0 5.675-2.325T20 12q0-3.35-2.325-5.675T12 4Q8.65 4 6.325 6.325T4 12q0 3.35 2.325 5.675T12 20m0-8"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-tip {
--mdbook-alerts-color: rgb(26, 127, 55);
/* https://icon-sets.iconify.design/material-symbols/lightbulb-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 22q-.825 0-1.412-.587T10 20h4q0 .825-.587 1.413T12 22m-3-3q-.425 0-.712-.288T8 18q0-.425.288-.712T9 17h6q.425 0 .713.288T16 18q0 .425-.288.713T15 19zm-.75-3q-1.725-1.025-2.738-2.75T4.5 9.5q0-3.125 2.188-5.312T12 2q3.125 0 5.313 2.188T19.5 9.5q0 2.025-1.012 3.75T15.75 16zm.6-2h6.3q1.125-.8 1.738-1.975T17.5 9.5q0-2.3-1.6-3.9T12 4Q9.7 4 8.1 5.6T6.5 9.5q0 1.35.613 2.525T8.85 14M12 14"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-important {
--mdbook-alerts-color: rgb(130, 80, 223);
/* https://icon-sets.iconify.design/material-symbols/chat-info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 7q.425 0 .713-.288T13 6q0-.425-.288-.712T12 5q-.425 0-.712.288T11 6q0 .425.288.713T12 7m0 8q.425 0 .713-.288T13 14v-4q0-.425-.288-.712T12 9q-.425 0-.712.288T11 10v4q0 .425.288.713T12 15m-6 3l-2.3 2.3q-.475.475-1.088.213T2 19.575V4q0-.825.588-1.412T4 2h16q.825 0 1.413.588T22 4v12q0 .825-.587 1.413T20 18zm-.85-2H20V4H4v13.125zM4 16V4z"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-warning {
--mdbook-alerts-color: rgb(154, 103, 0);
/* https://icon-sets.iconify.design/material-symbols/warning-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M2.725 21q-.275 0-.5-.137t-.35-.363q-.125-.225-.137-.488t.137-.512l9.25-16q.15-.25.388-.375T12 3q.25 0 .488.125t.387.375l9.25 16q.15.25.138.513t-.138.487q-.125.225-.35.363t-.5.137zm1.725-2h15.1L12 6zM12 18q.425 0 .713-.288T13 17q0-.425-.288-.712T12 16q-.425 0-.712.288T11 17q0 .425.288.713T12 18m0-3q.425 0 .713-.288T13 14v-3q0-.425-.288-.712T12 10q-.425 0-.712.288T11 11v3q0 .425.288.713T12 15m0-2.5"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-caution {
--mdbook-alerts-color: rgb(207, 34, 46);
/* https://icon-sets.iconify.design/material-symbols/brightness-alert-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16q0-.425-.288-.712T12 15q-.425 0-.712.288T11 16q0 .425.288.713T12 17m0-4q.425 0 .713-.288T13 12V8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8v4q0 .425.288.713T12 13m-3.35 7H6q-.825 0-1.412-.587T4 18v-2.65L2.075 13.4q-.275-.3-.425-.662T1.5 12q0-.375.15-.737t.425-.663L4 8.65V6q0-.825.588-1.412T6 4h2.65l1.95-1.925q.3-.275.663-.425T12 1.5q.375 0 .738.15t.662.425L15.35 4H18q.825 0 1.413.588T20 6v2.65l1.925 1.95q.275.3.425.663t.15.737q0 .375-.15.738t-.425.662L20 15.35V18q0 .825-.587 1.413T18 20h-2.65l-1.95 1.925q-.3.275-.662.425T12 22.5q-.375 0-.737-.15t-.663-.425zm.85-2l2.5 2.5l2.5-2.5H18v-3.5l2.5-2.5L18 9.5V6h-3.5L12 3.5L9.5 6H6v3.5L3.5 12L6 14.5V18zm2.5-6"%2F%3E%3C%2Fsvg%3E');
}
</style>
<h1 id="logging"><a class="header" href="#logging">Logging</a></h1>
<p>This chapter describes the support for message logs.
Both applications and <em>NNG</em> itself can emit logs, which can be useful
for application field support and debugging. Additionally applications
can customize the handling of this logging as needed.</p>
<p>Note that logging is disabled by default unless an application
configures a suitable logger with <a href="api/logging.html#log-handlers"><code>nng_log_set_logger</code></a>.</p>
<h2 id="submitting-logs"><a class="header" href="#submitting-logs">Submitting Logs</a></h2>
<pre><code class="language-c">void nng_log_err(const char *msgid, const char *msg, ...);
void nng_log_warn(const char *msgid, const char *msg, ...);
void nng_log_notice(const char *msgid, const char *msg, ...);
void nng_log_info(const char *msgid, const char *msg, ...);
void nng_log_debug(const char *msgid, const char *msg, ...);
</code></pre>
<p>These <a name="a001"></a> functions inject a a message into the
logging system, where it will be processed and potentially go to
system logs, standard output, or procssed further.</p>
<p>The <em>msgid</em> is a short prefix that should uniquely identify the message,
possibly also with some kind of category. It is recommended that
strings between 8 and 16 charactes be used. As this may, but will not necessarily
be displayed to the user, the content of the message should not appear
solely in this field. A <code>NULL</code> value is permitted here, but that may
make filtering the message or other automatic processing more difficult.</p>
<p>The <em>msg</em> is a <code>printf</code>-style format string, which is used to format the
message content. The following arguments are consumed in the
same manner as <code>printf</code>.</p>
<div class="mdbook-alerts mdbook-alerts-tip">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
tip
</p>
<p>Applications should take care to limit the use of higher severity levels, as message logs
are potentially expensive, increase stress for end users and administrators, and further may
mask real problems if incorrectly over used.</p>
<p>Warnings and error messages should be concise and actionable, and notices should only
really be those things that are worthy of attention.</p>
<p>Informational and debug messages used during development should be removed when no longer
needed, as these messages can overwhelm logging subsystems and can reduce the
signal-to-noise value for the message logs, impairing the diagnostic value of the logs.</p>
</div>
<h2 id="auth-logs"><a class="header" href="#auth-logs">Auth Logs</a></h2>
<pre><code class="language-c">void nng_log_auth(nng_log_level level, const char *msgid, const char *msg, ...);
</code></pre>
<p>The <a name="a002"></a><code>nng_log_auth</code> function formats and injects a security related log message.
(“Auth” can indicate either “authentication” or “authorization”.)
The <em>level</em> is a <a href="api/logging.html#log-levels">log level</a>.
The <em>msgid</em>, <em>msg</em>, and any remaining arguments are processed in a fashion
similar to the other <a href="api/logging.html#submitting-logs">logging functions</a>, except that the
logs may be are logged using the <code>NNG_LOG_AUTH</code> <a href="api/logging.html#log-facilities">facility</a>, and thus may be
redirected or receive other special treatment.</p>
<h2 id="log-levels"><a class="header" href="#log-levels">Log Levels</a></h2>
<pre><code class="language-c">typedef enum nng_log_level nng_log_level;
void nng_log_set_level(nng_log_level level);
nng_log_level nng_log_get_level(void);
</code></pre>
<p>The <a name="a003"></a><code>nng_log_level</code> type represents a severity for logged messages.
These levels correspond to those found in the UNIX syslog subsystem,
although applications should not depend upon the values being identical.</p>
<p>The <a name="a004"></a><code>nng_log_set_level</code> function sets the log level.
Messages with a severity that is numerically greater than this (less-severe)
will be discarded.</p>
<p>The <a name="a005"></a><code>nng_log_get_level</code> function returns the log level most recently
set by <code>nng_log_set_level</code> or the default
if that function has not been called.</p>
<p>The log levels are defined as follows:</p>
<pre><code class="language-c">typedef enum nng_log_level {
NNG_LOG_NONE = 0, // used for filters only, NNG suppresses these
NNG_LOG_ERR = 3,
NNG_LOG_WARN = 4,
NNG_LOG_NOTICE = 5,
NNG_LOG_INFO = 6,
NNG_LOG_DEBUG = 7
} nng_log_level;
</code></pre>
<p>The value <code>NNG_LOG_NONE</code> may be useful to suppress message logs altogether.</p>
<p>The default level is typically <code>NNG_LOG_NOTICE</code>, but applications should
select a value rather than relying upon the default.</p>
<h2 id="log-facilities"><a class="header" href="#log-facilities">Log Facilities</a></h2>
<pre><code class="language-c">typedef enum nng_log_facility
void nng_log_set_facility(nng_log_facility facility);
</code></pre>
<p>Logging facilities are used to indicate the source of a log message,
and may be useful in routing and processing these logs.
Traditionally these are used with the UNIX <code>syslog</code> system, and
the values here represent some (but not all) of the values found there.</p>
<p>The following values are defined:</p>
<pre><code class="language-c">typedef enum nng_log_facility {
NNG_LOG_USER = 1,
NNG_LOG_DAEMON = 3,
NNG_LOG_AUTH = 10,
NNG_LOG_LOCAL0 = 16,
NNG_LOG_LOCAL1 = 17,
NNG_LOG_LOCAL2 = 18,
NNG_LOG_LOCAL3 = 19,
NNG_LOG_LOCAL4 = 20,
NNG_LOG_LOCAL5 = 21,
NNG_LOG_LOCAL6 = 22,
NNG_LOG_LOCAL7 = 23,
} nng_log_facility;
</code></pre>
<p>The <a name="a006"></a><code>nng_log_set_facility</code> function can be used to
set the facility that the application will use when emitting log
messages. This should be called as part of initialization of the
application, if logging is to be used.</p>
<p>The default facility is typically <code>NNG_LOG_USER</code>, but applications should
select a value rather than relying upon the default.</p>
<h2 id="log-handlers"><a class="header" href="#log-handlers">Log Handlers</a></h2>
<pre><code class="language-c">typedef void (*nng_logger)(nng_log_level level, nng_log_facility facility,
const char *msgid, const char *msg);
void nng_null_logger(nng_log_level, nng_log_facility, const char *, const char *);
void nng_stderr_logger(nng_log_level, nng_log_facility, const char *, const char *);
void nng_system_logger(nng_log_level, nng_log_facility, const char *, const char *);
void nng_log_set_logger(nng_logger logger);
</code></pre>
<p><a name="a007"></a>Log handlers are responsible for actually processing the logged messages.</p>
<p>The <a name="a008"></a><code>nng_log_set_logger</code> function installs the named <em>logger</em>, of type <a name="a009"></a><code>nng_logger</code>,
as the log handler. The function <em>logger</em> will be called when any message is meant to
be processed. (Messages are first filtered by <a href="api/logging.html#log-levels">severity</a>, then formatted,
before calling the logger.)</p>
<p>Any previously installed logger is replaced by <em>logger</em>.</p>
<p>The <a name="a010"></a><code>nng_null_logger</code> function is an implementation of <code>nng_logger</code> that simply discards the content.
This is the default logger, so logging is disabled by default.</p>
<p>The <a name="a011"></a><code>nng_stderr_logger</code> function is an implementation that logs messages to the standard error stream.
It will attempt to colorize messages by the severity, if the standard error is a terminal device.
This can be suppressed by setting either the <code>NO_COLOR</code> or <code>NNG_LOG_NO_COLOR</code> environment variables.</p>
<p>The <a name="a012"></a><code>nng_system_logger</code> attempts to use an appropriate system facility to log messages.
For POSIX systems, this means using <code>syslog</code> to process the messages.
For other systems the defauilt behavior may be the same as <code>nng_stderr_logger</code>.</p>
<h2 id="see-also-5"><a class="header" href="#see-also-5">See Also</a></h2>
<p>The Syslog Protocol upon which this is based is documented in the following two IETF
RFCS,</p>
<ul>
<li>R. Gerhards, <a href="https://datatracker.ietf.org/doc/html/rfc5424">RFC 5424</a>, <em>The Syslog Protocol</em>,
March 2009</li>
<li>C. Lonvick, <a href="https://datatracker.ietf.org/doc/html/rfc3164">RFC 3164</a>, <em>The BSD syslog Protocol</em>,
August 2001</li>
</ul>
<div style="break-before: page; page-break-before: always;"></div><style>
.mdbook-alerts {
padding: 8px 16px;
margin-bottom: 16px;
border-left: 0.25em solid var(--mdbook-alerts-color);
}
.mdbook-alerts > *:first-child {
margin-top: 0;
}
.mdbook-alerts > *:last-child {
margin-bottom: 0;
}
.mdbook-alerts-title {
display: flex;
font-weight: 600;
align-items: center;
line-height: 1;
color: var(--mdbook-alerts-color);
text-transform: capitalize;
}
.mdbook-alerts-icon {
display: inline-block;
width: 1em;
height: 1em;
margin-right: 0.2em;
background-color: currentColor;
-webkit-mask: no-repeat center / 100%;
mask: no-repeat center / 100%;
-webkit-mask-image: var(--mdbook-alerts-icon);
mask-image: var(--mdbook-alerts-icon);
}
.mdbook-alerts-note {
--mdbook-alerts-color: rgb(9, 105, 218);
/* https://icon-sets.iconify.design/material-symbols/info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16v-4q0-.425-.288-.712T12 11q-.425 0-.712.288T11 12v4q0 .425.288.713T12 17m0-8q.425 0 .713-.288T13 8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8q0 .425.288.713T12 9m0 13q-2.075 0-3.9-.788t-3.175-2.137q-1.35-1.35-2.137-3.175T2 12q0-2.075.788-3.9t2.137-3.175q1.35-1.35 3.175-2.137T12 2q2.075 0 3.9.788t3.175 2.137q1.35 1.35 2.138 3.175T22 12q0 2.075-.788 3.9t-2.137 3.175q-1.35 1.35-3.175 2.138T12 22m0-2q3.35 0 5.675-2.325T20 12q0-3.35-2.325-5.675T12 4Q8.65 4 6.325 6.325T4 12q0 3.35 2.325 5.675T12 20m0-8"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-tip {
--mdbook-alerts-color: rgb(26, 127, 55);
/* https://icon-sets.iconify.design/material-symbols/lightbulb-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 22q-.825 0-1.412-.587T10 20h4q0 .825-.587 1.413T12 22m-3-3q-.425 0-.712-.288T8 18q0-.425.288-.712T9 17h6q.425 0 .713.288T16 18q0 .425-.288.713T15 19zm-.75-3q-1.725-1.025-2.738-2.75T4.5 9.5q0-3.125 2.188-5.312T12 2q3.125 0 5.313 2.188T19.5 9.5q0 2.025-1.012 3.75T15.75 16zm.6-2h6.3q1.125-.8 1.738-1.975T17.5 9.5q0-2.3-1.6-3.9T12 4Q9.7 4 8.1 5.6T6.5 9.5q0 1.35.613 2.525T8.85 14M12 14"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-important {
--mdbook-alerts-color: rgb(130, 80, 223);
/* https://icon-sets.iconify.design/material-symbols/chat-info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 7q.425 0 .713-.288T13 6q0-.425-.288-.712T12 5q-.425 0-.712.288T11 6q0 .425.288.713T12 7m0 8q.425 0 .713-.288T13 14v-4q0-.425-.288-.712T12 9q-.425 0-.712.288T11 10v4q0 .425.288.713T12 15m-6 3l-2.3 2.3q-.475.475-1.088.213T2 19.575V4q0-.825.588-1.412T4 2h16q.825 0 1.413.588T22 4v12q0 .825-.587 1.413T20 18zm-.85-2H20V4H4v13.125zM4 16V4z"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-warning {
--mdbook-alerts-color: rgb(154, 103, 0);
/* https://icon-sets.iconify.design/material-symbols/warning-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M2.725 21q-.275 0-.5-.137t-.35-.363q-.125-.225-.137-.488t.137-.512l9.25-16q.15-.25.388-.375T12 3q.25 0 .488.125t.387.375l9.25 16q.15.25.138.513t-.138.487q-.125.225-.35.363t-.5.137zm1.725-2h15.1L12 6zM12 18q.425 0 .713-.288T13 17q0-.425-.288-.712T12 16q-.425 0-.712.288T11 17q0 .425.288.713T12 18m0-3q.425 0 .713-.288T13 14v-3q0-.425-.288-.712T12 10q-.425 0-.712.288T11 11v3q0 .425.288.713T12 15m0-2.5"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-caution {
--mdbook-alerts-color: rgb(207, 34, 46);
/* https://icon-sets.iconify.design/material-symbols/brightness-alert-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16q0-.425-.288-.712T12 15q-.425 0-.712.288T11 16q0 .425.288.713T12 17m0-4q.425 0 .713-.288T13 12V8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8v4q0 .425.288.713T12 13m-3.35 7H6q-.825 0-1.412-.587T4 18v-2.65L2.075 13.4q-.275-.3-.425-.662T1.5 12q0-.375.15-.737t.425-.663L4 8.65V6q0-.825.588-1.412T6 4h2.65l1.95-1.925q.3-.275.663-.425T12 1.5q.375 0 .738.15t.662.425L15.35 4H18q.825 0 1.413.588T20 6v2.65l1.925 1.95q.275.3.425.663t.15.737q0 .375-.15.738t-.425.662L20 15.35V18q0 .825-.587 1.413T18 20h-2.65l-1.95 1.925q-.3.275-.662.425T12 22.5q-.375 0-.737-.15t-.663-.425zm.85-2l2.5 2.5l2.5-2.5H18v-3.5l2.5-2.5L18 9.5V6h-3.5L12 3.5L9.5 6H6v3.5L3.5 12L6 14.5V18zm2.5-6"%2F%3E%3C%2Fsvg%3E');
}
</style>
<h1 id="statistics"><a class="header" href="#statistics">Statistics</a></h1>
<p>To facilitate debugging and support situations, the <em>NNG</em> library
provides for collection and reporting of numerous <a name="a001"></a>statistics.</p>
<p>These statistics are organized in a tree, and include both values,
and metadata describing the statistics. In order to be efficient and
minimize the impact of maintaining statistics, an explicit snapshot
of statistics must be taken, and that snapshot can then be processed.</p>
<div class="mdbook-alerts mdbook-alerts-note">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
note
</p>
<p>Statistics may be disabled by build-time configuration options,
in order to reduce program size and run-time overheads.</p>
</div>
<h2 id="statistic-structure"><a class="header" href="#statistic-structure">Statistic Structure</a></h2>
<pre><code class="language-c">typedef struct nng_stat nng_stat;
</code></pre>
<p>The <a name="a002"></a><code>nng_stat</code> structure represents a statistic, which is a single value
collected at a specific point in time.</p>
<p>This structure has meta-data describing the value, the value itself, and links
to any sibling or child statistics.</p>
<div class="mdbook-alerts mdbook-alerts-note">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
note
</p>
<p>The presence, name, and semantics of any given statistic are
subject to change at any time and without notice.</p>
</div>
<h2 id="collecting-a-snapshot"><a class="header" href="#collecting-a-snapshot">Collecting a Snapshot</a></h2>
<pre><code class="language-c">int nng_stats_get(nng_stat **statsp);
</code></pre>
<p>The <a name="a003"></a><code>nng_stats_get</code> function takes a snapshot of the statistics for
the system and returns it through the pointer <em>statsp</em>.
This function may return <a href="api//api/errors.html#NNG_ENOMEM"><code>NNG_ENOMEM</code></a> if memory is exhausted, or <a href="api//api/errors.html#NNG_ENOTSUP"><code>NNG_ENOTSUP</code></a> if the statistics
support is not enabled in the build, but is otherwise expected to return zero.</p>
<h2 id="freeing-a-snapshot"><a class="header" href="#freeing-a-snapshot">Freeing a Snapshot</a></h2>
<pre><code class="language-c">void nng_stats_free(nng_stat *stat);
</code></pre>
<p>The <a name="a004"></a><code>nng_stats_free</code> function deallocates the snapshot referenced by <em>stat</em>.</p>
<div class="mdbook-alerts mdbook-alerts-important">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
important
</p>
<p>The <em>stat</em> must be root of the statistics tree, i.e. the value that was returned
through <em>statsp</em> using the function <code>nng_stats_get</code>.</p>
</div>
<h2 id="traversing-the-tree"><a class="header" href="#traversing-the-tree">Traversing the Tree</a></h2>
<pre><code class="language-c">const nng_stat *nng_stat_child(const nng_stat *stat);
const nng_stat *nng_stat_next(const nng_stat *stat);
</code></pre>
<p>Traversing the tree of statistics is done using the <a name="a005"></a><code>nng_stat_child</code> and
<a name="a006"></a><code>nng_stat_next</code> functions.</p>
<p>The <code>nng_stat_child</code> function returns either the first child of <em>stat</em>,
or <code>NULL</code> if the <em>stat</em> has no children.</p>
<p>The <code>nng_stat_next</code> function returns the nearest sibling to the right of <em>stat</em>,
or <code>NULL</code> if <em>stat</em> has no more siblings to the right.</p>
<h2 id="finding-a-statistic"><a class="header" href="#finding-a-statistic">Finding a Statistic</a></h2>
<pre><code class="language-c">const nng_stat *nng_stat_find(const nng_stat *stat, const char *name);
const nng_stat *nng_stat_find_dialer(const nng_stat *stat, nng_dialer dialer);
const nng_stat *nng_stat_find_listener(const nng_stat *stat, nng_dialer listener);
const nng_stat *nng_stat_find_socket(const nng_stat *stat, nng_dialer socket);
</code></pre>
<p>Sometimes it is easiest to search for a specific statistic, matching by name,
or possibly to find the tree of statistics associated iwth a specific <a href="api//TODO.html">socket</a>,
<a href="api//TODO.html">dialer</a>, or <a href="api//TODO.html">listener</a>.</p>
<p>The <code>nng_stat_find</code> functions are provided for this purpose.</p>
<p>The <a name="a007"></a><code>nng_stat_find</code> function returns the first statistic within the subtree of
statistics <em>stat</em>, with the given <em>name</em>. If no such statistic can be found, <code>NULL</code>
is returned.</p>
<p>The <a name="a008"></a><code>nng_stat_find_dialer</code>, <a name="a009"></a><code>nng_stat_find_listener</code>, and <a name="a010"></a><code>nng_stat_find_socket</code>
return the statistics subtree for the given dialer, listener, or socket object. If no such
statistic can be found, then they return <code>NULL</code>.
These functions should be provided the root of the statistic tree, in order to ensure
that they can find the desired object.</p>
<h2 id="statistic-identification"><a class="header" href="#statistic-identification">Statistic Identification</a></h2>
<pre><code class="language-c">const char *nng_stat_name(const nng_stat *stat);
const char *nng_stat_desc(const nng_stat *stat);
</code></pre>
<p>Every statistic has a name, returned by <a name="a011"></a><code>nng_stat_name</code>, and a description, returned by
<a name="a012"></a><code>nng_stat_desc</code>. Descriptions are human-readable text, which might be useful for display.</p>
<h2 id="statistic-type"><a class="header" href="#statistic-type">Statistic Type</a></h2>
<pre><code class="language-c">int nng_stat_type(const nng_stat *stat);
</code></pre>
<p>The function <a name="a013"></a><code>nng_stat_type</code> returns the type of the statistic.
The type of a statistic determines the nature of the value, and which
function can be used to obtain that value.</p>
<ul>
<li>
<p><a name="a014"></a><code>NNG_STAT_SCOPE</code>: <a name="NNG_STAT_SCOPE"></a>
The statistic does not carry any real value, but is
used for grouping related statistics together. This is a nexus in the
statistics tree.</p>
</li>
<li>
<p><a name="a015"></a><code>NNG_STAT_COUNTER</code>: <a name="NNG_STAT_COUNTER"></a>
The statistic is a counter that only increments.
Usually the change in the value of the statistic is more interesting
(as a rate) than the absolute value at any given time. The value should
be obtained using <a href="api//api/stats.html#statistic-value"><code>nng_stat_value</code></a>.
The units will be given by the value returned from <a href="api//api/stats.html#statistic-units"><code>nng_stat_unit</code></a>.</p>
</li>
<li>
<p><a name="a016"></a><code>NNG_STAT_LEVEL</code>: <a name="NNG_STAT_LEVEL"></a>
The statistic represnts a measured value which corresponds
to a specific value at a specific time. For example, this may represent the
number of messages currently queued for some operation, or the link speed
of a network interface. Most often the absolute value is more interesting
than the change in the value over time. Again the value can be obtained with
<a href="api//api/stats.html#statistic-value"><code>nng_stat_value</code></a>, and any appropriate unit of measurement
with <a href="api//api/stats.html#statistic-units"><code>nng_stat_unit</code></a>.</p>
</li>
<li>
<p><a name="a017"></a><code>NNG_STAT_STRING</code>: <a name="NNG_STAT_STRING"></a>
The statistic is a string, such as a name. The value
of the string can be obtained with <a href="api//api/stats.html#statistic-value"><code>nng_stat_string</code></a>.
The value of this string
will remain valid until the snapshot is deallocated with <a href="api//api/stats.html#freeing-a-snapshot"><code>nng_stats_free</code></a>.</p>
</li>
<li>
<p><a name="a018"></a><code>NNG_STAT_BOOLEAN</code>: <a name="NNG_STAT_BOOLEAN"></a>
The value of the statistic is a truth value (either <code>true</code>
or <code>false</code>) and can be obtained with <a href="api//api/stats.html#statistic-value"><code>nng_stat_bool</code></a>.</p>
</li>
<li>
<p><a name="a019"></a><code>NNG_STAT_ID</code>: <a name="NNG_STAT_ID"></a>
The value of the statistic is a numeric identifier, such as a socket
identifier. The value can be obtained with <a href="api//api/stats.html#statistic-value"><code>nng_stat_value</code></a>,
and will be fixed for the life of the statistic.</p>
</li>
</ul>
<h2 id="statistic-value"><a class="header" href="#statistic-value">Statistic Value</a></h2>
<pre><code class="language-c">uint64_t nng_stat_value(const nng_stat *stat);
const char *nng_stat_string(const nng_stat *stat);
bool nng_stat_bool(const nng_stat *stat);
</code></pre>
<p>These functions return the value associated with the statistic.</p>
<p>The <a name="a020"></a><code>nng_stat_value</code> function returns the the numeric value for the statistic <em>stat</em>
of type <a href="api//api/stats.html#NNG_STAT_COUNTER"><code>NNG_STAT_COUNTER</code></a>, <a href="api//api/stats.html#NNG_STAT_LEVEL"><code>NNG_STAT_LEVEL</code></a>, or <a href="api//api/stats.html#NNG_STAT_ID"><code>NNG_STAT_ID</code></a>.
If <em>stat</em> is not one of these types, then it returns zero.</p>
<p>The <a name="a021"></a><code>nng_stat_bool</code> function returns the Boolean value (either <code>true</code> or <code>false</code>) for the statistic <em>stat</em> of
type <a href="api//api/stats.html#NNG_STAT_BOOLEAN"><code>NNG_STAT_BOOLEAN</code></a>. If the statistics is not of this type, then it returns <code>false</code>.</p>
<p>The <a name="a022"></a><code>nng_stat_string</code> function returns a pointer to a string value for the statistic <em>stat</em>,
of type <a href="api//api/stats.html#statistic-value"><code>NNG_STAT_STRING</code></a>. This string will remain valud until the snapshot that
<em>stat</em> was collected with is deallocated with <a href="api//api/stats.html#freeing-a-snapshot"><code>nng_stats_free</code></a>. If the statistic
is not of type <code>NNG_STAT_STRING</code>, then <code>NULL</code> is returned.</p>
<h2 id="statistic-units"><a class="header" href="#statistic-units">Statistic Units</a></h2>
<pre><code class="language-c">int nng_stat_unit(const nng_stat *stat);
</code></pre>
<p>For statistics of type <a href="api//api/stats.html#NNG_STAT_COUNTER"><code>NNG_STAT_COUNTER</code></a> or <a href="api//api/stats.html#NNG_STAT_LEVEL"><code>NNG_STAT_LEVEL</code></a>,
it is often useful to know what that quantity being reported measures.
The following units may be returned from <a name="a023"></a><code>nng_stat_unit</code> for such a statistic:</p>
<ul>
<li><a name="a024"></a><code>NNG_UNIT_NONE</code>: No unit is known or applies.</li>
<li><a name="a025"></a><code>NNG_UNIT_BYTES</code>: A count of bytes.</li>
<li><a name="a026"></a><code>NNG_UNIT_MESSAGES</code>: A count of messages.</li>
<li><a name="a027"></a><code>NNG_UNIT_MILLIS</code>: A count of milliseconds.</li>
<li><a name="a028"></a><code>NNG_UNIT_EVENTS</code>: A count of events of some type.</li>
</ul>
<h2 id="statistic-timestamp"><a class="header" href="#statistic-timestamp">Statistic Timestamp</a></h2>
<pre><code class="language-c">uint64_t nng_stat_timestamp(const nng_stat *stat);
</code></pre>
<p>Statistics have a timestamp indicating when the value was sampled,
obtained via <a name="a029"></a><code>nng_stat_timestamp</code>. The timestamp is given in
in milliseconds since a reference time, and the reference time used
here is the same reference time used for <a href="api//api/time.html#get-the-current-time"><code>nng_clock</code></a>.</p>
<h2 id="see-also-6"><a class="header" href="#see-also-6">See Also</a></h2>
<p><a href="api//api/time.html#get-the-current-time"><code>nng_clock</code></a></p>
<!-- Symbol cross reference -->
<!-- Macros -->
<!-- Protocols -->
<!-- Transports -->
<!-- Concept index -->
<div style="break-before: page; page-break-before: always;"></div><style>
.mdbook-alerts {
padding: 8px 16px;
margin-bottom: 16px;
border-left: 0.25em solid var(--mdbook-alerts-color);
}
.mdbook-alerts > *:first-child {
margin-top: 0;
}
.mdbook-alerts > *:last-child {
margin-bottom: 0;
}
.mdbook-alerts-title {
display: flex;
font-weight: 600;
align-items: center;
line-height: 1;
color: var(--mdbook-alerts-color);
text-transform: capitalize;
}
.mdbook-alerts-icon {
display: inline-block;
width: 1em;
height: 1em;
margin-right: 0.2em;
background-color: currentColor;
-webkit-mask: no-repeat center / 100%;
mask: no-repeat center / 100%;
-webkit-mask-image: var(--mdbook-alerts-icon);
mask-image: var(--mdbook-alerts-icon);
}
.mdbook-alerts-note {
--mdbook-alerts-color: rgb(9, 105, 218);
/* https://icon-sets.iconify.design/material-symbols/info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16v-4q0-.425-.288-.712T12 11q-.425 0-.712.288T11 12v4q0 .425.288.713T12 17m0-8q.425 0 .713-.288T13 8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8q0 .425.288.713T12 9m0 13q-2.075 0-3.9-.788t-3.175-2.137q-1.35-1.35-2.137-3.175T2 12q0-2.075.788-3.9t2.137-3.175q1.35-1.35 3.175-2.137T12 2q2.075 0 3.9.788t3.175 2.137q1.35 1.35 2.138 3.175T22 12q0 2.075-.788 3.9t-2.137 3.175q-1.35 1.35-3.175 2.138T12 22m0-2q3.35 0 5.675-2.325T20 12q0-3.35-2.325-5.675T12 4Q8.65 4 6.325 6.325T4 12q0 3.35 2.325 5.675T12 20m0-8"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-tip {
--mdbook-alerts-color: rgb(26, 127, 55);
/* https://icon-sets.iconify.design/material-symbols/lightbulb-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 22q-.825 0-1.412-.587T10 20h4q0 .825-.587 1.413T12 22m-3-3q-.425 0-.712-.288T8 18q0-.425.288-.712T9 17h6q.425 0 .713.288T16 18q0 .425-.288.713T15 19zm-.75-3q-1.725-1.025-2.738-2.75T4.5 9.5q0-3.125 2.188-5.312T12 2q3.125 0 5.313 2.188T19.5 9.5q0 2.025-1.012 3.75T15.75 16zm.6-2h6.3q1.125-.8 1.738-1.975T17.5 9.5q0-2.3-1.6-3.9T12 4Q9.7 4 8.1 5.6T6.5 9.5q0 1.35.613 2.525T8.85 14M12 14"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-important {
--mdbook-alerts-color: rgb(130, 80, 223);
/* https://icon-sets.iconify.design/material-symbols/chat-info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 7q.425 0 .713-.288T13 6q0-.425-.288-.712T12 5q-.425 0-.712.288T11 6q0 .425.288.713T12 7m0 8q.425 0 .713-.288T13 14v-4q0-.425-.288-.712T12 9q-.425 0-.712.288T11 10v4q0 .425.288.713T12 15m-6 3l-2.3 2.3q-.475.475-1.088.213T2 19.575V4q0-.825.588-1.412T4 2h16q.825 0 1.413.588T22 4v12q0 .825-.587 1.413T20 18zm-.85-2H20V4H4v13.125zM4 16V4z"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-warning {
--mdbook-alerts-color: rgb(154, 103, 0);
/* https://icon-sets.iconify.design/material-symbols/warning-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M2.725 21q-.275 0-.5-.137t-.35-.363q-.125-.225-.137-.488t.137-.512l9.25-16q.15-.25.388-.375T12 3q.25 0 .488.125t.387.375l9.25 16q.15.25.138.513t-.138.487q-.125.225-.35.363t-.5.137zm1.725-2h15.1L12 6zM12 18q.425 0 .713-.288T13 17q0-.425-.288-.712T12 16q-.425 0-.712.288T11 17q0 .425.288.713T12 18m0-3q.425 0 .713-.288T13 14v-3q0-.425-.288-.712T12 10q-.425 0-.712.288T11 11v3q0 .425.288.713T12 15m0-2.5"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-caution {
--mdbook-alerts-color: rgb(207, 34, 46);
/* https://icon-sets.iconify.design/material-symbols/brightness-alert-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16q0-.425-.288-.712T12 15q-.425 0-.712.288T11 16q0 .425.288.713T12 17m0-4q.425 0 .713-.288T13 12V8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8v4q0 .425.288.713T12 13m-3.35 7H6q-.825 0-1.412-.587T4 18v-2.65L2.075 13.4q-.275-.3-.425-.662T1.5 12q0-.375.15-.737t.425-.663L4 8.65V6q0-.825.588-1.412T6 4h2.65l1.95-1.925q.3-.275.663-.425T12 1.5q.375 0 .738.15t.662.425L15.35 4H18q.825 0 1.413.588T20 6v2.65l1.925 1.95q.275.3.425.663t.15.737q0 .375-.15.738t-.425.662L20 15.35V18q0 .825-.587 1.413T18 20h-2.65l-1.95 1.925q-.3.275-.662.425T12 22.5q-.375 0-.737-.15t-.663-.425zm.85-2l2.5 2.5l2.5-2.5H18v-3.5l2.5-2.5L18 9.5V6h-3.5L12 3.5L9.5 6H6v3.5L3.5 12L6 14.5V18zm2.5-6"%2F%3E%3C%2Fsvg%3E');
}
</style>
<h1 id="errors"><a class="header" href="#errors">Errors</a></h1>
<p>Many <em>NNG</em> functions can fail for a variety of reasons.
These functions tend to return either zero on success,
or a non-zero error code to indicate failure.
<sup><a name="to-footnote-1"><a href="api/errors.html#footnote-1">1</a></a></sup></p>
<p>All these error codes are <code>int</code>.</p>
<p>Not every possible error code is defined here, as sometimes
an underlying system or library error code is “wrapped”.</p>
<h2 id="human-readable-error-message"><a class="header" href="#human-readable-error-message">Human Readable Error Message</a></h2>
<pre><code class="language-c">const char *nng_strerror(int err);
</code></pre>
<p>The <a name="a001"></a><code>nng_strerror</code> returns the human-readable description of the
given error in <code>err</code>.</p>
<p>The error message returned is a fixed <code>NUL</code>-terminated string and may be located in
read-only memory.</p>
<p>The returned <a name="a002"></a>error message is provided in US English, but in the
future locale-specific strings may be presented instead.</p>
<div class="mdbook-alerts mdbook-alerts-note">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
note
</p>
<p>The specific strings associated with specific error messages are
subject to change.
Therefore applications must not depend on the message,
but may use them verbatim when supplying information to end-users, such
as in diagnostic messages or log entries.</p>
</div>
<h2 id="list-of-errors"><a class="header" href="#list-of-errors">List of Errors</a></h2>
<div class="table-wrapper"><table><thead><tr><th>Error</th><th>Value</th><th>Description</th></tr></thead><tbody>
<tr><td><code>NNG_EINTR</code><a name="NNG_EINTR"></a></td><td>1</td><td>Operation interrupted.</td></tr>
<tr><td><code>NNG_ENOMEM</code><a name="NNG_ENOMEM"></a></td><td>2</td><td>Out of memory, or other resource exahusted.</td></tr>
<tr><td><code>NNG_EINVAL</code><a name="NNG_EINVAL"></a></td><td>3</td><td>Invalid argument. The arguments are invalid or malformed somehow.</td></tr>
<tr><td><code>NNG_EBUSY</code><a name="NNG_EBUSY"></a></td><td>4</td><td>Resource busy.</td></tr>
<tr><td><code>NNG_ETIMEDOUT</code><a name="NNG_ETIMEDOUT"></a></td><td>5</td><td>Timed out. The operation took longer than the allotted time.</td></tr>
<tr><td><code>NNG_ECONNREFUSED</code><a name="NNG_ECONNREFUSED"></a></td><td>6</td><td>Connection refused. Usually indicates the wrong address or a server is running.</td></tr>
<tr><td><code>NNG_ECLOSED</code><a name="NNG_ECLOSED"></a></td><td>7</td><td>Object closed. Typically the <a href="api//TODO.html">socket</a> is closed.</td></tr>
<tr><td><code>NNG_EAGAIN</code><a name="NNG_EAGAIN"></a></td><td>8</td><td>Try again. Typcally for a non-blocking operation that might succeed later.</td></tr>
<tr><td><code>NNG_ENOTSUP</code><a name="NNG_ENOTSUP"></a></td><td>9</td><td>Not supported. Perhaps the protocol or transport is not supported, or the operation is not not supported with the transport or protocol.</td></tr>
<tr><td><code>NNG_EADDRINUSE</code><a name="NNG_EADDRINUSE"></a></td><td>10</td><td>Address in use. The network address is already used by another process. Most often this is seen for <a href="api//TODO.html">listeners</a>.</td></tr>
<tr><td><code>NNG_ESTATE</code><a name="NNG_ESTATE"></a></td><td>11</td><td>Incorrect state. The operation cannot be performed in the current state, such as trying to send a response when no request has yet been received.</td></tr>
<tr><td><code>NNG_ENOENT</code><a name="NNG_ENOENT"></a></td><td>12</td><td>Entry not found (no such object.) Can also indicate that a file does not exist.</td></tr>
<tr><td><code>NNG_EPROTO</code><a name="NNG_EPROTO"></a></td><td>13</td><td>Protocol error. Typically this indicates incorrect messages over a network.</td></tr>
<tr><td><code>NNG_EUNREACHABLE</code><a name="NNG_EUNREACHABLE"></a></td><td>14</td><td>Destination unreachable.</td></tr>
<tr><td><code>NNG_EADDRINVAL</code><a name="NNG_EADDRINVAL"></a></td><td>15</td><td>Address invalid. Like <a href="api//api/errors.html#NNG_EINVAL"><code>NNG_EINVAL</code></a>, but only for network addresses.</td></tr>
<tr><td><code>NNG_EPERM</code><a name="NNG_EPERM"></a></td><td>16</td><td>Permission denied.</td></tr>
<tr><td><code>NNG_EMSGSIZE</code><a name="NNG_EMSGSIZE"></a></td><td>17</td><td>Message too large.</td></tr>
<tr><td><code>NNG_ECONNABORTED</code><a name="NNG_ECONNABORTED"></a></td><td>18</td><td>Connection aborted. A connection attempt was aborted locally.</td></tr>
<tr><td><code>NNG_ECONNRESET</code><a name="NNG_ECONNRESET"></a></td><td>19</td><td>Connection reset. The remote peer reset the connection unexpectedly.</td></tr>
<tr><td><code>NNG_ECANCELED</code><a name="NNG_ECANCELED"></a></td><td>20</td><td>Operation canceled. Typically as a result of <a href="api//api/aio.html#cancellation"><code>nng_aio_cancel</code></a> or similar.</td></tr>
<tr><td><code>NNG_ENOFILES</code><a name="NNG_ENOFILES"></a></td><td>21</td><td>Out of files. Either the destination file system cannot store files, or all available file handles are used.</td></tr>
<tr><td><code>NNG_ENOSPC</code><a name="NNG_ENOSPC"></a></td><td>22</td><td>Out of space. Destination table or filesystem is full.</td></tr>
<tr><td><code>NNG_EEXIST</code><a name="NNG_EEXIST"></a></td><td>23</td><td>Resource already exists.</td></tr>
<tr><td><code>NNG_EREADONLY</code><a name="NNG_EREADONLY"></a></td><td>24</td><td>Read only resource. An attempt to modify a read-only file or other object.</td></tr>
<tr><td><code>NNG_EWRITEONLY</code><a name="NNG_EWRITEONLY"></a></td><td>25</td><td>Write only resource. A read operation failed because the object only supports writes.</td></tr>
<tr><td><code>NNG_ECRYPTO</code><a name="NNG_ECRYPTO"></a></td><td>26</td><td>Cryptographic error. Usually indicates an invalid key was used for TLS.</td></tr>
<tr><td><code>NNG_EPEERAUTH</code><a name="NNG_EPEERAUTH"></a></td><td>27</td><td>Peer could not be authenticated.</td></tr>
<tr><td><code>NNG_ENOARG</code><a name="NNG_ENOARG"></a></td><td>28</td><td>Option requires argument. A command-line option was supplied without an argument. Only used with <a href="api//api/cmd_opts.html#parse-command-line-options"><code>nng_opts_parse</code></a>.</td></tr>
<tr><td><code>NNG_EAMBIGUOUS</code><a name="NNG_EAMBIGUOUS"></a></td><td>29</td><td>Ambiguous option. The command line option could not be unambiguously resolved. Only used with <a href="api//api/cmd_opts.html#parse-command-line-options"><code>nng_opts_parse</code></a>.</td></tr>
<tr><td><code>NNG_EBADTYPE</code><a name="NNG_EBADTYPE"></a></td><td>30</td><td>Incorrect type. A type-specific function was used for an object of the wrong type.</td></tr>
<tr><td><code>NNG_ECONNSHUT</code><a name="NNG_ECONNSHUT"></a></td><td>31</td><td>Connection shutdown. The connection was shut down and cannot be used.</td></tr>
<tr><td><code>NNG_EINTERNAL</code><a name="NNG_EINTERNAL"></a></td><td>1000</td><td>An unidentifier internal error occurred.</td></tr>
<tr><td><code>NNG_ESYSERR</code><a name="NNG_ESYSERR"></a></td><td>0x10000000 - 0x1FFFFFFF</td><td>An unidentified system error occurred. These are errors reported by the operating system.</td></tr>
<tr><td><code>NNG_ETRANERR</code><a name="NNG_ETRANERR"></a></td><td>0x20000000 - 0x2FFFFFFF</td><td>An unidentified transport error occurred.</td></tr>
</tbody></table>
</div><!-- Symbol cross reference -->
<!-- Macros -->
<!-- Protocols -->
<!-- Transports -->
<!-- Concept index -->
<p><hr/>
<p><a name="footnote-1"><a href="api/errors.html#to-footnote-1">1</a></a>: This convention goes back to UNIX system calls,
which behave the same way, but <em>NNG</em> does not use a separate
<em>errno</em> variable.</p>
<div style="break-before: page; page-break-before: always;"></div><style>
.mdbook-alerts {
padding: 8px 16px;
margin-bottom: 16px;
border-left: 0.25em solid var(--mdbook-alerts-color);
}
.mdbook-alerts > *:first-child {
margin-top: 0;
}
.mdbook-alerts > *:last-child {
margin-bottom: 0;
}
.mdbook-alerts-title {
display: flex;
font-weight: 600;
align-items: center;
line-height: 1;
color: var(--mdbook-alerts-color);
text-transform: capitalize;
}
.mdbook-alerts-icon {
display: inline-block;
width: 1em;
height: 1em;
margin-right: 0.2em;
background-color: currentColor;
-webkit-mask: no-repeat center / 100%;
mask: no-repeat center / 100%;
-webkit-mask-image: var(--mdbook-alerts-icon);
mask-image: var(--mdbook-alerts-icon);
}
.mdbook-alerts-note {
--mdbook-alerts-color: rgb(9, 105, 218);
/* https://icon-sets.iconify.design/material-symbols/info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16v-4q0-.425-.288-.712T12 11q-.425 0-.712.288T11 12v4q0 .425.288.713T12 17m0-8q.425 0 .713-.288T13 8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8q0 .425.288.713T12 9m0 13q-2.075 0-3.9-.788t-3.175-2.137q-1.35-1.35-2.137-3.175T2 12q0-2.075.788-3.9t2.137-3.175q1.35-1.35 3.175-2.137T12 2q2.075 0 3.9.788t3.175 2.137q1.35 1.35 2.138 3.175T22 12q0 2.075-.788 3.9t-2.137 3.175q-1.35 1.35-3.175 2.138T12 22m0-2q3.35 0 5.675-2.325T20 12q0-3.35-2.325-5.675T12 4Q8.65 4 6.325 6.325T4 12q0 3.35 2.325 5.675T12 20m0-8"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-tip {
--mdbook-alerts-color: rgb(26, 127, 55);
/* https://icon-sets.iconify.design/material-symbols/lightbulb-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 22q-.825 0-1.412-.587T10 20h4q0 .825-.587 1.413T12 22m-3-3q-.425 0-.712-.288T8 18q0-.425.288-.712T9 17h6q.425 0 .713.288T16 18q0 .425-.288.713T15 19zm-.75-3q-1.725-1.025-2.738-2.75T4.5 9.5q0-3.125 2.188-5.312T12 2q3.125 0 5.313 2.188T19.5 9.5q0 2.025-1.012 3.75T15.75 16zm.6-2h6.3q1.125-.8 1.738-1.975T17.5 9.5q0-2.3-1.6-3.9T12 4Q9.7 4 8.1 5.6T6.5 9.5q0 1.35.613 2.525T8.85 14M12 14"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-important {
--mdbook-alerts-color: rgb(130, 80, 223);
/* https://icon-sets.iconify.design/material-symbols/chat-info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 7q.425 0 .713-.288T13 6q0-.425-.288-.712T12 5q-.425 0-.712.288T11 6q0 .425.288.713T12 7m0 8q.425 0 .713-.288T13 14v-4q0-.425-.288-.712T12 9q-.425 0-.712.288T11 10v4q0 .425.288.713T12 15m-6 3l-2.3 2.3q-.475.475-1.088.213T2 19.575V4q0-.825.588-1.412T4 2h16q.825 0 1.413.588T22 4v12q0 .825-.587 1.413T20 18zm-.85-2H20V4H4v13.125zM4 16V4z"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-warning {
--mdbook-alerts-color: rgb(154, 103, 0);
/* https://icon-sets.iconify.design/material-symbols/warning-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M2.725 21q-.275 0-.5-.137t-.35-.363q-.125-.225-.137-.488t.137-.512l9.25-16q.15-.25.388-.375T12 3q.25 0 .488.125t.387.375l9.25 16q.15.25.138.513t-.138.487q-.125.225-.35.363t-.5.137zm1.725-2h15.1L12 6zM12 18q.425 0 .713-.288T13 17q0-.425-.288-.712T12 16q-.425 0-.712.288T11 17q0 .425.288.713T12 18m0-3q.425 0 .713-.288T13 14v-3q0-.425-.288-.712T12 10q-.425 0-.712.288T11 11v3q0 .425.288.713T12 15m0-2.5"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-caution {
--mdbook-alerts-color: rgb(207, 34, 46);
/* https://icon-sets.iconify.design/material-symbols/brightness-alert-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16q0-.425-.288-.712T12 15q-.425 0-.712.288T11 16q0 .425.288.713T12 17m0-4q.425 0 .713-.288T13 12V8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8v4q0 .425.288.713T12 13m-3.35 7H6q-.825 0-1.412-.587T4 18v-2.65L2.075 13.4q-.275-.3-.425-.662T1.5 12q0-.375.15-.737t.425-.663L4 8.65V6q0-.825.588-1.412T6 4h2.65l1.95-1.925q.3-.275.663-.425T12 1.5q.375 0 .738.15t.662.425L15.35 4H18q.825 0 1.413.588T20 6v2.65l1.925 1.95q.275.3.425.663t.15.737q0 .375-.15.738t-.425.662L20 15.35V18q0 .825-.587 1.413T18 20h-2.65l-1.95 1.925q-.3.275-.662.425T12 22.5q-.375 0-.737-.15t-.663-.425zm.85-2l2.5 2.5l2.5-2.5H18v-3.5l2.5-2.5L18 9.5V6h-3.5L12 3.5L9.5 6H6v3.5L3.5 12L6 14.5V18zm2.5-6"%2F%3E%3C%2Fsvg%3E');
}
</style>
<h1 id="miscellaneous"><a class="header" href="#miscellaneous">Miscellaneous</a></h1>
<p>This chapter discusses some interfaces that don’t really
fit anywhere else.</p>
<h2 id="get-random-number"><a class="header" href="#get-random-number">Get Random Number</a></h2>
<pre><code class="language-c">uint32_t nng_random(void);
</code></pre>
<p>The <a name="a001"></a><code>nng_random</code> returns a <a name="a002"></a>random number.
The value returned is suitable for use with cryptographic functions such as
key generation, and is obtained using platform-specific cryptographically strong random
number facilities when available.</p>
<h2 id="create-socket-pair"><a class="header" href="#create-socket-pair">Create Socket Pair</a></h2>
<pre><code class="language-c">int nng_socket_pair(int fds[2]);
</code></pre>
<p>The <code>nng_socket_pair</code> function creates a pair of connected file descriptors.
These file descriptors, which are returned in the <em>fds</em> array, are suitable for
use with the <a href="api//tran/socket.html">Socket transport</a>.</p>
<p>On POSIX platforms, this is a thin wrapper around the standard <code>socketpair</code> function,
using the <a name="a003"></a><code>AF_UNIX</code> family and the <code>SOCK_STREAM</code> socket type.
<sup><a name="to-footnote-1"><a href="api/misc.html#footnote-1">1</a></a></sup></p>
<p>This will return zero on success, or an error number. On platforms that lack this
capability, such as Windows, it will return <code>NNG_ENOTSUP</code>.</p>
<div class="mdbook-alerts mdbook-alerts-tip">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
tip
</p>
<p>This function may be useful for creating a shared connection between a parent process and
a child process on UNIX platforms, without requiring the processes use a shared filesystem or TCP connection.</p>
</div>
<h2 id="report-library-version"><a class="header" href="#report-library-version">Report Library Version</a></h2>
<pre><code class="language-c">const char * nng_version(void);
</code></pre>
<p>The <a name="a004"></a><code>nng_version</code> function returns a human readable <a name="a005"></a>version number
for <em>NNG</em>, formatted as a <code>NUL</code>-terminated string.</p>
<p>Additionally, compile time version information is available
via some predefined macros:</p>
<ul>
<li><a name="a006"></a><code>NNG_MAJOR_VERSION</code>: Major version number.</li>
<li><a name="a007"></a><code>NNG_MINOR_VERSION</code>: Minor version number.</li>
<li><a name="a008"></a><code>NNG_PATCH_VERSION</code>: Patch version number.</li>
</ul>
<p><em>NNG</em> is developed and released using
<a href="http://www.semver.org">Semantic Versioning 2.0</a>, and
the version numbers reported refer to both the API and the library itself.
(The <a name="a009"></a>ABI – <a name="a010"></a>application binary interface – between the
library and the application is controlled in a similar, but different
manner depending upon the link options and how the library is built.)</p>
<!-- Symbol cross reference -->
<!-- Macros -->
<!-- Protocols -->
<!-- Transports -->
<!-- Concept index -->
<p><hr/>
<p><a name="footnote-1"><a href="api/misc.html#to-footnote-1">1</a></a>: At present only POSIX platforms implementing <code>socketpair</code> support this function.</p>
<div style="break-before: page; page-break-before: always;"></div><style>
.mdbook-alerts {
padding: 8px 16px;
margin-bottom: 16px;
border-left: 0.25em solid var(--mdbook-alerts-color);
}
.mdbook-alerts > *:first-child {
margin-top: 0;
}
.mdbook-alerts > *:last-child {
margin-bottom: 0;
}
.mdbook-alerts-title {
display: flex;
font-weight: 600;
align-items: center;
line-height: 1;
color: var(--mdbook-alerts-color);
text-transform: capitalize;
}
.mdbook-alerts-icon {
display: inline-block;
width: 1em;
height: 1em;
margin-right: 0.2em;
background-color: currentColor;
-webkit-mask: no-repeat center / 100%;
mask: no-repeat center / 100%;
-webkit-mask-image: var(--mdbook-alerts-icon);
mask-image: var(--mdbook-alerts-icon);
}
.mdbook-alerts-note {
--mdbook-alerts-color: rgb(9, 105, 218);
/* https://icon-sets.iconify.design/material-symbols/info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16v-4q0-.425-.288-.712T12 11q-.425 0-.712.288T11 12v4q0 .425.288.713T12 17m0-8q.425 0 .713-.288T13 8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8q0 .425.288.713T12 9m0 13q-2.075 0-3.9-.788t-3.175-2.137q-1.35-1.35-2.137-3.175T2 12q0-2.075.788-3.9t2.137-3.175q1.35-1.35 3.175-2.137T12 2q2.075 0 3.9.788t3.175 2.137q1.35 1.35 2.138 3.175T22 12q0 2.075-.788 3.9t-2.137 3.175q-1.35 1.35-3.175 2.138T12 22m0-2q3.35 0 5.675-2.325T20 12q0-3.35-2.325-5.675T12 4Q8.65 4 6.325 6.325T4 12q0 3.35 2.325 5.675T12 20m0-8"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-tip {
--mdbook-alerts-color: rgb(26, 127, 55);
/* https://icon-sets.iconify.design/material-symbols/lightbulb-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 22q-.825 0-1.412-.587T10 20h4q0 .825-.587 1.413T12 22m-3-3q-.425 0-.712-.288T8 18q0-.425.288-.712T9 17h6q.425 0 .713.288T16 18q0 .425-.288.713T15 19zm-.75-3q-1.725-1.025-2.738-2.75T4.5 9.5q0-3.125 2.188-5.312T12 2q3.125 0 5.313 2.188T19.5 9.5q0 2.025-1.012 3.75T15.75 16zm.6-2h6.3q1.125-.8 1.738-1.975T17.5 9.5q0-2.3-1.6-3.9T12 4Q9.7 4 8.1 5.6T6.5 9.5q0 1.35.613 2.525T8.85 14M12 14"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-important {
--mdbook-alerts-color: rgb(130, 80, 223);
/* https://icon-sets.iconify.design/material-symbols/chat-info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 7q.425 0 .713-.288T13 6q0-.425-.288-.712T12 5q-.425 0-.712.288T11 6q0 .425.288.713T12 7m0 8q.425 0 .713-.288T13 14v-4q0-.425-.288-.712T12 9q-.425 0-.712.288T11 10v4q0 .425.288.713T12 15m-6 3l-2.3 2.3q-.475.475-1.088.213T2 19.575V4q0-.825.588-1.412T4 2h16q.825 0 1.413.588T22 4v12q0 .825-.587 1.413T20 18zm-.85-2H20V4H4v13.125zM4 16V4z"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-warning {
--mdbook-alerts-color: rgb(154, 103, 0);
/* https://icon-sets.iconify.design/material-symbols/warning-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M2.725 21q-.275 0-.5-.137t-.35-.363q-.125-.225-.137-.488t.137-.512l9.25-16q.15-.25.388-.375T12 3q.25 0 .488.125t.387.375l9.25 16q.15.25.138.513t-.138.487q-.125.225-.35.363t-.5.137zm1.725-2h15.1L12 6zM12 18q.425 0 .713-.288T13 17q0-.425-.288-.712T12 16q-.425 0-.712.288T11 17q0 .425.288.713T12 18m0-3q.425 0 .713-.288T13 14v-3q0-.425-.288-.712T12 10q-.425 0-.712.288T11 11v3q0 .425.288.713T12 15m0-2.5"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-caution {
--mdbook-alerts-color: rgb(207, 34, 46);
/* https://icon-sets.iconify.design/material-symbols/brightness-alert-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16q0-.425-.288-.712T12 15q-.425 0-.712.288T11 16q0 .425.288.713T12 17m0-4q.425 0 .713-.288T13 12V8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8v4q0 .425.288.713T12 13m-3.35 7H6q-.825 0-1.412-.587T4 18v-2.65L2.075 13.4q-.275-.3-.425-.662T1.5 12q0-.375.15-.737t.425-.663L4 8.65V6q0-.825.588-1.412T6 4h2.65l1.95-1.925q.3-.275.663-.425T12 1.5q.375 0 .738.15t.662.425L15.35 4H18q.825 0 1.413.588T20 6v2.65l1.925 1.95q.275.3.425.663t.15.737q0 .375-.15.738t-.425.662L20 15.35V18q0 .825-.587 1.413T18 20h-2.65l-1.95 1.925q-.3.275-.662.425T12 22.5q-.375 0-.737-.15t-.663-.425zm.85-2l2.5 2.5l2.5-2.5H18v-3.5l2.5-2.5L18 9.5V6h-3.5L12 3.5L9.5 6H6v3.5L3.5 12L6 14.5V18zm2.5-6"%2F%3E%3C%2Fsvg%3E');
}
</style>
<h1 id="id-map"><a class="header" href="#id-map">ID Map</a></h1>
<p>Internally, <em>NNG</em> uses a map of numeric identifiers to data structures.
This feature is also exposed for application use, as a “supplemental” feature.</p>
<p>When using these functions, it is necessary to add the <code>#include <nng/supplemental/util/idhash.h></code>
include file to list of includes.</p>
<h2 id="id-map-structure"><a class="header" href="#id-map-structure">ID Map Structure</a></h2>
<pre><code class="language-c">#include <nng/nng.h>
#include <nng/supplemental/util/idhash.h>
typedef struct nng_id_map_s nng_id_map;
</code></pre>
<p>The ID map structure, <a name="a001"></a><code>nng_id_map</code> provides a table of identifiers mapping
to user-supplied pointers (which must not be <code>NULL</code>). The identifiers can be
thought of as indices into the table, with the pointers providing the reference
for the user supplied data.</p>
<p>The values of identifiers can be supplied by the user, or can be allocated automatically
by <code>nng_id_map</code> from a predefined range. The starting point for allocations
can also be randomly within the range.</p>
<p>The identifiers are 64-bit unsigned integers and can be sparse; the structure
will use space efficiently even if identifiers are very far apart.
<sup><a name="to-footnote-1"><a href="api/id_map.html#footnote-1">1</a></a></sup></p>
<div class="mdbook-alerts mdbook-alerts-important">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
important
</p>
<p>The function available for <code>nng_id_map</code> are <em>not</em> thread-safe.
Callers should use a <a href="api//api/synch.html#mutual-exclusion-lock">mutex</a> or similar approach when thread-safety is needed.</p>
</div>
<h2 id="create-id-map"><a class="header" href="#create-id-map">Create ID Map</a></h2>
<pre><code class="language-c">#define NNG_MAP_RANDOM 1
int nng_id_map_alloc(nng_id_map **map_p, uint64_t lo, uint64_t hi, int flags);
</code></pre>
<p>The <a name="a002"></a><code>nng_id_map_alloc</code> function allocates a map without any data in it,
and returns a pointer to it in <em>map_p</em>. When allocating identifiers dynamically,
the values will be chosen from the range defined by <em>lo</em> and <em>hi</em>, inclusive.</p>
<p>The <em>flags</em> argument is a bit mask of flags that can adjust behavior of the map.
The only flag defined at present
is <code>NNG_MAP_RANDOM</code>, which causes the first identifier allocation to start at a random
point within the range.
This is useful to reduce the odds of different instances of an application using
the same identifiers at the same time.</p>
<p>If both <em>lo</em> and <em>hi</em> are zero, then the values <code>0</code> and <code>0xffffffff</code> are substituted
in their place, giving a full range of 32-bit identifiers.</p>
<p>This function can return <a href="api//api/errors.html#NNG_ENOMEM"><code>NNG_ENOMEM</code></a> if it is unable to allocate resources, otherwise
it returns zero on success.</p>
<h2 id="destroy-map"><a class="header" href="#destroy-map">Destroy Map</a></h2>
<pre><code class="language-c">void nng_id_map_free(nng_id_map *map);
</code></pre>
<p>The <a name="a003"></a><code>nng_id_map_free</code> function destroys <em>map</em>, releasing any resources associated
with it.</p>
<div class="mdbook-alerts mdbook-alerts-note">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
note
</p>
<p>The <code>nng_id_map_free</code> frees the map itself, but will not free memory associated with
any strctures contained within it.</p>
</div>
<h2 id="store-a-value"><a class="header" href="#store-a-value">Store a Value</a></h2>
<pre><code class="language-c">int nng_id_set(nng_id_map *map, uint64_t id, void *value);
</code></pre>
<p>The <a name="a004"></a><code>nng_id_map_set</code> function is used to store the <em>value</em> in the <em>map</em> at
index <em>id</em>.</p>
<p>If another value is already stored at that same location, then it is overwritten with
<em>value</em>.</p>
<div class="mdbook-alerts mdbook-alerts-note">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
note
</p>
<p>The <em>value</em> must not be <code>NULL</code>.</p>
</div>
<p>If the table has to grow to accommodate this value, it may fail if insufficient
memory is available, returning <a href="api//api/errors.html#NNG_ENOMEM"><code>NNG_ENOMEM</code></a>. Otherwise it returns zero.</p>
<h2 id="lookup-a-value"><a class="header" href="#lookup-a-value">Lookup a Value</a></h2>
<pre><code class="language-c">void *nng_id_get(nng_id_map *map, uint64_t id);
</code></pre>
<p>The <a name="a005"></a><code>nng_id_get</code> function looks up the entry for <em>id</em> in <em>map</em>, returning the
associated value if present, or <code>NULL</code> if no such entry exists.</p>
<h2 id="allocate-an-id"><a class="header" href="#allocate-an-id">Allocate an ID</a></h2>
<pre><code class="language-c">int nng_id_alloc(nng_id_map *map, uint64_t *id_p, void *value);
</code></pre>
<p>The <a name="a006"></a><code>nng_id_alloc</code> stores the <em>value</em> in the <em>map</em>, at a newly allocated index,
and returns the index in <em>id_p</em>.</p>
<p>Identifiers are allocated in increasing order, without reusing old identifiers until the
largest possible identifier is allocated. After wrapping, only identifiers that are no longer
in use will be considered.
No effort is made to order the availability of identifiers based on
when they were freed.<sup><a name="to-footnote-2"><a href="api/id_map.html#footnote-2">2</a></a></sup></p>
<p>As with <a href="api//api/id_map.html#store-a-value"><code>nng_id_set</code></a>, this may need to allocate memory and can thus
fail with <a href="api//api/errors.html#NNG_ENOMEM"><code>NNG_ENOMEM</code></a>.</p>
<p>Additionally, if there are no more free identifiers within the range specified
when <em>map</em> was created, then it will return <a href="api//api/errors.html#NNG_ENOSPC"><code>NNG_ENOSPC</code></a>.</p>
<p>Otherwise it returns zero, indicating success.</p>
<h2 id="remove-an-id"><a class="header" href="#remove-an-id">Remove an ID</a></h2>
<pre><code class="language-c">int nng_id_remove(nng_id_map *map, uint64_t id);
</code></pre>
<p>The <a name="a007"></a><code>nng_id_remove</code> removes the entry at index <em>id</em> from <em>map</em>.</p>
<p>If no such entry exist, it will return <a href="api//api/errors.html#NNG_ENOENT"><code>NNG_ENOENT</code></a>. Otherwise it returns zero.</p>
<h2 id="iterating-ids"><a class="header" href="#iterating-ids">Iterating IDs</a></h2>
<pre><code class="language-c">bool nng_id_visit(nng_id_map *map, uint64_t *id_p, void **value_p, uint32_t *cursor);
</code></pre>
<p>The <a name="a008"></a><code>nng_id_visit</code> function is used to iterate over all items in the table.
The caller starts the iteration by setting the <em>cursor</em> to 0 before calling it.
For each call, the associated key and value of the next item will be returned in <em>id_p</em>,
and <em>value_p</em> and the <em>cursor</em> will be updated.
When all items have been iterated, the function returns <code>false</code>.
The order of items returned is not guaranteed to be sequential.
The caller must not attempt to derive any value of the <em>cursor</em> as it refers to internal table indices.</p>
<p>Entries may be safely removed from <em>map</em> while iterating.</p>
<p>However, if new entries are added to the table while iterating, the result of
iteration is undefined; entries may be repeated or omitted during such an iteration.</p>
<p>The caller must not attempt to derive any value of the <em>cursor</em> as it refers to internal
table indices.</p>
<!-- Symbol cross reference -->
<!-- Macros -->
<!-- Protocols -->
<!-- Transports -->
<!-- Concept index -->
<p><hr/>
<p><a name="footnote-1"><a href="api/id_map.html#to-footnote-1">1</a></a>: The ID map is capable of storing at most 2<sup>32</sup> identifiers, even though the identifers may
themselves be much larger than this.</p>
<p><a name="footnote-2"><a href="api/id_map.html#to-footnote-2">2</a></a>: The concern about possibly reusing a
recently released identifier comes into consideration after the range has wrapped.
Given a sufficiently large range, this is unlikely to be a concern.</p>
<div style="break-before: page; page-break-before: always;"></div><style>
.mdbook-alerts {
padding: 8px 16px;
margin-bottom: 16px;
border-left: 0.25em solid var(--mdbook-alerts-color);
}
.mdbook-alerts > *:first-child {
margin-top: 0;
}
.mdbook-alerts > *:last-child {
margin-bottom: 0;
}
.mdbook-alerts-title {
display: flex;
font-weight: 600;
align-items: center;
line-height: 1;
color: var(--mdbook-alerts-color);
text-transform: capitalize;
}
.mdbook-alerts-icon {
display: inline-block;
width: 1em;
height: 1em;
margin-right: 0.2em;
background-color: currentColor;
-webkit-mask: no-repeat center / 100%;
mask: no-repeat center / 100%;
-webkit-mask-image: var(--mdbook-alerts-icon);
mask-image: var(--mdbook-alerts-icon);
}
.mdbook-alerts-note {
--mdbook-alerts-color: rgb(9, 105, 218);
/* https://icon-sets.iconify.design/material-symbols/info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16v-4q0-.425-.288-.712T12 11q-.425 0-.712.288T11 12v4q0 .425.288.713T12 17m0-8q.425 0 .713-.288T13 8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8q0 .425.288.713T12 9m0 13q-2.075 0-3.9-.788t-3.175-2.137q-1.35-1.35-2.137-3.175T2 12q0-2.075.788-3.9t2.137-3.175q1.35-1.35 3.175-2.137T12 2q2.075 0 3.9.788t3.175 2.137q1.35 1.35 2.138 3.175T22 12q0 2.075-.788 3.9t-2.137 3.175q-1.35 1.35-3.175 2.138T12 22m0-2q3.35 0 5.675-2.325T20 12q0-3.35-2.325-5.675T12 4Q8.65 4 6.325 6.325T4 12q0 3.35 2.325 5.675T12 20m0-8"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-tip {
--mdbook-alerts-color: rgb(26, 127, 55);
/* https://icon-sets.iconify.design/material-symbols/lightbulb-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 22q-.825 0-1.412-.587T10 20h4q0 .825-.587 1.413T12 22m-3-3q-.425 0-.712-.288T8 18q0-.425.288-.712T9 17h6q.425 0 .713.288T16 18q0 .425-.288.713T15 19zm-.75-3q-1.725-1.025-2.738-2.75T4.5 9.5q0-3.125 2.188-5.312T12 2q3.125 0 5.313 2.188T19.5 9.5q0 2.025-1.012 3.75T15.75 16zm.6-2h6.3q1.125-.8 1.738-1.975T17.5 9.5q0-2.3-1.6-3.9T12 4Q9.7 4 8.1 5.6T6.5 9.5q0 1.35.613 2.525T8.85 14M12 14"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-important {
--mdbook-alerts-color: rgb(130, 80, 223);
/* https://icon-sets.iconify.design/material-symbols/chat-info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 7q.425 0 .713-.288T13 6q0-.425-.288-.712T12 5q-.425 0-.712.288T11 6q0 .425.288.713T12 7m0 8q.425 0 .713-.288T13 14v-4q0-.425-.288-.712T12 9q-.425 0-.712.288T11 10v4q0 .425.288.713T12 15m-6 3l-2.3 2.3q-.475.475-1.088.213T2 19.575V4q0-.825.588-1.412T4 2h16q.825 0 1.413.588T22 4v12q0 .825-.587 1.413T20 18zm-.85-2H20V4H4v13.125zM4 16V4z"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-warning {
--mdbook-alerts-color: rgb(154, 103, 0);
/* https://icon-sets.iconify.design/material-symbols/warning-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M2.725 21q-.275 0-.5-.137t-.35-.363q-.125-.225-.137-.488t.137-.512l9.25-16q.15-.25.388-.375T12 3q.25 0 .488.125t.387.375l9.25 16q.15.25.138.513t-.138.487q-.125.225-.35.363t-.5.137zm1.725-2h15.1L12 6zM12 18q.425 0 .713-.288T13 17q0-.425-.288-.712T12 16q-.425 0-.712.288T11 17q0 .425.288.713T12 18m0-3q.425 0 .713-.288T13 14v-3q0-.425-.288-.712T12 10q-.425 0-.712.288T11 11v3q0 .425.288.713T12 15m0-2.5"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-caution {
--mdbook-alerts-color: rgb(207, 34, 46);
/* https://icon-sets.iconify.design/material-symbols/brightness-alert-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16q0-.425-.288-.712T12 15q-.425 0-.712.288T11 16q0 .425.288.713T12 17m0-4q.425 0 .713-.288T13 12V8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8v4q0 .425.288.713T12 13m-3.35 7H6q-.825 0-1.412-.587T4 18v-2.65L2.075 13.4q-.275-.3-.425-.662T1.5 12q0-.375.15-.737t.425-.663L4 8.65V6q0-.825.588-1.412T6 4h2.65l1.95-1.925q.3-.275.663-.425T12 1.5q.375 0 .738.15t.662.425L15.35 4H18q.825 0 1.413.588T20 6v2.65l1.925 1.95q.275.3.425.663t.15.737q0 .375-.15.738t-.425.662L20 15.35V18q0 .825-.587 1.413T18 20h-2.65l-1.95 1.925q-.3.275-.662.425T12 22.5q-.375 0-.737-.15t-.663-.425zm.85-2l2.5 2.5l2.5-2.5H18v-3.5l2.5-2.5L18 9.5V6h-3.5L12 3.5L9.5 6H6v3.5L3.5 12L6 14.5V18zm2.5-6"%2F%3E%3C%2Fsvg%3E');
}
</style>
<h1 id="command-options"><a class="header" href="#command-options">Command Options</a></h1>
<p>Some <em>NNG</em> utilities need to parse command line options,
and the supplementary function here allows applications that
need the same support to benefit from this.</p>
<p>To make use of this, the supplemental header <code><nng/supplemental/util/options.h></code>
must be included.</p>
<h2 id="parse-command-line-options"><a class="header" href="#parse-command-line-options">Parse Command Line Options</a></h2>
<pre><code class="language-c">typedef struct nng_optspec {
const char *o_name; // Long style name (may be NULL for short only)
int o_short; // Short option (no clustering!)
int o_val; // Value stored on a good parse (>0)
bool o_arg; // Option takes an argument if true
} nng_optspec;
int nng_opts_parse(int argc, char *const *argv,
const nng_optspec *spec, int *val, char **arg, int *idx);
</code></pre>
<p>The <a name="a001"></a><code>nng_opts_parse</code> function is a intended to facilitate parsing
<a name="a002"></a>command-line arguments.
This function exists largely to stand in for <a name="a003"></a><code>getopt</code> from POSIX systems,
but it is available everywhere that <em>NNG</em> is, and it includes
some capabilities missing from <code>getopt</code>.</p>
<p>The function parses arguments from
<code>main</code><sup><a name="to-footnote-1"><a href="api/cmd_opts.html#footnote-1">1</a></a></sup>
(using <em>argc</em> and <em>argv</em>),
starting at the index referenced by <em>idx</em>.
(New invocations typically set the value pointed to by <em>idx</em> to 1.)</p>
<p>Options are parsed as specified by <em>spec</em> (see <a href="api/cmd_opts.html#option-specification">Option Specification</a>.)
The value of the parsed option will be stored at the address indicated by
<em>val</em>, and the value of <em>idx</em> will be incremented to reflect the next
option to parse.</p>
<div class="mdbook-alerts mdbook-alerts-tip">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
tip
</p>
<p>For using this to parse command-line like strings that do not include
the command name itself, set the value referenced by <em>idx</em> to zero instead of one.</p>
</div>
<p>If the option had an argument, a pointer to that is returned at the address
referenced by <em>arg</em>.</p>
<p>This function should be called repeatedly, until it returns either -1
(indicating the end of options is reached) or a non-zero error code is
returned.</p>
<p>This function may return the following errors:</p>
<ul>
<li><a href="api//api/errors.html#NNG_EAMBIGUOUS"><code>NNG_EAMBIGUOUS</code></a>: Parsed option matches more than one specification.</li>
<li><a href="api//api/errors.html#NNG_ENOARG"><code>NNG_ENOARG</code></a>: Option requires an argument, but one is not present.</li>
<li><a href="api//api/errors.html#NNG_EINVAL"><code>NNG_EINVAL</code></a>: An invalid (unknown) argument is present.</li>
</ul>
<h3 id="option-specification"><a class="header" href="#option-specification">Option Specification</a></h3>
<p>The calling program must first create an array of <a name="a004"></a><code>nng_optspec</code> structures
describing the options to be supported.
This structure has the following members:</p>
<ul>
<li>
<p><code>o_name</code>:</p>
<p>The long style name for the option, such as “verbose”.
This will be parsed as a <a href="api/cmd_opts.html#long-options">long option</a> on the command line when it is prefixed with two dashes.
It may be <code>NULL</code> if only a <a href="api/cmd_opts.html#short-options">short option</a> is to be supported.</p>
</li>
<li>
<p><code>o_short</code>:</p>
<p>This is a single letter (at present only ASCII letters are supported).
These options appear as just a single letter, and are prefixed with a single dash on the command line.
The use of a slash in lieu of the dash is <em>not</em> supported, in order to avoid confusion with path name arguments.
This value may be set to 0 if no <a href="api/cmd_opts.html#short-options">short option</a> is needed.</p>
</li>
<li>
<p><code>o_val</code>:</p>
<p>This is a numeric value that is unique to this option.
This value is assigned by the application program, and must be non-zero for a valid option.
If this is zero, then it indicates the end of the specifications, and the
rest of this structure is ignored.
The value will be returned to the caller in <em>val</em> by <code>nng_opts_parse</code> when
this option is parsed from the command line.</p>
</li>
<li>
<p><code>o_arg</code>:</p>
<p>This value should be set to <code>true</code> if the option should take an argument.</p>
</li>
</ul>
<h3 id="long-options"><a class="header" href="#long-options">Long Options</a></h3>
<p>Long options are parsed from the <em>argv</em> array, and are indicated when
the element being scanned starts with two dashes.
For example, the “verbose” option would be specified as <code>--verbose</code> on
the command line.
If a long option takes an argument, it can either immediately follow
the option as the next element in <em>argv</em>, or it can be appended to
the option, separated from the option by an equals sign (<code>=</code>) or a
colon (<code>:</code>).</p>
<h3 id="short-options"><a class="header" href="#short-options">Short Options</a></h3>
<p>Short options appear by themselves in an <em>argv</em> element, prefixed by a dash (<code>-</code>).
If the short option takes an argument, it can either be appended in the
same element of <em>argv</em>, or may appear in the next <em>argv</em> element.</p>
<div class="mdbook-alerts mdbook-alerts-note">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
note
</p>
<p>Option clustering, where multiple options can be crammed together in
a single <em>argv</em> element, is not supported by this function (yet).</p>
</div>
<h3 id="prefix-matching"><a class="header" href="#prefix-matching">Prefix Matching</a></h3>
<p>When using long options, the parser will match if it is equal to a prefix
of the <code>o_name</code> member of a option specification, provided that it do so
unambiguously (meaning it must not match any other option specification.)</p>
<h2 id="example"><a class="header" href="#example">Example</a></h2>
<p>The following program fragment demonstrates this function.</p>
<pre><code class="language-c"> enum { OPT_LOGFILE, OPT_VERBOSE };
char *logfile; // options to be set
bool verbose;
static nng_optspec specs[] = {
{
.o_name = "logfile",
.o_short = 'D',
.o_val = OPT_LOGFILE,
.o_arg = true,
}, {
.o_name = "verbose",
.o_short = 'V',
.o_val = OPT_VERBOSE,
.o_arg = false,
}, {
.o_val = 0; // Terminate array
}
};
for (int idx = 1;;) {
int rv, opt;
char *arg;
rv = nng_opts_parse(argc, argv, specs, &opt, &arg, &idx);
if (rv != 0) {
break;
}
switch (opt) {
case OPT_LOGFILE:
logfile = arg;
break;
case OPT_VERBOSE:
verbose = true;
break;
}
}
if (rv != -1) {
printf("Options error: %s\n", nng_strerror(rv));
exit(1);
}
</code></pre>
<!-- Symbol cross reference -->
<!-- Macros -->
<!-- Protocols -->
<!-- Transports -->
<!-- Concept index -->
<p><hr/>
<p><a name="footnote-1"><a href="api/cmd_opts.html#to-footnote-1">1</a></a>: Parsing argument strings from other sources can be done as well,
although usually then <em>idx</em> will be initialized to zero.</p>
<div style="break-before: page; page-break-before: always;"></div><style>
.mdbook-alerts {
padding: 8px 16px;
margin-bottom: 16px;
border-left: 0.25em solid var(--mdbook-alerts-color);
}
.mdbook-alerts > *:first-child {
margin-top: 0;
}
.mdbook-alerts > *:last-child {
margin-bottom: 0;
}
.mdbook-alerts-title {
display: flex;
font-weight: 600;
align-items: center;
line-height: 1;
color: var(--mdbook-alerts-color);
text-transform: capitalize;
}
.mdbook-alerts-icon {
display: inline-block;
width: 1em;
height: 1em;
margin-right: 0.2em;
background-color: currentColor;
-webkit-mask: no-repeat center / 100%;
mask: no-repeat center / 100%;
-webkit-mask-image: var(--mdbook-alerts-icon);
mask-image: var(--mdbook-alerts-icon);
}
.mdbook-alerts-note {
--mdbook-alerts-color: rgb(9, 105, 218);
/* https://icon-sets.iconify.design/material-symbols/info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16v-4q0-.425-.288-.712T12 11q-.425 0-.712.288T11 12v4q0 .425.288.713T12 17m0-8q.425 0 .713-.288T13 8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8q0 .425.288.713T12 9m0 13q-2.075 0-3.9-.788t-3.175-2.137q-1.35-1.35-2.137-3.175T2 12q0-2.075.788-3.9t2.137-3.175q1.35-1.35 3.175-2.137T12 2q2.075 0 3.9.788t3.175 2.137q1.35 1.35 2.138 3.175T22 12q0 2.075-.788 3.9t-2.137 3.175q-1.35 1.35-3.175 2.138T12 22m0-2q3.35 0 5.675-2.325T20 12q0-3.35-2.325-5.675T12 4Q8.65 4 6.325 6.325T4 12q0 3.35 2.325 5.675T12 20m0-8"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-tip {
--mdbook-alerts-color: rgb(26, 127, 55);
/* https://icon-sets.iconify.design/material-symbols/lightbulb-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 22q-.825 0-1.412-.587T10 20h4q0 .825-.587 1.413T12 22m-3-3q-.425 0-.712-.288T8 18q0-.425.288-.712T9 17h6q.425 0 .713.288T16 18q0 .425-.288.713T15 19zm-.75-3q-1.725-1.025-2.738-2.75T4.5 9.5q0-3.125 2.188-5.312T12 2q3.125 0 5.313 2.188T19.5 9.5q0 2.025-1.012 3.75T15.75 16zm.6-2h6.3q1.125-.8 1.738-1.975T17.5 9.5q0-2.3-1.6-3.9T12 4Q9.7 4 8.1 5.6T6.5 9.5q0 1.35.613 2.525T8.85 14M12 14"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-important {
--mdbook-alerts-color: rgb(130, 80, 223);
/* https://icon-sets.iconify.design/material-symbols/chat-info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 7q.425 0 .713-.288T13 6q0-.425-.288-.712T12 5q-.425 0-.712.288T11 6q0 .425.288.713T12 7m0 8q.425 0 .713-.288T13 14v-4q0-.425-.288-.712T12 9q-.425 0-.712.288T11 10v4q0 .425.288.713T12 15m-6 3l-2.3 2.3q-.475.475-1.088.213T2 19.575V4q0-.825.588-1.412T4 2h16q.825 0 1.413.588T22 4v12q0 .825-.587 1.413T20 18zm-.85-2H20V4H4v13.125zM4 16V4z"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-warning {
--mdbook-alerts-color: rgb(154, 103, 0);
/* https://icon-sets.iconify.design/material-symbols/warning-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M2.725 21q-.275 0-.5-.137t-.35-.363q-.125-.225-.137-.488t.137-.512l9.25-16q.15-.25.388-.375T12 3q.25 0 .488.125t.387.375l9.25 16q.15.25.138.513t-.138.487q-.125.225-.35.363t-.5.137zm1.725-2h15.1L12 6zM12 18q.425 0 .713-.288T13 17q0-.425-.288-.712T12 16q-.425 0-.712.288T11 17q0 .425.288.713T12 18m0-3q.425 0 .713-.288T13 14v-3q0-.425-.288-.712T12 10q-.425 0-.712.288T11 11v3q0 .425.288.713T12 15m0-2.5"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-caution {
--mdbook-alerts-color: rgb(207, 34, 46);
/* https://icon-sets.iconify.design/material-symbols/brightness-alert-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16q0-.425-.288-.712T12 15q-.425 0-.712.288T11 16q0 .425.288.713T12 17m0-4q.425 0 .713-.288T13 12V8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8v4q0 .425.288.713T12 13m-3.35 7H6q-.825 0-1.412-.587T4 18v-2.65L2.075 13.4q-.275-.3-.425-.662T1.5 12q0-.375.15-.737t.425-.663L4 8.65V6q0-.825.588-1.412T6 4h2.65l1.95-1.925q.3-.275.663-.425T12 1.5q.375 0 .738.15t.662.425L15.35 4H18q.825 0 1.413.588T20 6v2.65l1.925 1.95q.275.3.425.663t.15.737q0 .375-.15.738t-.425.662L20 15.35V18q0 .825-.587 1.413T18 20h-2.65l-1.95 1.925q-.3.275-.662.425T12 22.5q-.375 0-.737-.15t-.663-.425zm.85-2l2.5 2.5l2.5-2.5H18v-3.5l2.5-2.5L18 9.5V6h-3.5L12 3.5L9.5 6H6v3.5L3.5 12L6 14.5V18zm2.5-6"%2F%3E%3C%2Fsvg%3E');
}
</style>
<h1 id="protocols"><a class="header" href="#protocols">Protocols</a></h1>
<p><a name="a001"></a>
The Scalability Protocols are a principally a collection of common networking
patterns found in applications.</p>
<p>The following patterns are included:</p>
<h2 id="request---reply"><a class="header" href="#request---reply">Request - Reply</a></h2>
<p>The <a name="a002"></a>request/reply pattern is made up of the <a href="proto/req.html"><em>REQ</em></a> and <a href="proto/rep.html"><em>REP</em></a> protocols.
This most often used when implementing RPC-like services, where
a given request is matched by a single reply.</p>
<h2 id="pipeline"><a class="header" href="#pipeline">Pipeline</a></h2>
<p>The <a name="a003"></a>pipeline pattern is made up of the <a href="proto/push.html"><em>PUSH</em></a> and <a href="proto/pull.html"><em>PULL</em></a>
protocols.</p>
<p>In this pattern communication is <a name="a004"></a>half-duplex, in that one side sends
data and another side receives.</p>
<p>This pattern is also characterized by its ability to solve distribution
problems, and the fact that it has <a name="a005"></a>back-pressure, providing a measure
of <a name="a006"></a>flow control to data production and consumption.</p>
<h2 id="publish---subscribe"><a class="header" href="#publish---subscribe">Publish - Subscribe</a></h2>
<h2 id="bus"><a class="header" href="#bus">Bus</a></h2>
<h2 id="pair"><a class="header" href="#pair">Pair</a></h2>
<div style="break-before: page; page-break-before: always;"></div><style>
.mdbook-alerts {
padding: 8px 16px;
margin-bottom: 16px;
border-left: 0.25em solid var(--mdbook-alerts-color);
}
.mdbook-alerts > *:first-child {
margin-top: 0;
}
.mdbook-alerts > *:last-child {
margin-bottom: 0;
}
.mdbook-alerts-title {
display: flex;
font-weight: 600;
align-items: center;
line-height: 1;
color: var(--mdbook-alerts-color);
text-transform: capitalize;
}
.mdbook-alerts-icon {
display: inline-block;
width: 1em;
height: 1em;
margin-right: 0.2em;
background-color: currentColor;
-webkit-mask: no-repeat center / 100%;
mask: no-repeat center / 100%;
-webkit-mask-image: var(--mdbook-alerts-icon);
mask-image: var(--mdbook-alerts-icon);
}
.mdbook-alerts-note {
--mdbook-alerts-color: rgb(9, 105, 218);
/* https://icon-sets.iconify.design/material-symbols/info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16v-4q0-.425-.288-.712T12 11q-.425 0-.712.288T11 12v4q0 .425.288.713T12 17m0-8q.425 0 .713-.288T13 8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8q0 .425.288.713T12 9m0 13q-2.075 0-3.9-.788t-3.175-2.137q-1.35-1.35-2.137-3.175T2 12q0-2.075.788-3.9t2.137-3.175q1.35-1.35 3.175-2.137T12 2q2.075 0 3.9.788t3.175 2.137q1.35 1.35 2.138 3.175T22 12q0 2.075-.788 3.9t-2.137 3.175q-1.35 1.35-3.175 2.138T12 22m0-2q3.35 0 5.675-2.325T20 12q0-3.35-2.325-5.675T12 4Q8.65 4 6.325 6.325T4 12q0 3.35 2.325 5.675T12 20m0-8"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-tip {
--mdbook-alerts-color: rgb(26, 127, 55);
/* https://icon-sets.iconify.design/material-symbols/lightbulb-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 22q-.825 0-1.412-.587T10 20h4q0 .825-.587 1.413T12 22m-3-3q-.425 0-.712-.288T8 18q0-.425.288-.712T9 17h6q.425 0 .713.288T16 18q0 .425-.288.713T15 19zm-.75-3q-1.725-1.025-2.738-2.75T4.5 9.5q0-3.125 2.188-5.312T12 2q3.125 0 5.313 2.188T19.5 9.5q0 2.025-1.012 3.75T15.75 16zm.6-2h6.3q1.125-.8 1.738-1.975T17.5 9.5q0-2.3-1.6-3.9T12 4Q9.7 4 8.1 5.6T6.5 9.5q0 1.35.613 2.525T8.85 14M12 14"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-important {
--mdbook-alerts-color: rgb(130, 80, 223);
/* https://icon-sets.iconify.design/material-symbols/chat-info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 7q.425 0 .713-.288T13 6q0-.425-.288-.712T12 5q-.425 0-.712.288T11 6q0 .425.288.713T12 7m0 8q.425 0 .713-.288T13 14v-4q0-.425-.288-.712T12 9q-.425 0-.712.288T11 10v4q0 .425.288.713T12 15m-6 3l-2.3 2.3q-.475.475-1.088.213T2 19.575V4q0-.825.588-1.412T4 2h16q.825 0 1.413.588T22 4v12q0 .825-.587 1.413T20 18zm-.85-2H20V4H4v13.125zM4 16V4z"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-warning {
--mdbook-alerts-color: rgb(154, 103, 0);
/* https://icon-sets.iconify.design/material-symbols/warning-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M2.725 21q-.275 0-.5-.137t-.35-.363q-.125-.225-.137-.488t.137-.512l9.25-16q.15-.25.388-.375T12 3q.25 0 .488.125t.387.375l9.25 16q.15.25.138.513t-.138.487q-.125.225-.35.363t-.5.137zm1.725-2h15.1L12 6zM12 18q.425 0 .713-.288T13 17q0-.425-.288-.712T12 16q-.425 0-.712.288T11 17q0 .425.288.713T12 18m0-3q.425 0 .713-.288T13 14v-3q0-.425-.288-.712T12 10q-.425 0-.712.288T11 11v3q0 .425.288.713T12 15m0-2.5"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-caution {
--mdbook-alerts-color: rgb(207, 34, 46);
/* https://icon-sets.iconify.design/material-symbols/brightness-alert-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16q0-.425-.288-.712T12 15q-.425 0-.712.288T11 16q0 .425.288.713T12 17m0-4q.425 0 .713-.288T13 12V8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8v4q0 .425.288.713T12 13m-3.35 7H6q-.825 0-1.412-.587T4 18v-2.65L2.075 13.4q-.275-.3-.425-.662T1.5 12q0-.375.15-.737t.425-.663L4 8.65V6q0-.825.588-1.412T6 4h2.65l1.95-1.925q.3-.275.663-.425T12 1.5q.375 0 .738.15t.662.425L15.35 4H18q.825 0 1.413.588T20 6v2.65l1.925 1.95q.275.3.425.663t.15.737q0 .375-.15.738t-.425.662L20 15.35V18q0 .825-.587 1.413T18 20h-2.65l-1.95 1.925q-.3.275-.662.425T12 22.5q-.375 0-.737-.15t-.663-.425zm.85-2l2.5 2.5l2.5-2.5H18v-3.5l2.5-2.5L18 9.5V6h-3.5L12 3.5L9.5 6H6v3.5L3.5 12L6 14.5V18zm2.5-6"%2F%3E%3C%2Fsvg%3E');
}
</style>
<h1 id="bus-protocol"><a class="header" href="#bus-protocol">BUS Protocol</a></h1>
<p>The <a name="a001"></a><em>BUS</em> protocol<a name="a002"></a> provides for building mesh networks where
every peer is connected to every other peer.
In this protocol, each message sent by a node is sent to every one of
its directly connected peers.</p>
<div class="mdbook-alerts mdbook-alerts-tip">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
tip
</p>
<p>Messages are only sent to directly connected peers.
This means that in the event that a peer is connected indirectly, it will not
receive messages.
When using this protocol to build mesh networks, it
is therefore important that a <em>fully-connected</em> mesh network be constructed.</p>
</div>
<p>All message delivery in this pattern is <a name="a003"></a>best-effort, which means that
peers may not receive messages.
Furthermore, delivery may occur to some,
all, or none of the directly connected peers.
(Messages are not delivered when peer nodes are unable to receive.)
Hence, send operations will never block; instead if the
message cannot be delivered for any reason it is discarded.</p>
<div class="mdbook-alerts mdbook-alerts-tip">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
tip
</p>
<p>In order to minimize the likelihood of message loss, this protocol
should not be used for high throughput communications.
Furthermore, the more traffic <em>in aggregate</em> that occurs across the topology,
the more likely that message loss is to occur.</p>
</div>
<h2 id="socket-operations"><a class="header" href="#socket-operations">Socket Operations</a></h2>
<p>The <a href="proto/TODO.html"><code>nng_bus0_open</code></a> functions create a bus socket.
This socket may be used to send and receive messages.
Sending messages will attempt to deliver to each directly connected peer.</p>
<h2 id="protocol-versions"><a class="header" href="#protocol-versions">Protocol Versions</a></h2>
<p>Only version 0 of this protocol is supported.
(At the time of writing, no other versions of this protocol have been defined.)</p>
<h2 id="protocol-options"><a class="header" href="#protocol-options">Protocol Options</a></h2>
<p>The <em>BUS</em> protocol has no protocol-specific options.</p>
<h2 id="protocol-headers"><a class="header" href="#protocol-headers">Protocol Headers</a></h2>
<p>When using a <em>BUS</em> socket in <a href="proto/TODO.html">raw mode</a>, received messages will
contain the incoming <a href="proto/TODO.html">pipe</a> ID as the sole element in the header.
If a message containing such a header is sent using a raw <em>BUS</em> socket, then,
the message will be delivered to all connected pipes <em>except</em> the one
identified in the header.
This behavior is intended for use with <a href="proto/TODO.html">device</a>
configurations consisting of just a single socket.
Such configurations are useful in the creation of rebroadcasters, and this
capability prevents a message from being routed back to its source.
If no header is present, then a message is sent to all connected pipes.</p>
<p>When using normal (cooked mode) <em>BUS</em> sockets, no message headers are present.</p>
<div style="break-before: page; page-break-before: always;"></div><style>
.mdbook-alerts {
padding: 8px 16px;
margin-bottom: 16px;
border-left: 0.25em solid var(--mdbook-alerts-color);
}
.mdbook-alerts > *:first-child {
margin-top: 0;
}
.mdbook-alerts > *:last-child {
margin-bottom: 0;
}
.mdbook-alerts-title {
display: flex;
font-weight: 600;
align-items: center;
line-height: 1;
color: var(--mdbook-alerts-color);
text-transform: capitalize;
}
.mdbook-alerts-icon {
display: inline-block;
width: 1em;
height: 1em;
margin-right: 0.2em;
background-color: currentColor;
-webkit-mask: no-repeat center / 100%;
mask: no-repeat center / 100%;
-webkit-mask-image: var(--mdbook-alerts-icon);
mask-image: var(--mdbook-alerts-icon);
}
.mdbook-alerts-note {
--mdbook-alerts-color: rgb(9, 105, 218);
/* https://icon-sets.iconify.design/material-symbols/info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16v-4q0-.425-.288-.712T12 11q-.425 0-.712.288T11 12v4q0 .425.288.713T12 17m0-8q.425 0 .713-.288T13 8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8q0 .425.288.713T12 9m0 13q-2.075 0-3.9-.788t-3.175-2.137q-1.35-1.35-2.137-3.175T2 12q0-2.075.788-3.9t2.137-3.175q1.35-1.35 3.175-2.137T12 2q2.075 0 3.9.788t3.175 2.137q1.35 1.35 2.138 3.175T22 12q0 2.075-.788 3.9t-2.137 3.175q-1.35 1.35-3.175 2.138T12 22m0-2q3.35 0 5.675-2.325T20 12q0-3.35-2.325-5.675T12 4Q8.65 4 6.325 6.325T4 12q0 3.35 2.325 5.675T12 20m0-8"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-tip {
--mdbook-alerts-color: rgb(26, 127, 55);
/* https://icon-sets.iconify.design/material-symbols/lightbulb-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 22q-.825 0-1.412-.587T10 20h4q0 .825-.587 1.413T12 22m-3-3q-.425 0-.712-.288T8 18q0-.425.288-.712T9 17h6q.425 0 .713.288T16 18q0 .425-.288.713T15 19zm-.75-3q-1.725-1.025-2.738-2.75T4.5 9.5q0-3.125 2.188-5.312T12 2q3.125 0 5.313 2.188T19.5 9.5q0 2.025-1.012 3.75T15.75 16zm.6-2h6.3q1.125-.8 1.738-1.975T17.5 9.5q0-2.3-1.6-3.9T12 4Q9.7 4 8.1 5.6T6.5 9.5q0 1.35.613 2.525T8.85 14M12 14"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-important {
--mdbook-alerts-color: rgb(130, 80, 223);
/* https://icon-sets.iconify.design/material-symbols/chat-info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 7q.425 0 .713-.288T13 6q0-.425-.288-.712T12 5q-.425 0-.712.288T11 6q0 .425.288.713T12 7m0 8q.425 0 .713-.288T13 14v-4q0-.425-.288-.712T12 9q-.425 0-.712.288T11 10v4q0 .425.288.713T12 15m-6 3l-2.3 2.3q-.475.475-1.088.213T2 19.575V4q0-.825.588-1.412T4 2h16q.825 0 1.413.588T22 4v12q0 .825-.587 1.413T20 18zm-.85-2H20V4H4v13.125zM4 16V4z"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-warning {
--mdbook-alerts-color: rgb(154, 103, 0);
/* https://icon-sets.iconify.design/material-symbols/warning-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M2.725 21q-.275 0-.5-.137t-.35-.363q-.125-.225-.137-.488t.137-.512l9.25-16q.15-.25.388-.375T12 3q.25 0 .488.125t.387.375l9.25 16q.15.25.138.513t-.138.487q-.125.225-.35.363t-.5.137zm1.725-2h15.1L12 6zM12 18q.425 0 .713-.288T13 17q0-.425-.288-.712T12 16q-.425 0-.712.288T11 17q0 .425.288.713T12 18m0-3q.425 0 .713-.288T13 14v-3q0-.425-.288-.712T12 10q-.425 0-.712.288T11 11v3q0 .425.288.713T12 15m0-2.5"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-caution {
--mdbook-alerts-color: rgb(207, 34, 46);
/* https://icon-sets.iconify.design/material-symbols/brightness-alert-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16q0-.425-.288-.712T12 15q-.425 0-.712.288T11 16q0 .425.288.713T12 17m0-4q.425 0 .713-.288T13 12V8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8v4q0 .425.288.713T12 13m-3.35 7H6q-.825 0-1.412-.587T4 18v-2.65L2.075 13.4q-.275-.3-.425-.662T1.5 12q0-.375.15-.737t.425-.663L4 8.65V6q0-.825.588-1.412T6 4h2.65l1.95-1.925q.3-.275.663-.425T12 1.5q.375 0 .738.15t.662.425L15.35 4H18q.825 0 1.413.588T20 6v2.65l1.925 1.95q.275.3.425.663t.15.737q0 .375-.15.738t-.425.662L20 15.35V18q0 .825-.587 1.413T18 20h-2.65l-1.95 1.925q-.3.275-.662.425T12 22.5q-.375 0-.737-.15t-.663-.425zm.85-2l2.5 2.5l2.5-2.5H18v-3.5l2.5-2.5L18 9.5V6h-3.5L12 3.5L9.5 6H6v3.5L3.5 12L6 14.5V18zm2.5-6"%2F%3E%3C%2Fsvg%3E');
}
</style>
<h1 id="pair-protocol"><a class="header" href="#pair-protocol">PAIR protocol</a></h1>
<p>The <a name="a001"></a><em>PAIR</em> protocol<a name="a002"></a> implements a peer-to-peer pattern, where
relationships between peers are one-to-one.</p>
<h3 id="socket-operations-1"><a class="header" href="#socket-operations-1">Socket Operations</a></h3>
<p>The <a href="proto/TODO.html"><code>nng_pair_open</code></a> functions create a <em>PAIR</em> socket.</p>
<p>Normally, this pattern will block when attempting to send a message if
no peer is able to receive the message.</p>
<div class="mdbook-alerts mdbook-alerts-note">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
note
</p>
<p>Even though this mode may appear to be reliable, because back-pressure
prevents discarding messages most of the time, there are topologies involving
where messages may be discarded.
Applications that require reliable delivery semantics should consider using
<a href="proto/./req.html"><em>REQ</em></a> sockets, or implement their own acknowledgment layer on top of <em>PAIR</em> sockets.</p>
</div>
<h3 id="protocol-versions-1"><a class="header" href="#protocol-versions-1">Protocol Versions</a></h3>
<p>Version 0 is the legacy version of this protocol.
It lacks any header
information, and is suitable when building simple one-to-one topologies.</p>
<div class="mdbook-alerts mdbook-alerts-tip">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
tip
</p>
<p>Use version 0 if you need to communicate with other implementations,
including the legacy <a href="proto/TODO.html">libnanomsg</a> library or
<a href="proto/TODO.html">mangos</a>.</p>
</div>
<p>Version 1 of the protocol offers improved protection against loops when
used with <a href="proto/TODO.html">devices</a>.</p>
<h3 id="polyamorous-mode"><a class="header" href="#polyamorous-mode">Polyamorous Mode</a></h3>
<div class="mdbook-alerts mdbook-alerts-note">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
note
</p>
<p>Polyamorous mode is deprecated, and support for it will likely
be removed in a future release, when a suitable mesh protocol is
available.
In the meantime, applications are encouraged to look to other patterns.</p>
</div>
<p>Normally pair sockets are for one-to-one communication, and a given peer
will reject new connections if it already has an active connection to another
peer.</p>
<p><em>Polyamorous</em><a name="a003"></a> changes this, to allow a socket to communicate with
multiple directly-connected peers.
This mode is enabled by opening a socket using <a href="proto/TODO.html"><code>nng_pair1_open_poly</code></a>.</p>
<div class="mdbook-alerts mdbook-alerts-tip">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
tip
</p>
<p>Polyamorous mode is only available when using pair version 1.</p>
</div>
<p>In polyamorous mode a socket can support many one-to-one connections.
In this mode, the application must
choose the remote peer to receive an outgoing message by setting the
<a href="proto/TODO.html"><code>nng_pipe</code></a> to use for the outgoing message using
<a href="proto/../api/msg/nng_msg_pipe.html"><code>nng_msg_set_pipe</code></a>.</p>
<p>If no remote peer is specified by the sender, then the protocol will select
any available connected peer.</p>
<p>Most often the value of the outgoing pipe will be obtained from an incoming
message using <a href="proto/../api/msg/nng_msg_pipe.html"><code>nng_msg_get_pipe</code></a>,
such as when replying to an incoming message.</p>
<div class="mdbook-alerts mdbook-alerts-note">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
note
</p>
<p>Directed send <em>only</em> works with directly connected peers.
It will not function across <a href="proto/TODO.html">device</a> proxies.</p>
</div>
<p>In order to prevent head-of-line blocking, if the peer on the given pipe
is not able to receive (or the pipe is no longer available, such as if the
peer has disconnected), then the message will be discarded with no notification
to the sender.</p>
<h3 id="protocol-options-1"><a class="header" href="#protocol-options-1">Protocol Options</a></h3>
<p>The following protocol-specific options are available.</p>
<ul>
<li>
<p><a href="proto/TODO.html"><code>NNG_OPT_MAXTTL</code></a>:
(<code>int</code>, version 1 only). Maximum time-to-live.</p>
</li>
<li>
<p><code>NNG_OPT_PAIR1_POLY</code>:
(<code>bool</code>, version 1 only) This option is no longer supported.
Formerly it was used to configure <em>polyamorous</em> mode, but that mode
is now established by using the <code>nng_pair1_open_poly</code> function.</p>
</li>
</ul>
<h3 id="protocol-headers-1"><a class="header" href="#protocol-headers-1">Protocol Headers</a></h3>
<p>Version 0 of the pair protocol has no protocol-specific headers.</p>
<p>Version 1 of the pair protocol uses a single 32-bit unsigned value. The
low-order (big-endian) byte of this value contains a “hop” count, and is
used in conjunction with the
<a href="proto/TODO.html"><code>NNG_OPT_MAXTTL</code></a> option to guard against
device forwarding loops.
This value is initialized to 1, and incremented each time the message is
received by a new node.</p>
<div style="break-before: page; page-break-before: always;"></div><style>
.mdbook-alerts {
padding: 8px 16px;
margin-bottom: 16px;
border-left: 0.25em solid var(--mdbook-alerts-color);
}
.mdbook-alerts > *:first-child {
margin-top: 0;
}
.mdbook-alerts > *:last-child {
margin-bottom: 0;
}
.mdbook-alerts-title {
display: flex;
font-weight: 600;
align-items: center;
line-height: 1;
color: var(--mdbook-alerts-color);
text-transform: capitalize;
}
.mdbook-alerts-icon {
display: inline-block;
width: 1em;
height: 1em;
margin-right: 0.2em;
background-color: currentColor;
-webkit-mask: no-repeat center / 100%;
mask: no-repeat center / 100%;
-webkit-mask-image: var(--mdbook-alerts-icon);
mask-image: var(--mdbook-alerts-icon);
}
.mdbook-alerts-note {
--mdbook-alerts-color: rgb(9, 105, 218);
/* https://icon-sets.iconify.design/material-symbols/info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16v-4q0-.425-.288-.712T12 11q-.425 0-.712.288T11 12v4q0 .425.288.713T12 17m0-8q.425 0 .713-.288T13 8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8q0 .425.288.713T12 9m0 13q-2.075 0-3.9-.788t-3.175-2.137q-1.35-1.35-2.137-3.175T2 12q0-2.075.788-3.9t2.137-3.175q1.35-1.35 3.175-2.137T12 2q2.075 0 3.9.788t3.175 2.137q1.35 1.35 2.138 3.175T22 12q0 2.075-.788 3.9t-2.137 3.175q-1.35 1.35-3.175 2.138T12 22m0-2q3.35 0 5.675-2.325T20 12q0-3.35-2.325-5.675T12 4Q8.65 4 6.325 6.325T4 12q0 3.35 2.325 5.675T12 20m0-8"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-tip {
--mdbook-alerts-color: rgb(26, 127, 55);
/* https://icon-sets.iconify.design/material-symbols/lightbulb-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 22q-.825 0-1.412-.587T10 20h4q0 .825-.587 1.413T12 22m-3-3q-.425 0-.712-.288T8 18q0-.425.288-.712T9 17h6q.425 0 .713.288T16 18q0 .425-.288.713T15 19zm-.75-3q-1.725-1.025-2.738-2.75T4.5 9.5q0-3.125 2.188-5.312T12 2q3.125 0 5.313 2.188T19.5 9.5q0 2.025-1.012 3.75T15.75 16zm.6-2h6.3q1.125-.8 1.738-1.975T17.5 9.5q0-2.3-1.6-3.9T12 4Q9.7 4 8.1 5.6T6.5 9.5q0 1.35.613 2.525T8.85 14M12 14"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-important {
--mdbook-alerts-color: rgb(130, 80, 223);
/* https://icon-sets.iconify.design/material-symbols/chat-info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 7q.425 0 .713-.288T13 6q0-.425-.288-.712T12 5q-.425 0-.712.288T11 6q0 .425.288.713T12 7m0 8q.425 0 .713-.288T13 14v-4q0-.425-.288-.712T12 9q-.425 0-.712.288T11 10v4q0 .425.288.713T12 15m-6 3l-2.3 2.3q-.475.475-1.088.213T2 19.575V4q0-.825.588-1.412T4 2h16q.825 0 1.413.588T22 4v12q0 .825-.587 1.413T20 18zm-.85-2H20V4H4v13.125zM4 16V4z"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-warning {
--mdbook-alerts-color: rgb(154, 103, 0);
/* https://icon-sets.iconify.design/material-symbols/warning-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M2.725 21q-.275 0-.5-.137t-.35-.363q-.125-.225-.137-.488t.137-.512l9.25-16q.15-.25.388-.375T12 3q.25 0 .488.125t.387.375l9.25 16q.15.25.138.513t-.138.487q-.125.225-.35.363t-.5.137zm1.725-2h15.1L12 6zM12 18q.425 0 .713-.288T13 17q0-.425-.288-.712T12 16q-.425 0-.712.288T11 17q0 .425.288.713T12 18m0-3q.425 0 .713-.288T13 14v-3q0-.425-.288-.712T12 10q-.425 0-.712.288T11 11v3q0 .425.288.713T12 15m0-2.5"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-caution {
--mdbook-alerts-color: rgb(207, 34, 46);
/* https://icon-sets.iconify.design/material-symbols/brightness-alert-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16q0-.425-.288-.712T12 15q-.425 0-.712.288T11 16q0 .425.288.713T12 17m0-4q.425 0 .713-.288T13 12V8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8v4q0 .425.288.713T12 13m-3.35 7H6q-.825 0-1.412-.587T4 18v-2.65L2.075 13.4q-.275-.3-.425-.662T1.5 12q0-.375.15-.737t.425-.663L4 8.65V6q0-.825.588-1.412T6 4h2.65l1.95-1.925q.3-.275.663-.425T12 1.5q.375 0 .738.15t.662.425L15.35 4H18q.825 0 1.413.588T20 6v2.65l1.925 1.95q.275.3.425.663t.15.737q0 .375-.15.738t-.425.662L20 15.35V18q0 .825-.587 1.413T18 20h-2.65l-1.95 1.925q-.3.275-.662.425T12 22.5q-.375 0-.737-.15t-.663-.425zm.85-2l2.5 2.5l2.5-2.5H18v-3.5l2.5-2.5L18 9.5V6h-3.5L12 3.5L9.5 6H6v3.5L3.5 12L6 14.5V18zm2.5-6"%2F%3E%3C%2Fsvg%3E');
}
</style>
<h1 id="pub-protocol"><a class="header" href="#pub-protocol">PUB Protocol</a></h1>
<p>The <a name="a001"></a><em>PUB</em> protocol<a name="a002"></a> is one half of a <a name="a003"></a>publisher/subscriber pattern.
In this pattern, a publisher sends data, which is broadcast to all
subscribers.
The subscribing applications only see the data to which
they have subscribed.</p>
<p>The <em>PUB</em> protocol is the publisher side, and the
<a href="proto/sub.html"><em>SUB</em></a> protocol is the subscriber side.</p>
<div class="mdbook-alerts mdbook-alerts-note">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
note
</p>
<p>In this implementation, the publisher delivers all messages to all
subscribers.
The subscribers maintain their own subscriptions, and filter them locally.
Thus, this pattern should not be used in an attempt to reduce bandwidth
consumption.</p>
</div>
<p>The topics that subscribers subscribe to is just the first part of
the message body.
Applications should construct their messages accordingly.</p>
<h2 id="socket-operations-2"><a class="header" href="#socket-operations-2">Socket Operations</a></h2>
<p>The <a href="proto/TODO.html"><code>nng_pub0_open</code></a> functions create a publisher socket.
This socket may be used to send messages, but is unable to receive them.
Attempts to receive messages will result in <code>NNG_ENOTSUP</code>.</p>
<h2 id="protocol-versions-2"><a class="header" href="#protocol-versions-2">Protocol Versions</a></h2>
<p>Only version 0 of this protocol is supported.
(At the time of writing, no other versions of this protocol have been defined.)</p>
<h2 id="protocol-options-2"><a class="header" href="#protocol-options-2">Protocol Options</a></h2>
<p>The <em>PUB</em> protocol has no protocol-specific options.</p>
<h2 id="protocol-headers-2"><a class="header" href="#protocol-headers-2">Protocol Headers</a></h2>
<p>The <em>PUB</em> protocol has no protocol-specific headers.</p>
<div style="break-before: page; page-break-before: always;"></div><style>
.mdbook-alerts {
padding: 8px 16px;
margin-bottom: 16px;
border-left: 0.25em solid var(--mdbook-alerts-color);
}
.mdbook-alerts > *:first-child {
margin-top: 0;
}
.mdbook-alerts > *:last-child {
margin-bottom: 0;
}
.mdbook-alerts-title {
display: flex;
font-weight: 600;
align-items: center;
line-height: 1;
color: var(--mdbook-alerts-color);
text-transform: capitalize;
}
.mdbook-alerts-icon {
display: inline-block;
width: 1em;
height: 1em;
margin-right: 0.2em;
background-color: currentColor;
-webkit-mask: no-repeat center / 100%;
mask: no-repeat center / 100%;
-webkit-mask-image: var(--mdbook-alerts-icon);
mask-image: var(--mdbook-alerts-icon);
}
.mdbook-alerts-note {
--mdbook-alerts-color: rgb(9, 105, 218);
/* https://icon-sets.iconify.design/material-symbols/info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16v-4q0-.425-.288-.712T12 11q-.425 0-.712.288T11 12v4q0 .425.288.713T12 17m0-8q.425 0 .713-.288T13 8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8q0 .425.288.713T12 9m0 13q-2.075 0-3.9-.788t-3.175-2.137q-1.35-1.35-2.137-3.175T2 12q0-2.075.788-3.9t2.137-3.175q1.35-1.35 3.175-2.137T12 2q2.075 0 3.9.788t3.175 2.137q1.35 1.35 2.138 3.175T22 12q0 2.075-.788 3.9t-2.137 3.175q-1.35 1.35-3.175 2.138T12 22m0-2q3.35 0 5.675-2.325T20 12q0-3.35-2.325-5.675T12 4Q8.65 4 6.325 6.325T4 12q0 3.35 2.325 5.675T12 20m0-8"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-tip {
--mdbook-alerts-color: rgb(26, 127, 55);
/* https://icon-sets.iconify.design/material-symbols/lightbulb-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 22q-.825 0-1.412-.587T10 20h4q0 .825-.587 1.413T12 22m-3-3q-.425 0-.712-.288T8 18q0-.425.288-.712T9 17h6q.425 0 .713.288T16 18q0 .425-.288.713T15 19zm-.75-3q-1.725-1.025-2.738-2.75T4.5 9.5q0-3.125 2.188-5.312T12 2q3.125 0 5.313 2.188T19.5 9.5q0 2.025-1.012 3.75T15.75 16zm.6-2h6.3q1.125-.8 1.738-1.975T17.5 9.5q0-2.3-1.6-3.9T12 4Q9.7 4 8.1 5.6T6.5 9.5q0 1.35.613 2.525T8.85 14M12 14"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-important {
--mdbook-alerts-color: rgb(130, 80, 223);
/* https://icon-sets.iconify.design/material-symbols/chat-info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 7q.425 0 .713-.288T13 6q0-.425-.288-.712T12 5q-.425 0-.712.288T11 6q0 .425.288.713T12 7m0 8q.425 0 .713-.288T13 14v-4q0-.425-.288-.712T12 9q-.425 0-.712.288T11 10v4q0 .425.288.713T12 15m-6 3l-2.3 2.3q-.475.475-1.088.213T2 19.575V4q0-.825.588-1.412T4 2h16q.825 0 1.413.588T22 4v12q0 .825-.587 1.413T20 18zm-.85-2H20V4H4v13.125zM4 16V4z"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-warning {
--mdbook-alerts-color: rgb(154, 103, 0);
/* https://icon-sets.iconify.design/material-symbols/warning-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M2.725 21q-.275 0-.5-.137t-.35-.363q-.125-.225-.137-.488t.137-.512l9.25-16q.15-.25.388-.375T12 3q.25 0 .488.125t.387.375l9.25 16q.15.25.138.513t-.138.487q-.125.225-.35.363t-.5.137zm1.725-2h15.1L12 6zM12 18q.425 0 .713-.288T13 17q0-.425-.288-.712T12 16q-.425 0-.712.288T11 17q0 .425.288.713T12 18m0-3q.425 0 .713-.288T13 14v-3q0-.425-.288-.712T12 10q-.425 0-.712.288T11 11v3q0 .425.288.713T12 15m0-2.5"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-caution {
--mdbook-alerts-color: rgb(207, 34, 46);
/* https://icon-sets.iconify.design/material-symbols/brightness-alert-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16q0-.425-.288-.712T12 15q-.425 0-.712.288T11 16q0 .425.288.713T12 17m0-4q.425 0 .713-.288T13 12V8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8v4q0 .425.288.713T12 13m-3.35 7H6q-.825 0-1.412-.587T4 18v-2.65L2.075 13.4q-.275-.3-.425-.662T1.5 12q0-.375.15-.737t.425-.663L4 8.65V6q0-.825.588-1.412T6 4h2.65l1.95-1.925q.3-.275.663-.425T12 1.5q.375 0 .738.15t.662.425L15.35 4H18q.825 0 1.413.588T20 6v2.65l1.925 1.95q.275.3.425.663t.15.737q0 .375-.15.738t-.425.662L20 15.35V18q0 .825-.587 1.413T18 20h-2.65l-1.95 1.925q-.3.275-.662.425T12 22.5q-.375 0-.737-.15t-.663-.425zm.85-2l2.5 2.5l2.5-2.5H18v-3.5l2.5-2.5L18 9.5V6h-3.5L12 3.5L9.5 6H6v3.5L3.5 12L6 14.5V18zm2.5-6"%2F%3E%3C%2Fsvg%3E');
}
</style>
<h1 id="pull-protocol"><a class="header" href="#pull-protocol">PULL protocol</a></h1>
<p>The <a name="a001"></a><em>PULL</em> protocol<a name="a002"></a> is one half of a
<a name="a003"></a>pipeline pattern.
The other half is the <a href="proto/./push.html"><em>PUSH</em></a> protocol.</p>
<p>In the pipeline pattern, pushers distribute messages to pullers.
Each message sent
by a pusher will be sent to one of its peer pullers,
chosen in a round-robin fashion
from the set of connected peers available for receiving.
This property makes this pattern useful in <a name="a004"></a>load-balancing scenarios.</p>
<h3 id="socket-operations-3"><a class="header" href="#socket-operations-3">Socket Operations</a></h3>
<p>The <a href="proto/TODO.html"><code>nng_pull0_open</code></a> functions create a
<em>PULL</em> socket.
This socket may be used to receive messages, but is unable to send them.
Attempts to send messages will result in <code>NNG_ENOTSUP</code>.</p>
<p>When receiving messages, the <em>PULL</em> protocol accepts messages as
they arrive from peers.
If two peers both have a message ready, the
order in which messages are handled is undefined.</p>
<h3 id="protocol-versions-3"><a class="header" href="#protocol-versions-3">Protocol Versions</a></h3>
<p>Only version 0 of this protocol is supported.
(At the time of writing, no other versions of this protocol have been defined.)</p>
<h3 id="protocol-options-3"><a class="header" href="#protocol-options-3">Protocol Options</a></h3>
<p>The <em>PULL</em> protocol has no protocol-specific options.</p>
<h3 id="protocol-headers-3"><a class="header" href="#protocol-headers-3">Protocol Headers</a></h3>
<p>The <em>PULL</em> protocol has no protocol-specific headers.</p>
<div style="break-before: page; page-break-before: always;"></div><style>
.mdbook-alerts {
padding: 8px 16px;
margin-bottom: 16px;
border-left: 0.25em solid var(--mdbook-alerts-color);
}
.mdbook-alerts > *:first-child {
margin-top: 0;
}
.mdbook-alerts > *:last-child {
margin-bottom: 0;
}
.mdbook-alerts-title {
display: flex;
font-weight: 600;
align-items: center;
line-height: 1;
color: var(--mdbook-alerts-color);
text-transform: capitalize;
}
.mdbook-alerts-icon {
display: inline-block;
width: 1em;
height: 1em;
margin-right: 0.2em;
background-color: currentColor;
-webkit-mask: no-repeat center / 100%;
mask: no-repeat center / 100%;
-webkit-mask-image: var(--mdbook-alerts-icon);
mask-image: var(--mdbook-alerts-icon);
}
.mdbook-alerts-note {
--mdbook-alerts-color: rgb(9, 105, 218);
/* https://icon-sets.iconify.design/material-symbols/info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16v-4q0-.425-.288-.712T12 11q-.425 0-.712.288T11 12v4q0 .425.288.713T12 17m0-8q.425 0 .713-.288T13 8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8q0 .425.288.713T12 9m0 13q-2.075 0-3.9-.788t-3.175-2.137q-1.35-1.35-2.137-3.175T2 12q0-2.075.788-3.9t2.137-3.175q1.35-1.35 3.175-2.137T12 2q2.075 0 3.9.788t3.175 2.137q1.35 1.35 2.138 3.175T22 12q0 2.075-.788 3.9t-2.137 3.175q-1.35 1.35-3.175 2.138T12 22m0-2q3.35 0 5.675-2.325T20 12q0-3.35-2.325-5.675T12 4Q8.65 4 6.325 6.325T4 12q0 3.35 2.325 5.675T12 20m0-8"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-tip {
--mdbook-alerts-color: rgb(26, 127, 55);
/* https://icon-sets.iconify.design/material-symbols/lightbulb-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 22q-.825 0-1.412-.587T10 20h4q0 .825-.587 1.413T12 22m-3-3q-.425 0-.712-.288T8 18q0-.425.288-.712T9 17h6q.425 0 .713.288T16 18q0 .425-.288.713T15 19zm-.75-3q-1.725-1.025-2.738-2.75T4.5 9.5q0-3.125 2.188-5.312T12 2q3.125 0 5.313 2.188T19.5 9.5q0 2.025-1.012 3.75T15.75 16zm.6-2h6.3q1.125-.8 1.738-1.975T17.5 9.5q0-2.3-1.6-3.9T12 4Q9.7 4 8.1 5.6T6.5 9.5q0 1.35.613 2.525T8.85 14M12 14"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-important {
--mdbook-alerts-color: rgb(130, 80, 223);
/* https://icon-sets.iconify.design/material-symbols/chat-info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 7q.425 0 .713-.288T13 6q0-.425-.288-.712T12 5q-.425 0-.712.288T11 6q0 .425.288.713T12 7m0 8q.425 0 .713-.288T13 14v-4q0-.425-.288-.712T12 9q-.425 0-.712.288T11 10v4q0 .425.288.713T12 15m-6 3l-2.3 2.3q-.475.475-1.088.213T2 19.575V4q0-.825.588-1.412T4 2h16q.825 0 1.413.588T22 4v12q0 .825-.587 1.413T20 18zm-.85-2H20V4H4v13.125zM4 16V4z"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-warning {
--mdbook-alerts-color: rgb(154, 103, 0);
/* https://icon-sets.iconify.design/material-symbols/warning-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M2.725 21q-.275 0-.5-.137t-.35-.363q-.125-.225-.137-.488t.137-.512l9.25-16q.15-.25.388-.375T12 3q.25 0 .488.125t.387.375l9.25 16q.15.25.138.513t-.138.487q-.125.225-.35.363t-.5.137zm1.725-2h15.1L12 6zM12 18q.425 0 .713-.288T13 17q0-.425-.288-.712T12 16q-.425 0-.712.288T11 17q0 .425.288.713T12 18m0-3q.425 0 .713-.288T13 14v-3q0-.425-.288-.712T12 10q-.425 0-.712.288T11 11v3q0 .425.288.713T12 15m0-2.5"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-caution {
--mdbook-alerts-color: rgb(207, 34, 46);
/* https://icon-sets.iconify.design/material-symbols/brightness-alert-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16q0-.425-.288-.712T12 15q-.425 0-.712.288T11 16q0 .425.288.713T12 17m0-4q.425 0 .713-.288T13 12V8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8v4q0 .425.288.713T12 13m-3.35 7H6q-.825 0-1.412-.587T4 18v-2.65L2.075 13.4q-.275-.3-.425-.662T1.5 12q0-.375.15-.737t.425-.663L4 8.65V6q0-.825.588-1.412T6 4h2.65l1.95-1.925q.3-.275.663-.425T12 1.5q.375 0 .738.15t.662.425L15.35 4H18q.825 0 1.413.588T20 6v2.65l1.925 1.95q.275.3.425.663t.15.737q0 .375-.15.738t-.425.662L20 15.35V18q0 .825-.587 1.413T18 20h-2.65l-1.95 1.925q-.3.275-.662.425T12 22.5q-.375 0-.737-.15t-.663-.425zm.85-2l2.5 2.5l2.5-2.5H18v-3.5l2.5-2.5L18 9.5V6h-3.5L12 3.5L9.5 6H6v3.5L3.5 12L6 14.5V18zm2.5-6"%2F%3E%3C%2Fsvg%3E');
}
</style>
<h1 id="push-protocol"><a class="header" href="#push-protocol">PUSH protocol</a></h1>
<h2 id="description"><a class="header" href="#description">DESCRIPTION</a></h2>
<p>The <a name="a001"></a><em>PUSH</em> protocol<a name="a002"></a> is one half of a <a name="a003"></a>pipeline pattern.
The other side is the <a href="proto/./pull.html"><em>PULL</em></a> protocol.</p>
<p>In the pipeline pattern, pushers distribute messages to pullers.
Each message sent by a pusher will be sent to one of its peer pullers,
chosen in a round-robin fashion
from the set of connected peers available for receiving.
This property makes this pattern useful in <a name="a004"></a>load-balancing scenarios.</p>
<h3 id="socket-operations-4"><a class="header" href="#socket-operations-4">Socket Operations</a></h3>
<p>The <a href="proto/TODO.html"><code>nng_push0_open</code></a> call creates a <em>PUSH</em> socket.
This socket may be used to send messages, but is unable to receive them.
Attempts to receive messages will result in <code>NNG_ENOTSUP</code>.</p>
<p>Send operations will observe flow control (back-pressure), so that
only peers capable of accepting a message will be considered.
If no peer is available to receive a message, then the send operation will
wait until one is available, or the operation times out.</p>
<div class="mdbook-alerts mdbook-alerts-note">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
note
</p>
<p>Although the pipeline protocol honors flow control, and attempts
to avoid dropping messages, no guarantee of delivery is made.
Furthermore, as there is no capability for message acknowledgment,
applications that need reliable delivery are encouraged to consider the
<a href="proto/./req.html"><em>REQ</em></a> protocol instead.</p>
</div>
<h3 id="protocol-versions-4"><a class="header" href="#protocol-versions-4">Protocol Versions</a></h3>
<p>Only version 0 of this protocol is supported.
(At the time of writing, no other versions of this protocol have been defined.)</p>
<h3 id="protocol-options-4"><a class="header" href="#protocol-options-4">Protocol Options</a></h3>
<ul>
<li><a href="proto/TODO.html"><code>NNG_OPT_SENDBUF</code></a>:
(<code>int</code>, 0 - 8192)
Normally this is set to zero, indicating that send operations are unbuffered.
In unbuffered operation, send operations will wait until a suitable peer is available to receive the message.
If this is set to a positive value (up to 8192), then an intermediate buffer is
provided for the socket with the specified depth (in messages).</li>
</ul>
<div class="mdbook-alerts mdbook-alerts-note">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
note
</p>
<p>Transport layer buffering may occur in addition to any socket
buffer determined by this option.</p>
</div>
<h3 id="protocol-headers-4"><a class="header" href="#protocol-headers-4">Protocol Headers</a></h3>
<p>The <em>PUSH</em> protocol has no protocol-specific headers.</p>
<div style="break-before: page; page-break-before: always;"></div><style>
.mdbook-alerts {
padding: 8px 16px;
margin-bottom: 16px;
border-left: 0.25em solid var(--mdbook-alerts-color);
}
.mdbook-alerts > *:first-child {
margin-top: 0;
}
.mdbook-alerts > *:last-child {
margin-bottom: 0;
}
.mdbook-alerts-title {
display: flex;
font-weight: 600;
align-items: center;
line-height: 1;
color: var(--mdbook-alerts-color);
text-transform: capitalize;
}
.mdbook-alerts-icon {
display: inline-block;
width: 1em;
height: 1em;
margin-right: 0.2em;
background-color: currentColor;
-webkit-mask: no-repeat center / 100%;
mask: no-repeat center / 100%;
-webkit-mask-image: var(--mdbook-alerts-icon);
mask-image: var(--mdbook-alerts-icon);
}
.mdbook-alerts-note {
--mdbook-alerts-color: rgb(9, 105, 218);
/* https://icon-sets.iconify.design/material-symbols/info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16v-4q0-.425-.288-.712T12 11q-.425 0-.712.288T11 12v4q0 .425.288.713T12 17m0-8q.425 0 .713-.288T13 8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8q0 .425.288.713T12 9m0 13q-2.075 0-3.9-.788t-3.175-2.137q-1.35-1.35-2.137-3.175T2 12q0-2.075.788-3.9t2.137-3.175q1.35-1.35 3.175-2.137T12 2q2.075 0 3.9.788t3.175 2.137q1.35 1.35 2.138 3.175T22 12q0 2.075-.788 3.9t-2.137 3.175q-1.35 1.35-3.175 2.138T12 22m0-2q3.35 0 5.675-2.325T20 12q0-3.35-2.325-5.675T12 4Q8.65 4 6.325 6.325T4 12q0 3.35 2.325 5.675T12 20m0-8"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-tip {
--mdbook-alerts-color: rgb(26, 127, 55);
/* https://icon-sets.iconify.design/material-symbols/lightbulb-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 22q-.825 0-1.412-.587T10 20h4q0 .825-.587 1.413T12 22m-3-3q-.425 0-.712-.288T8 18q0-.425.288-.712T9 17h6q.425 0 .713.288T16 18q0 .425-.288.713T15 19zm-.75-3q-1.725-1.025-2.738-2.75T4.5 9.5q0-3.125 2.188-5.312T12 2q3.125 0 5.313 2.188T19.5 9.5q0 2.025-1.012 3.75T15.75 16zm.6-2h6.3q1.125-.8 1.738-1.975T17.5 9.5q0-2.3-1.6-3.9T12 4Q9.7 4 8.1 5.6T6.5 9.5q0 1.35.613 2.525T8.85 14M12 14"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-important {
--mdbook-alerts-color: rgb(130, 80, 223);
/* https://icon-sets.iconify.design/material-symbols/chat-info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 7q.425 0 .713-.288T13 6q0-.425-.288-.712T12 5q-.425 0-.712.288T11 6q0 .425.288.713T12 7m0 8q.425 0 .713-.288T13 14v-4q0-.425-.288-.712T12 9q-.425 0-.712.288T11 10v4q0 .425.288.713T12 15m-6 3l-2.3 2.3q-.475.475-1.088.213T2 19.575V4q0-.825.588-1.412T4 2h16q.825 0 1.413.588T22 4v12q0 .825-.587 1.413T20 18zm-.85-2H20V4H4v13.125zM4 16V4z"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-warning {
--mdbook-alerts-color: rgb(154, 103, 0);
/* https://icon-sets.iconify.design/material-symbols/warning-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M2.725 21q-.275 0-.5-.137t-.35-.363q-.125-.225-.137-.488t.137-.512l9.25-16q.15-.25.388-.375T12 3q.25 0 .488.125t.387.375l9.25 16q.15.25.138.513t-.138.487q-.125.225-.35.363t-.5.137zm1.725-2h15.1L12 6zM12 18q.425 0 .713-.288T13 17q0-.425-.288-.712T12 16q-.425 0-.712.288T11 17q0 .425.288.713T12 18m0-3q.425 0 .713-.288T13 14v-3q0-.425-.288-.712T12 10q-.425 0-.712.288T11 11v3q0 .425.288.713T12 15m0-2.5"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-caution {
--mdbook-alerts-color: rgb(207, 34, 46);
/* https://icon-sets.iconify.design/material-symbols/brightness-alert-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16q0-.425-.288-.712T12 15q-.425 0-.712.288T11 16q0 .425.288.713T12 17m0-4q.425 0 .713-.288T13 12V8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8v4q0 .425.288.713T12 13m-3.35 7H6q-.825 0-1.412-.587T4 18v-2.65L2.075 13.4q-.275-.3-.425-.662T1.5 12q0-.375.15-.737t.425-.663L4 8.65V6q0-.825.588-1.412T6 4h2.65l1.95-1.925q.3-.275.663-.425T12 1.5q.375 0 .738.15t.662.425L15.35 4H18q.825 0 1.413.588T20 6v2.65l1.925 1.95q.275.3.425.663t.15.737q0 .375-.15.738t-.425.662L20 15.35V18q0 .825-.587 1.413T18 20h-2.65l-1.95 1.925q-.3.275-.662.425T12 22.5q-.375 0-.737-.15t-.663-.425zm.85-2l2.5 2.5l2.5-2.5H18v-3.5l2.5-2.5L18 9.5V6h-3.5L12 3.5L9.5 6H6v3.5L3.5 12L6 14.5V18zm2.5-6"%2F%3E%3C%2Fsvg%3E');
}
</style>
<h1 id="rep-protocol"><a class="header" href="#rep-protocol">REP Protocol</a></h1>
<p>The <a name="a001"></a><em>REP</em> protocol<a name="a002"></a> is one half of a <a name="a003"></a>request/reply pattern.
In this pattern, a requester sends a message to one replier, who
is expected to reply.
The request is resent if no reply arrives,
until a reply is received or the request times out.</p>
<div class="mdbook-alerts mdbook-alerts-tip">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
tip
</p>
<p>This protocol is useful in setting up RPC-like services.
It is also reliable, in that a requester will keep retrying until
a reply is received.</p>
</div>
<p>The <em>REP</em> protocol is the replier side, and the
<a href="proto/./req.html"><em>REP</em></a> protocol is the requester side.</p>
<h2 id="socket-operations-5"><a class="header" href="#socket-operations-5">Socket Operations</a></h2>
<p>The <a href="proto/TODO.html"><code>nng_rep0_open</code></a> functions create a replier socket.
This socket may be used to receive messages (requests), and then to send
replies.</p>
<p>Generally a reply can only be sent after receiving a request.</p>
<p>Send operations will result in <code>NNG_ESTATE</code> if no corresponding request
was previously received.</p>
<p>Likewise, only one receive operation may be pending at a time.
Any additional concurrent receive operations will result in <code>NNG_ESTATE</code>.</p>
<p><a href="proto/TODO.html">Raw mode</a> sockets ignore all these restrictions.</p>
<h2 id="context-operations"><a class="header" href="#context-operations">Context Operations</a></h2>
<p>This protocol supports the creation of <a href="proto/TODO.html">contexts</a> for concurrent
use cases using <a href="proto/TODO.html"><code>nng_ctx_open</code></a>.</p>
<p>Each context may have at most one outstanding request, and operates
independently of the others.
The restrictions for order of operations with sockets apply equally
well for contexts, except that each context will be treated as if it were
a separate socket.</p>
<h2 id="protocol-versions-5"><a class="header" href="#protocol-versions-5">Protocol Versions</a></h2>
<p>Only version 0 of this protocol is supported.
(At the time of writing, no other versions of this protocol have been defined.)</p>
<h2 id="protocol-options-5"><a class="header" href="#protocol-options-5">Protocol Options</a></h2>
<p>The <em>REP</em> protocol has no protocol-specific options.</p>
<h2 id="protocol-headers-5"><a class="header" href="#protocol-headers-5">Protocol Headers</a></h2>
<p>The <em>REP</em> protocol uses a <a name="a004"></a><em>backtrace</em> in the header.
This is more fully documented in the <a href="proto/./req.html"><em>REQ</em></a> chapter.</p>
<div style="break-before: page; page-break-before: always;"></div><style>
.mdbook-alerts {
padding: 8px 16px;
margin-bottom: 16px;
border-left: 0.25em solid var(--mdbook-alerts-color);
}
.mdbook-alerts > *:first-child {
margin-top: 0;
}
.mdbook-alerts > *:last-child {
margin-bottom: 0;
}
.mdbook-alerts-title {
display: flex;
font-weight: 600;
align-items: center;
line-height: 1;
color: var(--mdbook-alerts-color);
text-transform: capitalize;
}
.mdbook-alerts-icon {
display: inline-block;
width: 1em;
height: 1em;
margin-right: 0.2em;
background-color: currentColor;
-webkit-mask: no-repeat center / 100%;
mask: no-repeat center / 100%;
-webkit-mask-image: var(--mdbook-alerts-icon);
mask-image: var(--mdbook-alerts-icon);
}
.mdbook-alerts-note {
--mdbook-alerts-color: rgb(9, 105, 218);
/* https://icon-sets.iconify.design/material-symbols/info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16v-4q0-.425-.288-.712T12 11q-.425 0-.712.288T11 12v4q0 .425.288.713T12 17m0-8q.425 0 .713-.288T13 8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8q0 .425.288.713T12 9m0 13q-2.075 0-3.9-.788t-3.175-2.137q-1.35-1.35-2.137-3.175T2 12q0-2.075.788-3.9t2.137-3.175q1.35-1.35 3.175-2.137T12 2q2.075 0 3.9.788t3.175 2.137q1.35 1.35 2.138 3.175T22 12q0 2.075-.788 3.9t-2.137 3.175q-1.35 1.35-3.175 2.138T12 22m0-2q3.35 0 5.675-2.325T20 12q0-3.35-2.325-5.675T12 4Q8.65 4 6.325 6.325T4 12q0 3.35 2.325 5.675T12 20m0-8"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-tip {
--mdbook-alerts-color: rgb(26, 127, 55);
/* https://icon-sets.iconify.design/material-symbols/lightbulb-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 22q-.825 0-1.412-.587T10 20h4q0 .825-.587 1.413T12 22m-3-3q-.425 0-.712-.288T8 18q0-.425.288-.712T9 17h6q.425 0 .713.288T16 18q0 .425-.288.713T15 19zm-.75-3q-1.725-1.025-2.738-2.75T4.5 9.5q0-3.125 2.188-5.312T12 2q3.125 0 5.313 2.188T19.5 9.5q0 2.025-1.012 3.75T15.75 16zm.6-2h6.3q1.125-.8 1.738-1.975T17.5 9.5q0-2.3-1.6-3.9T12 4Q9.7 4 8.1 5.6T6.5 9.5q0 1.35.613 2.525T8.85 14M12 14"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-important {
--mdbook-alerts-color: rgb(130, 80, 223);
/* https://icon-sets.iconify.design/material-symbols/chat-info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 7q.425 0 .713-.288T13 6q0-.425-.288-.712T12 5q-.425 0-.712.288T11 6q0 .425.288.713T12 7m0 8q.425 0 .713-.288T13 14v-4q0-.425-.288-.712T12 9q-.425 0-.712.288T11 10v4q0 .425.288.713T12 15m-6 3l-2.3 2.3q-.475.475-1.088.213T2 19.575V4q0-.825.588-1.412T4 2h16q.825 0 1.413.588T22 4v12q0 .825-.587 1.413T20 18zm-.85-2H20V4H4v13.125zM4 16V4z"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-warning {
--mdbook-alerts-color: rgb(154, 103, 0);
/* https://icon-sets.iconify.design/material-symbols/warning-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M2.725 21q-.275 0-.5-.137t-.35-.363q-.125-.225-.137-.488t.137-.512l9.25-16q.15-.25.388-.375T12 3q.25 0 .488.125t.387.375l9.25 16q.15.25.138.513t-.138.487q-.125.225-.35.363t-.5.137zm1.725-2h15.1L12 6zM12 18q.425 0 .713-.288T13 17q0-.425-.288-.712T12 16q-.425 0-.712.288T11 17q0 .425.288.713T12 18m0-3q.425 0 .713-.288T13 14v-3q0-.425-.288-.712T12 10q-.425 0-.712.288T11 11v3q0 .425.288.713T12 15m0-2.5"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-caution {
--mdbook-alerts-color: rgb(207, 34, 46);
/* https://icon-sets.iconify.design/material-symbols/brightness-alert-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16q0-.425-.288-.712T12 15q-.425 0-.712.288T11 16q0 .425.288.713T12 17m0-4q.425 0 .713-.288T13 12V8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8v4q0 .425.288.713T12 13m-3.35 7H6q-.825 0-1.412-.587T4 18v-2.65L2.075 13.4q-.275-.3-.425-.662T1.5 12q0-.375.15-.737t.425-.663L4 8.65V6q0-.825.588-1.412T6 4h2.65l1.95-1.925q.3-.275.663-.425T12 1.5q.375 0 .738.15t.662.425L15.35 4H18q.825 0 1.413.588T20 6v2.65l1.925 1.95q.275.3.425.663t.15.737q0 .375-.15.738t-.425.662L20 15.35V18q0 .825-.587 1.413T18 20h-2.65l-1.95 1.925q-.3.275-.662.425T12 22.5q-.375 0-.737-.15t-.663-.425zm.85-2l2.5 2.5l2.5-2.5H18v-3.5l2.5-2.5L18 9.5V6h-3.5L12 3.5L9.5 6H6v3.5L3.5 12L6 14.5V18zm2.5-6"%2F%3E%3C%2Fsvg%3E');
}
</style>
<h1 id="req-protocol"><a class="header" href="#req-protocol">REQ protocol</a></h1>
<p>The <a name="a001"></a><em>REQ</em> protocol<a name="a002"></a> is one half of a <a name="a003"></a>request/reply pattern.
In this pattern, a requester sends a message to one replier, who
is expected to reply.
The request is resent if no reply arrives,
until a reply is received or the request times out.</p>
<div class="mdbook-alerts mdbook-alerts-tip">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
tip
</p>
<p>This protocol is useful in setting up RPC-like services.
It is also “reliable”, in that a the requester will keep retrying until
a reply is received.</p>
</div>
<div class="mdbook-alerts mdbook-alerts-note">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
note
</p>
<p>Because requests are resent, it is important that they be <a name="a004"></a>idempotent
to ensure predictable and repeatable behavior even in the face of duplicated
requests, which can occur (for example if a reply message is lost for
some reason.)</p>
</div>
<p><a name="a005"></a>
The requester generally only has one outstanding request at a time unless
in <a href="proto/TODO.html">raw mode</a>,
and it will generally attempt to spread work requests to different peer repliers.</p>
<div class="mdbook-alerts mdbook-alerts-tip">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
tip
</p>
<p>This property, when combined with a <a href="proto/TODO.html">device</a>
can help provide a degree of load-balancing.</p>
</div>
<p>The <em>REQ</em> protocol is the requester side, and the <a href="proto/./rep.html"><em>REP</em></a> protocol
is the replier side.</p>
<h3 id="socket-operations-6"><a class="header" href="#socket-operations-6">Socket Operations</a></h3>
<p>The <a href="proto/TODO.html"><code>nng_req0_open</code></a> functions create a <em>REQ</em> socket.
This socket may be used to send messages (requests), and then to receive replies.</p>
<p>Generally a reply can only be received after sending a request.
(Attempts to receive a message will result in <code>NNG_ESTATE</code> if there is no
outstanding request.)</p>
<p>Furthermore, only a single receive operation may be pending at a time.
Attempts to post more receive operations concurrently will result in
<code>NNG_ESTATE</code>.</p>
<p>Requests may be canceled by sending a different request.
This will cause the requester to discard any reply from the earlier request,
but it will not stop a replier
from processing a request it has already received or terminate a request
that has already been placed on the wire.</p>
<p><a href="proto/TODO.html">Raw mode</a> sockets ignore all these restrictions.</p>
<h3 id="context-operations-1"><a class="header" href="#context-operations-1">Context Operations</a></h3>
<p>This protocol supports the creation of <a href="proto/TODO.html">contexts</a> for concurrent
use cases using <a href="proto/TODO.html"><code>nng_ctx_open</code></a>.</p>
<p>The <code>NNG_OPT_REQ_RESENDTIME</code> value may be configured differently
on contexts created this way.</p>
<p>Each context may have at most one outstanding request, and operates
independently from the others.</p>
<p>The restrictions for order of operations with sockets apply equally
well for contexts, except that each context will be treated as if it were
a separate socket.</p>
<h3 id="protocol-versions-6"><a class="header" href="#protocol-versions-6">Protocol Versions</a></h3>
<p>Only version 0 of this protocol is supported.
(At the time of writing, no other versions of this protocol have been defined.)</p>
<h3 id="protocol-options-6"><a class="header" href="#protocol-options-6">Protocol Options</a></h3>
<p>The following protocol-specific option is available.</p>
<ul>
<li>
<p><a name="a006"></a><code>NNG_OPT_REQ_RESENDTIME</code>: <br />
(<a href="proto/../api/util/nng_duration.html"><code>nng_duration</code></a>) <br />
When a new request is started, a timer of this duration is also started.
If no reply is received before this timer expires, then the request will
be resent. <br />
<br />
Requests are also automatically resent if the peer to whom
the original request was sent disconnects. <br />
<br />
Resending may be deferred up to the value of the <code>NNG_OPT_RESENDTICK</code> parameter. <br />
<br />
If the value is set to <a href="proto/../api/util/nng_duration.html"><code>NNG_DURATION_INFINITE</code></a>, then resends are disabled
altogether. This should be used when the request is not idemptoent.</p>
</li>
<li>
<p><a name="a007"></a><code>NNG_OPT_REQ_RESENDTICK</code>: <br />
(<a href="proto/../api/util/nng_duration.html"><code>nng_duration</code></a>) <br />
This is the granularity of the clock that is used to check for resending.
The default is a second. Setting this to a higher rate will allow for
more timely resending to occur, but may incur significant additional
overhead when the socket has many outstanding requests (contexts). <br />
<br />
When there are no requests outstanding that have a resend set, then
the clock does not tick at all. <br />
<br />
This option is shared for all contexts on a socket, and is only available for the socket itself.</p>
</li>
</ul>
<h3 id="protocol-headers-6"><a class="header" href="#protocol-headers-6">Protocol Headers</a></h3>
<p>This protocol uses a <a name="a008"></a><em>backtrace</em> in the header.
This form uses a stack of 32-bit big-endian identifiers.
There <em>must</em> be at least one identifier, the <strong>request ID</strong>, which will be the
last element in the array, and <em>must</em> have the most significant bit set.</p>
<p>There may be additional <strong>peer ID</strong>s preceding the request ID.
These will be distinguishable from the request ID by having their most
significant bit clear.</p>
<p>When a request message is received by a forwarding node (such as a <a href="proto/TODO.html">device</a>),
the forwarding node prepends a
32-bit peer ID (which <em>must</em> have the most significant bit clear),
which is the forwarder’s way of identifying the directly connected
peer from which it received the message.
(This peer ID, except for the
most significant bit, has meaning only to the forwarding node itself.)</p>
<p>It may help to think of prepending a peer ID as pushing a peer ID onto the
front of the stack of headers for the message.
(It will use the peer ID
it popped from the front to determine the next intermediate destination
for the reply.)</p>
<p>When a reply message is created, it is created using the same headers
that the request contained.</p>
<p>A forwarding node can pop the peer ID it originally pushed on the
message, stripping it from the front of the message as it does so.</p>
<p>When the reply finally arrives back at the initiating requester, it
should have only a single element in the message, which will be the
request ID it originally used for the request.</p>
<div style="break-before: page; page-break-before: always;"></div><style>
.mdbook-alerts {
padding: 8px 16px;
margin-bottom: 16px;
border-left: 0.25em solid var(--mdbook-alerts-color);
}
.mdbook-alerts > *:first-child {
margin-top: 0;
}
.mdbook-alerts > *:last-child {
margin-bottom: 0;
}
.mdbook-alerts-title {
display: flex;
font-weight: 600;
align-items: center;
line-height: 1;
color: var(--mdbook-alerts-color);
text-transform: capitalize;
}
.mdbook-alerts-icon {
display: inline-block;
width: 1em;
height: 1em;
margin-right: 0.2em;
background-color: currentColor;
-webkit-mask: no-repeat center / 100%;
mask: no-repeat center / 100%;
-webkit-mask-image: var(--mdbook-alerts-icon);
mask-image: var(--mdbook-alerts-icon);
}
.mdbook-alerts-note {
--mdbook-alerts-color: rgb(9, 105, 218);
/* https://icon-sets.iconify.design/material-symbols/info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16v-4q0-.425-.288-.712T12 11q-.425 0-.712.288T11 12v4q0 .425.288.713T12 17m0-8q.425 0 .713-.288T13 8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8q0 .425.288.713T12 9m0 13q-2.075 0-3.9-.788t-3.175-2.137q-1.35-1.35-2.137-3.175T2 12q0-2.075.788-3.9t2.137-3.175q1.35-1.35 3.175-2.137T12 2q2.075 0 3.9.788t3.175 2.137q1.35 1.35 2.138 3.175T22 12q0 2.075-.788 3.9t-2.137 3.175q-1.35 1.35-3.175 2.138T12 22m0-2q3.35 0 5.675-2.325T20 12q0-3.35-2.325-5.675T12 4Q8.65 4 6.325 6.325T4 12q0 3.35 2.325 5.675T12 20m0-8"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-tip {
--mdbook-alerts-color: rgb(26, 127, 55);
/* https://icon-sets.iconify.design/material-symbols/lightbulb-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 22q-.825 0-1.412-.587T10 20h4q0 .825-.587 1.413T12 22m-3-3q-.425 0-.712-.288T8 18q0-.425.288-.712T9 17h6q.425 0 .713.288T16 18q0 .425-.288.713T15 19zm-.75-3q-1.725-1.025-2.738-2.75T4.5 9.5q0-3.125 2.188-5.312T12 2q3.125 0 5.313 2.188T19.5 9.5q0 2.025-1.012 3.75T15.75 16zm.6-2h6.3q1.125-.8 1.738-1.975T17.5 9.5q0-2.3-1.6-3.9T12 4Q9.7 4 8.1 5.6T6.5 9.5q0 1.35.613 2.525T8.85 14M12 14"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-important {
--mdbook-alerts-color: rgb(130, 80, 223);
/* https://icon-sets.iconify.design/material-symbols/chat-info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 7q.425 0 .713-.288T13 6q0-.425-.288-.712T12 5q-.425 0-.712.288T11 6q0 .425.288.713T12 7m0 8q.425 0 .713-.288T13 14v-4q0-.425-.288-.712T12 9q-.425 0-.712.288T11 10v4q0 .425.288.713T12 15m-6 3l-2.3 2.3q-.475.475-1.088.213T2 19.575V4q0-.825.588-1.412T4 2h16q.825 0 1.413.588T22 4v12q0 .825-.587 1.413T20 18zm-.85-2H20V4H4v13.125zM4 16V4z"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-warning {
--mdbook-alerts-color: rgb(154, 103, 0);
/* https://icon-sets.iconify.design/material-symbols/warning-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M2.725 21q-.275 0-.5-.137t-.35-.363q-.125-.225-.137-.488t.137-.512l9.25-16q.15-.25.388-.375T12 3q.25 0 .488.125t.387.375l9.25 16q.15.25.138.513t-.138.487q-.125.225-.35.363t-.5.137zm1.725-2h15.1L12 6zM12 18q.425 0 .713-.288T13 17q0-.425-.288-.712T12 16q-.425 0-.712.288T11 17q0 .425.288.713T12 18m0-3q.425 0 .713-.288T13 14v-3q0-.425-.288-.712T12 10q-.425 0-.712.288T11 11v3q0 .425.288.713T12 15m0-2.5"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-caution {
--mdbook-alerts-color: rgb(207, 34, 46);
/* https://icon-sets.iconify.design/material-symbols/brightness-alert-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16q0-.425-.288-.712T12 15q-.425 0-.712.288T11 16q0 .425.288.713T12 17m0-4q.425 0 .713-.288T13 12V8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8v4q0 .425.288.713T12 13m-3.35 7H6q-.825 0-1.412-.587T4 18v-2.65L2.075 13.4q-.275-.3-.425-.662T1.5 12q0-.375.15-.737t.425-.663L4 8.65V6q0-.825.588-1.412T6 4h2.65l1.95-1.925q.3-.275.663-.425T12 1.5q.375 0 .738.15t.662.425L15.35 4H18q.825 0 1.413.588T20 6v2.65l1.925 1.95q.275.3.425.663t.15.737q0 .375-.15.738t-.425.662L20 15.35V18q0 .825-.587 1.413T18 20h-2.65l-1.95 1.925q-.3.275-.662.425T12 22.5q-.375 0-.737-.15t-.663-.425zm.85-2l2.5 2.5l2.5-2.5H18v-3.5l2.5-2.5L18 9.5V6h-3.5L12 3.5L9.5 6H6v3.5L3.5 12L6 14.5V18zm2.5-6"%2F%3E%3C%2Fsvg%3E');
}
</style>
<h1 id="respondent-protocol"><a class="header" href="#respondent-protocol">RESPONDENT protocol</a></h1>
<p>The <a name="a001"></a><em>RESPONDENT</em> protocol<a name="a002"></a> is one half of a <a name="a003"></a>survey pattern.
In this pattern, a surveyor sends a survey, which is broadcast to all
peer respondents.
The respondents then have a chance to reply (but are not obliged to reply).
The survey itself is a timed event, so that responses
received after the survey has finished are discarded.</p>
<div class="mdbook-alerts mdbook-alerts-tip">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
tip
</p>
<p>This protocol is useful in solving voting problems, such as leader
election in cluster configurations, as well as certain kinds of service
discovery problems.</p>
</div>
<p>The <em>RESPONDENT</em> protocol is the respondent side, and the
<a href="proto/./surveyor.html"><em>SURVEYOR</em></a> protocol is the surveyor side.</p>
<h3 id="socket-operations-7"><a class="header" href="#socket-operations-7">Socket Operations</a></h3>
<p>The <a href="proto/TODO.html"><code>nng_respondent0_open</code></a> functions create a
respondent socket.
This socket may be used to receive messages, and then to send replies.
A reply can only be sent after receiving a survey, and generally the
reply will be sent to surveyor from whom the last survey was received.</p>
<p>Respondents may discard a survey by simply not replying to it.</p>
<p><a href="proto/TODO.html">Raw mode</a> sockets ignore all these restrictions.</p>
<h3 id="context-operations-2"><a class="header" href="#context-operations-2">Context Operations</a></h3>
<p>This protocol supports the creation of <a href="proto/TODO.html">contexts</a> for concurrent
use cases using <a href="proto/TODO.html"><code>nng_ctx_open</code></a>.</p>
<p>Incoming surveys will be routed to and received by only one context.
Additional surveys may be received by other contexts in parallel.
Replies made using a context will be returned to the the surveyor that
issued the survey most recently received by that context.
The restrictions for order of operations with sockets apply equally
well for contexts, except that each context will be treated as if it were
a separate socket.</p>
<h3 id="protocol-versions-7"><a class="header" href="#protocol-versions-7">Protocol Versions</a></h3>
<p>Only version 0 of this protocol is supported.
At the time of writing, no other versions of this protocol have been defined.
<sup><a name="to-footnote-1"><a href="proto/respondent.html#footnote-1">1</a></a></sup></p>
<h3 id="protocol-options-7"><a class="header" href="#protocol-options-7">Protocol Options</a></h3>
<p>The <em>respondent</em> protocol has no protocol-specific options.</p>
<h3 id="protocol-headers-7"><a class="header" href="#protocol-headers-7">Protocol Headers</a></h3>
<p>The <em>RESPONDENT</em> protocol uses a <a name="a004"></a><em>backtrace</em> in the header.
This is more fully documented in the <a href="proto/./surveyor.html"><em>SURVEYOR</em></a> manual.</p>
<p><hr/>
<p><a name="footnote-1"><a href="proto/respondent.html#to-footnote-1">1</a></a>: An earlier and incompatible version of the protocol was used in older
pre-releases of <a href="proto/TODO.html">nanomsg</a>, but was not released in any production version.</p>
<div style="break-before: page; page-break-before: always;"></div><style>
.mdbook-alerts {
padding: 8px 16px;
margin-bottom: 16px;
border-left: 0.25em solid var(--mdbook-alerts-color);
}
.mdbook-alerts > *:first-child {
margin-top: 0;
}
.mdbook-alerts > *:last-child {
margin-bottom: 0;
}
.mdbook-alerts-title {
display: flex;
font-weight: 600;
align-items: center;
line-height: 1;
color: var(--mdbook-alerts-color);
text-transform: capitalize;
}
.mdbook-alerts-icon {
display: inline-block;
width: 1em;
height: 1em;
margin-right: 0.2em;
background-color: currentColor;
-webkit-mask: no-repeat center / 100%;
mask: no-repeat center / 100%;
-webkit-mask-image: var(--mdbook-alerts-icon);
mask-image: var(--mdbook-alerts-icon);
}
.mdbook-alerts-note {
--mdbook-alerts-color: rgb(9, 105, 218);
/* https://icon-sets.iconify.design/material-symbols/info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16v-4q0-.425-.288-.712T12 11q-.425 0-.712.288T11 12v4q0 .425.288.713T12 17m0-8q.425 0 .713-.288T13 8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8q0 .425.288.713T12 9m0 13q-2.075 0-3.9-.788t-3.175-2.137q-1.35-1.35-2.137-3.175T2 12q0-2.075.788-3.9t2.137-3.175q1.35-1.35 3.175-2.137T12 2q2.075 0 3.9.788t3.175 2.137q1.35 1.35 2.138 3.175T22 12q0 2.075-.788 3.9t-2.137 3.175q-1.35 1.35-3.175 2.138T12 22m0-2q3.35 0 5.675-2.325T20 12q0-3.35-2.325-5.675T12 4Q8.65 4 6.325 6.325T4 12q0 3.35 2.325 5.675T12 20m0-8"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-tip {
--mdbook-alerts-color: rgb(26, 127, 55);
/* https://icon-sets.iconify.design/material-symbols/lightbulb-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 22q-.825 0-1.412-.587T10 20h4q0 .825-.587 1.413T12 22m-3-3q-.425 0-.712-.288T8 18q0-.425.288-.712T9 17h6q.425 0 .713.288T16 18q0 .425-.288.713T15 19zm-.75-3q-1.725-1.025-2.738-2.75T4.5 9.5q0-3.125 2.188-5.312T12 2q3.125 0 5.313 2.188T19.5 9.5q0 2.025-1.012 3.75T15.75 16zm.6-2h6.3q1.125-.8 1.738-1.975T17.5 9.5q0-2.3-1.6-3.9T12 4Q9.7 4 8.1 5.6T6.5 9.5q0 1.35.613 2.525T8.85 14M12 14"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-important {
--mdbook-alerts-color: rgb(130, 80, 223);
/* https://icon-sets.iconify.design/material-symbols/chat-info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 7q.425 0 .713-.288T13 6q0-.425-.288-.712T12 5q-.425 0-.712.288T11 6q0 .425.288.713T12 7m0 8q.425 0 .713-.288T13 14v-4q0-.425-.288-.712T12 9q-.425 0-.712.288T11 10v4q0 .425.288.713T12 15m-6 3l-2.3 2.3q-.475.475-1.088.213T2 19.575V4q0-.825.588-1.412T4 2h16q.825 0 1.413.588T22 4v12q0 .825-.587 1.413T20 18zm-.85-2H20V4H4v13.125zM4 16V4z"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-warning {
--mdbook-alerts-color: rgb(154, 103, 0);
/* https://icon-sets.iconify.design/material-symbols/warning-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M2.725 21q-.275 0-.5-.137t-.35-.363q-.125-.225-.137-.488t.137-.512l9.25-16q.15-.25.388-.375T12 3q.25 0 .488.125t.387.375l9.25 16q.15.25.138.513t-.138.487q-.125.225-.35.363t-.5.137zm1.725-2h15.1L12 6zM12 18q.425 0 .713-.288T13 17q0-.425-.288-.712T12 16q-.425 0-.712.288T11 17q0 .425.288.713T12 18m0-3q.425 0 .713-.288T13 14v-3q0-.425-.288-.712T12 10q-.425 0-.712.288T11 11v3q0 .425.288.713T12 15m0-2.5"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-caution {
--mdbook-alerts-color: rgb(207, 34, 46);
/* https://icon-sets.iconify.design/material-symbols/brightness-alert-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16q0-.425-.288-.712T12 15q-.425 0-.712.288T11 16q0 .425.288.713T12 17m0-4q.425 0 .713-.288T13 12V8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8v4q0 .425.288.713T12 13m-3.35 7H6q-.825 0-1.412-.587T4 18v-2.65L2.075 13.4q-.275-.3-.425-.662T1.5 12q0-.375.15-.737t.425-.663L4 8.65V6q0-.825.588-1.412T6 4h2.65l1.95-1.925q.3-.275.663-.425T12 1.5q.375 0 .738.15t.662.425L15.35 4H18q.825 0 1.413.588T20 6v2.65l1.925 1.95q.275.3.425.663t.15.737q0 .375-.15.738t-.425.662L20 15.35V18q0 .825-.587 1.413T18 20h-2.65l-1.95 1.925q-.3.275-.662.425T12 22.5q-.375 0-.737-.15t-.663-.425zm.85-2l2.5 2.5l2.5-2.5H18v-3.5l2.5-2.5L18 9.5V6h-3.5L12 3.5L9.5 6H6v3.5L3.5 12L6 14.5V18zm2.5-6"%2F%3E%3C%2Fsvg%3E');
}
</style>
<h1 id="sub-protocol"><a class="header" href="#sub-protocol">SUB protocol</a></h1>
<p>The <a name="a001"></a><em>SUB</em> protocol<a name="a002"></a> is one half of a publisher/<a name="a003"></a>subscriber pattern.
In this pattern, a publisher sends data, which is broadcast to all subscribers.
The subscribing applications only see the data to which they have subscribed.</p>
<p>The <em>SUB</em> protocol is the subscriber side, and the
<a href="proto/./pub.html"><em>PUB</em></a> protocol is the publisher side.</p>
<div class="mdbook-alerts mdbook-alerts-note">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
note
</p>
<p>The publisher delivers all messages to all subscribers.
The subscribers maintain their own subscriptions, and filter them locally.
Thus, this pattern should not be used in an attempt to
reduce bandwidth consumption.</p>
</div>
<p>The topics that subscribers subscribe to is compared to the leading bytes of
the message body.
Applications should construct their messages accordingly.</p>
<h3 id="socket-operations-8"><a class="header" href="#socket-operations-8">Socket Operations</a></h3>
<p>The <a href="proto/TODO.html"><code>nng_sub0_open</code></a> functions create a <em>SUB</em> socket.
This socket may be used to receive messages, but is unable to send them.
Attempts to send messages will result in <code>NNG_ENOTSUP</code>.</p>
<h3 id="protocol-versions-8"><a class="header" href="#protocol-versions-8">Protocol Versions</a></h3>
<p>Only version 0 of this protocol is supported.
(At the time of writing, no other versions of this protocol have been defined.)</p>
<h3 id="protocol-options-8"><a class="header" href="#protocol-options-8">Protocol Options</a></h3>
<p>The following protocol-specific option is available.</p>
<ul>
<li><a name="a004"></a><code>NNG_OPT_SUB_PREFNEW</code>: <br />
(<code>bool</code>) <br />
<br />
This read/write option specifies the behavior of the subscriber when the queue is full.
When <code>true</code> (the default), the subscriber will make room in the queue by removing the oldest message.
When <code>false</code>, the subscriber will reject messages if the message queue does not have room.</li>
</ul>
<h3 id="protocol-headers-8"><a class="header" href="#protocol-headers-8">Protocol Headers</a></h3>
<p>The <em>SUB</em> protocol has no protocol-specific headers.</p>
<div style="break-before: page; page-break-before: always;"></div><style>
.mdbook-alerts {
padding: 8px 16px;
margin-bottom: 16px;
border-left: 0.25em solid var(--mdbook-alerts-color);
}
.mdbook-alerts > *:first-child {
margin-top: 0;
}
.mdbook-alerts > *:last-child {
margin-bottom: 0;
}
.mdbook-alerts-title {
display: flex;
font-weight: 600;
align-items: center;
line-height: 1;
color: var(--mdbook-alerts-color);
text-transform: capitalize;
}
.mdbook-alerts-icon {
display: inline-block;
width: 1em;
height: 1em;
margin-right: 0.2em;
background-color: currentColor;
-webkit-mask: no-repeat center / 100%;
mask: no-repeat center / 100%;
-webkit-mask-image: var(--mdbook-alerts-icon);
mask-image: var(--mdbook-alerts-icon);
}
.mdbook-alerts-note {
--mdbook-alerts-color: rgb(9, 105, 218);
/* https://icon-sets.iconify.design/material-symbols/info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16v-4q0-.425-.288-.712T12 11q-.425 0-.712.288T11 12v4q0 .425.288.713T12 17m0-8q.425 0 .713-.288T13 8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8q0 .425.288.713T12 9m0 13q-2.075 0-3.9-.788t-3.175-2.137q-1.35-1.35-2.137-3.175T2 12q0-2.075.788-3.9t2.137-3.175q1.35-1.35 3.175-2.137T12 2q2.075 0 3.9.788t3.175 2.137q1.35 1.35 2.138 3.175T22 12q0 2.075-.788 3.9t-2.137 3.175q-1.35 1.35-3.175 2.138T12 22m0-2q3.35 0 5.675-2.325T20 12q0-3.35-2.325-5.675T12 4Q8.65 4 6.325 6.325T4 12q0 3.35 2.325 5.675T12 20m0-8"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-tip {
--mdbook-alerts-color: rgb(26, 127, 55);
/* https://icon-sets.iconify.design/material-symbols/lightbulb-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 22q-.825 0-1.412-.587T10 20h4q0 .825-.587 1.413T12 22m-3-3q-.425 0-.712-.288T8 18q0-.425.288-.712T9 17h6q.425 0 .713.288T16 18q0 .425-.288.713T15 19zm-.75-3q-1.725-1.025-2.738-2.75T4.5 9.5q0-3.125 2.188-5.312T12 2q3.125 0 5.313 2.188T19.5 9.5q0 2.025-1.012 3.75T15.75 16zm.6-2h6.3q1.125-.8 1.738-1.975T17.5 9.5q0-2.3-1.6-3.9T12 4Q9.7 4 8.1 5.6T6.5 9.5q0 1.35.613 2.525T8.85 14M12 14"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-important {
--mdbook-alerts-color: rgb(130, 80, 223);
/* https://icon-sets.iconify.design/material-symbols/chat-info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 7q.425 0 .713-.288T13 6q0-.425-.288-.712T12 5q-.425 0-.712.288T11 6q0 .425.288.713T12 7m0 8q.425 0 .713-.288T13 14v-4q0-.425-.288-.712T12 9q-.425 0-.712.288T11 10v4q0 .425.288.713T12 15m-6 3l-2.3 2.3q-.475.475-1.088.213T2 19.575V4q0-.825.588-1.412T4 2h16q.825 0 1.413.588T22 4v12q0 .825-.587 1.413T20 18zm-.85-2H20V4H4v13.125zM4 16V4z"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-warning {
--mdbook-alerts-color: rgb(154, 103, 0);
/* https://icon-sets.iconify.design/material-symbols/warning-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M2.725 21q-.275 0-.5-.137t-.35-.363q-.125-.225-.137-.488t.137-.512l9.25-16q.15-.25.388-.375T12 3q.25 0 .488.125t.387.375l9.25 16q.15.25.138.513t-.138.487q-.125.225-.35.363t-.5.137zm1.725-2h15.1L12 6zM12 18q.425 0 .713-.288T13 17q0-.425-.288-.712T12 16q-.425 0-.712.288T11 17q0 .425.288.713T12 18m0-3q.425 0 .713-.288T13 14v-3q0-.425-.288-.712T12 10q-.425 0-.712.288T11 11v3q0 .425.288.713T12 15m0-2.5"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-caution {
--mdbook-alerts-color: rgb(207, 34, 46);
/* https://icon-sets.iconify.design/material-symbols/brightness-alert-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16q0-.425-.288-.712T12 15q-.425 0-.712.288T11 16q0 .425.288.713T12 17m0-4q.425 0 .713-.288T13 12V8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8v4q0 .425.288.713T12 13m-3.35 7H6q-.825 0-1.412-.587T4 18v-2.65L2.075 13.4q-.275-.3-.425-.662T1.5 12q0-.375.15-.737t.425-.663L4 8.65V6q0-.825.588-1.412T6 4h2.65l1.95-1.925q.3-.275.663-.425T12 1.5q.375 0 .738.15t.662.425L15.35 4H18q.825 0 1.413.588T20 6v2.65l1.925 1.95q.275.3.425.663t.15.737q0 .375-.15.738t-.425.662L20 15.35V18q0 .825-.587 1.413T18 20h-2.65l-1.95 1.925q-.3.275-.662.425T12 22.5q-.375 0-.737-.15t-.663-.425zm.85-2l2.5 2.5l2.5-2.5H18v-3.5l2.5-2.5L18 9.5V6h-3.5L12 3.5L9.5 6H6v3.5L3.5 12L6 14.5V18zm2.5-6"%2F%3E%3C%2Fsvg%3E');
}
</style>
<h1 id="surveyor-protocol"><a class="header" href="#surveyor-protocol">SURVEYOR protocol</a></h1>
<p>The <a name="a001"></a><em>SURVEYOR</em> protocol<a name="a002"></a> is one half of a <a name="a003"></a>survey pattern.
In this pattern, a surveyor sends a survey, which is broadcast to all
peer respondents.
The respondents then have a chance, but are not obliged, to reply.
The survey itself is a timed event, so that responses
received after the survey has finished are discarded.</p>
<div class="mdbook-alerts mdbook-alerts-tip">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
tip
</p>
<p>This protocol is useful in solving <a name="a004"></a>voting problems, such as
<a name="a005"></a>leader election in cluster configurations,
as well as certain kinds of <a name="a006"></a>service discovery problems.</p>
</div>
<p>The <em>SURVEYOR</em> protocol is the surveyor side, and the
<a href="proto/./respondent.html"><em>RESPONDENT</em></a> protocol is the respondent side.</p>
<h3 id="socket-operations-9"><a class="header" href="#socket-operations-9">Socket Operations</a></h3>
<p>The <a href="proto/TODO.html"><code>nng_surveyor0_open</code></a>
functions create a surveyor socket.
This socket may be used to send messages (surveys), and then to receive replies.
A reply can only be received after sending a survey.
A surveyor can normally expect to receive at most one reply from each responder.
(Messages can be duplicated in some topologies,
so there is no guarantee of this.)</p>
<p>Attempts to receive on a socket with no outstanding survey will result
in <code>NNG_ESTATE</code>.
If the survey times out while the surveyor is waiting
for replies, then the result will be <code>NNG_ETIMEDOUT</code>.</p>
<p>Only one survey can be outstanding at a time; sending another survey will
cancel the prior one, and any responses from respondents from the prior
survey that arrive after this will be discarded.</p>
<p><a href="proto/TODO.html">Raw mode</a> sockets ignore all these restrictions.</p>
<h3 id="context-operations-3"><a class="header" href="#context-operations-3">Context Operations</a></h3>
<p>This protocol supports the creation of <a href="proto/TODO.html">contexts</a> for concurrent
use cases using <a href="proto/TODO.html"><code>nng_ctx_open</code></a>.</p>
<p>Each context can initiate its own surveys, and it will receive only
responses to its own outstanding surveys.
Other contexts on the same socket may have overlapping surveys
operating at the same time.</p>
<p>Each of these may have their own timeouts established with
<code>NNG_OPT_SURVEYOR_SURVEYTIME</code>.</p>
<p>Additionally, sending a survey on a context will only cancel an outstanding
survey on the same context.</p>
<div class="mdbook-alerts mdbook-alerts-note">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
note
</p>
<p>Due to the best-effort nature of this protocol, if too may contexts
are attempting to perform surveys simultaneously, it is possible for either
individual outgoing surveys or incoming responses to be lost.</p>
</div>
<h3 id="protocol-versions-9"><a class="header" href="#protocol-versions-9">Protocol Versions</a></h3>
<p>Only version 0 of this protocol is supported.
At the time of writing, no other versions of this protocol have been defined.
<sup><a name="to-footnote-1"><a href="proto/surveyor.html#footnote-1">1</a></a></sup></p>
<h3 id="protocol-options-9"><a class="header" href="#protocol-options-9">Protocol Options</a></h3>
<p>The following protocol-specific option is available.</p>
<ul>
<li><a name="a007"></a><code>NNG_OPT_SURVEYOR_SURVEYTIME</code>: <br />
(<a href="proto/../api/util/nng_duration.html"><code>nng_duration</code></a>) <br />
<br />
When a new survey is started, a timer of this duration is started.
Any responses arriving this time will be discarded.
Attempts to receive
after the timer expires with no other surveys started will result in
<code>NNG_ESTATE</code>.<br />
<br />
If a receive is pending when this timer expires, it will result in
<code>NNG_ETIMEDOUT</code>.</li>
</ul>
<h3 id="protocol-headers-9"><a class="header" href="#protocol-headers-9">Protocol Headers</a></h3>
<p><a name="a008"></a>
This form uses a stack of 32-bit big-endian identifiers.
There <em>must</em> be at least one identifier, the <strong>survey ID</strong>, which will be the
last element in the array, and <em>must</em> have the most significant bit set.</p>
<p>There may be additional <strong>peer ID</strong>s preceding the survey ID.
These will be distinguishable from the survey ID by having their most
significant bit clear.</p>
<p>When a survey message is received by a forwarding node (such as a
<a href="proto/TODO.html">device</a>),
the forwarding node prepends a
32-bit peer ID (which <em>must</em> have the most significant bit clear),
which is the forwarder’s way of identifying the directly connected
peer from which it received the message.
(This peer ID, except for the
most significant bit, has meaning only to the forwarding node itself.)</p>
<p>It may help to think of prepending a peer ID as pushing a peer ID onto the
front of the stack of headers for the message.
(It will use the peer ID
it popped from the front to determine the next intermediate destination
for the response.)</p>
<p>When a response message is created, it is created using the same headers
that the survey contained.</p>
<p>A forwarding node can pop the peer ID it originally pushed on the
message, stripping it from the front of the message as it does so.</p>
<p>When the response finally arrives back at the initiating surveyor, it
should have only a single element in the message, which will be the
survey ID it originally used for the request.</p>
<p>More detail can be found in the <a href="proto/TODO.html">sp-surveyor-01 RFC</a> document.</p>
<p><hr/>
<p><a name="footnote-1"><a href="proto/surveyor.html#to-footnote-1">1</a></a>: An earlier and incompatible version of the protocol was used in older
pre-releases of <a href="proto/TODO.html">nanomsg</a>, but was not released in any production version.</p>
<div style="break-before: page; page-break-before: always;"></div><style>
.mdbook-alerts {
padding: 8px 16px;
margin-bottom: 16px;
border-left: 0.25em solid var(--mdbook-alerts-color);
}
.mdbook-alerts > *:first-child {
margin-top: 0;
}
.mdbook-alerts > *:last-child {
margin-bottom: 0;
}
.mdbook-alerts-title {
display: flex;
font-weight: 600;
align-items: center;
line-height: 1;
color: var(--mdbook-alerts-color);
text-transform: capitalize;
}
.mdbook-alerts-icon {
display: inline-block;
width: 1em;
height: 1em;
margin-right: 0.2em;
background-color: currentColor;
-webkit-mask: no-repeat center / 100%;
mask: no-repeat center / 100%;
-webkit-mask-image: var(--mdbook-alerts-icon);
mask-image: var(--mdbook-alerts-icon);
}
.mdbook-alerts-note {
--mdbook-alerts-color: rgb(9, 105, 218);
/* https://icon-sets.iconify.design/material-symbols/info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16v-4q0-.425-.288-.712T12 11q-.425 0-.712.288T11 12v4q0 .425.288.713T12 17m0-8q.425 0 .713-.288T13 8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8q0 .425.288.713T12 9m0 13q-2.075 0-3.9-.788t-3.175-2.137q-1.35-1.35-2.137-3.175T2 12q0-2.075.788-3.9t2.137-3.175q1.35-1.35 3.175-2.137T12 2q2.075 0 3.9.788t3.175 2.137q1.35 1.35 2.138 3.175T22 12q0 2.075-.788 3.9t-2.137 3.175q-1.35 1.35-3.175 2.138T12 22m0-2q3.35 0 5.675-2.325T20 12q0-3.35-2.325-5.675T12 4Q8.65 4 6.325 6.325T4 12q0 3.35 2.325 5.675T12 20m0-8"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-tip {
--mdbook-alerts-color: rgb(26, 127, 55);
/* https://icon-sets.iconify.design/material-symbols/lightbulb-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 22q-.825 0-1.412-.587T10 20h4q0 .825-.587 1.413T12 22m-3-3q-.425 0-.712-.288T8 18q0-.425.288-.712T9 17h6q.425 0 .713.288T16 18q0 .425-.288.713T15 19zm-.75-3q-1.725-1.025-2.738-2.75T4.5 9.5q0-3.125 2.188-5.312T12 2q3.125 0 5.313 2.188T19.5 9.5q0 2.025-1.012 3.75T15.75 16zm.6-2h6.3q1.125-.8 1.738-1.975T17.5 9.5q0-2.3-1.6-3.9T12 4Q9.7 4 8.1 5.6T6.5 9.5q0 1.35.613 2.525T8.85 14M12 14"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-important {
--mdbook-alerts-color: rgb(130, 80, 223);
/* https://icon-sets.iconify.design/material-symbols/chat-info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 7q.425 0 .713-.288T13 6q0-.425-.288-.712T12 5q-.425 0-.712.288T11 6q0 .425.288.713T12 7m0 8q.425 0 .713-.288T13 14v-4q0-.425-.288-.712T12 9q-.425 0-.712.288T11 10v4q0 .425.288.713T12 15m-6 3l-2.3 2.3q-.475.475-1.088.213T2 19.575V4q0-.825.588-1.412T4 2h16q.825 0 1.413.588T22 4v12q0 .825-.587 1.413T20 18zm-.85-2H20V4H4v13.125zM4 16V4z"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-warning {
--mdbook-alerts-color: rgb(154, 103, 0);
/* https://icon-sets.iconify.design/material-symbols/warning-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M2.725 21q-.275 0-.5-.137t-.35-.363q-.125-.225-.137-.488t.137-.512l9.25-16q.15-.25.388-.375T12 3q.25 0 .488.125t.387.375l9.25 16q.15.25.138.513t-.138.487q-.125.225-.35.363t-.5.137zm1.725-2h15.1L12 6zM12 18q.425 0 .713-.288T13 17q0-.425-.288-.712T12 16q-.425 0-.712.288T11 17q0 .425.288.713T12 18m0-3q.425 0 .713-.288T13 14v-3q0-.425-.288-.712T12 10q-.425 0-.712.288T11 11v3q0 .425.288.713T12 15m0-2.5"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-caution {
--mdbook-alerts-color: rgb(207, 34, 46);
/* https://icon-sets.iconify.design/material-symbols/brightness-alert-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16q0-.425-.288-.712T12 15q-.425 0-.712.288T11 16q0 .425.288.713T12 17m0-4q.425 0 .713-.288T13 12V8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8v4q0 .425.288.713T12 13m-3.35 7H6q-.825 0-1.412-.587T4 18v-2.65L2.075 13.4q-.275-.3-.425-.662T1.5 12q0-.375.15-.737t.425-.663L4 8.65V6q0-.825.588-1.412T6 4h2.65l1.95-1.925q.3-.275.663-.425T12 1.5q.375 0 .738.15t.662.425L15.35 4H18q.825 0 1.413.588T20 6v2.65l1.925 1.95q.275.3.425.663t.15.737q0 .375-.15.738t-.425.662L20 15.35V18q0 .825-.587 1.413T18 20h-2.65l-1.95 1.925q-.3.275-.662.425T12 22.5q-.375 0-.737-.15t-.663-.425zm.85-2l2.5 2.5l2.5-2.5H18v-3.5l2.5-2.5L18 9.5V6h-3.5L12 3.5L9.5 6H6v3.5L3.5 12L6 14.5V18zm2.5-6"%2F%3E%3C%2Fsvg%3E');
}
</style>
<h1 id="transports"><a class="header" href="#transports">Transports</a></h1>
<p>This section documents transports for Scalabity Protocols implemented by NNG.</p>
<ul>
<li><a href="tran/socket.html">BSD Socket</a></li>
<li><a href="tran/inproc.html">Intra-Process Transport</a></li>
<li><a href="tran/udp.html">UDP</a></li>
</ul>
<div style="break-before: page; page-break-before: always;"></div><style>
.mdbook-alerts {
padding: 8px 16px;
margin-bottom: 16px;
border-left: 0.25em solid var(--mdbook-alerts-color);
}
.mdbook-alerts > *:first-child {
margin-top: 0;
}
.mdbook-alerts > *:last-child {
margin-bottom: 0;
}
.mdbook-alerts-title {
display: flex;
font-weight: 600;
align-items: center;
line-height: 1;
color: var(--mdbook-alerts-color);
text-transform: capitalize;
}
.mdbook-alerts-icon {
display: inline-block;
width: 1em;
height: 1em;
margin-right: 0.2em;
background-color: currentColor;
-webkit-mask: no-repeat center / 100%;
mask: no-repeat center / 100%;
-webkit-mask-image: var(--mdbook-alerts-icon);
mask-image: var(--mdbook-alerts-icon);
}
.mdbook-alerts-note {
--mdbook-alerts-color: rgb(9, 105, 218);
/* https://icon-sets.iconify.design/material-symbols/info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16v-4q0-.425-.288-.712T12 11q-.425 0-.712.288T11 12v4q0 .425.288.713T12 17m0-8q.425 0 .713-.288T13 8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8q0 .425.288.713T12 9m0 13q-2.075 0-3.9-.788t-3.175-2.137q-1.35-1.35-2.137-3.175T2 12q0-2.075.788-3.9t2.137-3.175q1.35-1.35 3.175-2.137T12 2q2.075 0 3.9.788t3.175 2.137q1.35 1.35 2.138 3.175T22 12q0 2.075-.788 3.9t-2.137 3.175q-1.35 1.35-3.175 2.138T12 22m0-2q3.35 0 5.675-2.325T20 12q0-3.35-2.325-5.675T12 4Q8.65 4 6.325 6.325T4 12q0 3.35 2.325 5.675T12 20m0-8"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-tip {
--mdbook-alerts-color: rgb(26, 127, 55);
/* https://icon-sets.iconify.design/material-symbols/lightbulb-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 22q-.825 0-1.412-.587T10 20h4q0 .825-.587 1.413T12 22m-3-3q-.425 0-.712-.288T8 18q0-.425.288-.712T9 17h6q.425 0 .713.288T16 18q0 .425-.288.713T15 19zm-.75-3q-1.725-1.025-2.738-2.75T4.5 9.5q0-3.125 2.188-5.312T12 2q3.125 0 5.313 2.188T19.5 9.5q0 2.025-1.012 3.75T15.75 16zm.6-2h6.3q1.125-.8 1.738-1.975T17.5 9.5q0-2.3-1.6-3.9T12 4Q9.7 4 8.1 5.6T6.5 9.5q0 1.35.613 2.525T8.85 14M12 14"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-important {
--mdbook-alerts-color: rgb(130, 80, 223);
/* https://icon-sets.iconify.design/material-symbols/chat-info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 7q.425 0 .713-.288T13 6q0-.425-.288-.712T12 5q-.425 0-.712.288T11 6q0 .425.288.713T12 7m0 8q.425 0 .713-.288T13 14v-4q0-.425-.288-.712T12 9q-.425 0-.712.288T11 10v4q0 .425.288.713T12 15m-6 3l-2.3 2.3q-.475.475-1.088.213T2 19.575V4q0-.825.588-1.412T4 2h16q.825 0 1.413.588T22 4v12q0 .825-.587 1.413T20 18zm-.85-2H20V4H4v13.125zM4 16V4z"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-warning {
--mdbook-alerts-color: rgb(154, 103, 0);
/* https://icon-sets.iconify.design/material-symbols/warning-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M2.725 21q-.275 0-.5-.137t-.35-.363q-.125-.225-.137-.488t.137-.512l9.25-16q.15-.25.388-.375T12 3q.25 0 .488.125t.387.375l9.25 16q.15.25.138.513t-.138.487q-.125.225-.35.363t-.5.137zm1.725-2h15.1L12 6zM12 18q.425 0 .713-.288T13 17q0-.425-.288-.712T12 16q-.425 0-.712.288T11 17q0 .425.288.713T12 18m0-3q.425 0 .713-.288T13 14v-3q0-.425-.288-.712T12 10q-.425 0-.712.288T11 11v3q0 .425.288.713T12 15m0-2.5"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-caution {
--mdbook-alerts-color: rgb(207, 34, 46);
/* https://icon-sets.iconify.design/material-symbols/brightness-alert-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16q0-.425-.288-.712T12 15q-.425 0-.712.288T11 16q0 .425.288.713T12 17m0-4q.425 0 .713-.288T13 12V8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8v4q0 .425.288.713T12 13m-3.35 7H6q-.825 0-1.412-.587T4 18v-2.65L2.075 13.4q-.275-.3-.425-.662T1.5 12q0-.375.15-.737t.425-.663L4 8.65V6q0-.825.588-1.412T6 4h2.65l1.95-1.925q.3-.275.663-.425T12 1.5q.375 0 .738.15t.662.425L15.35 4H18q.825 0 1.413.588T20 6v2.65l1.925 1.95q.275.3.425.663t.15.737q0 .375-.15.738t-.425.662L20 15.35V18q0 .825-.587 1.413T18 20h-2.65l-1.95 1.925q-.3.275-.662.425T12 22.5q-.375 0-.737-.15t-.663-.425zm.85-2l2.5 2.5l2.5-2.5H18v-3.5l2.5-2.5L18 9.5V6h-3.5L12 3.5L9.5 6H6v3.5L3.5 12L6 14.5V18zm2.5-6"%2F%3E%3C%2Fsvg%3E');
}
</style>
<h1 id="inproc-transport"><a class="header" href="#inproc-transport">INPROC Transport</a></h1>
<p>The <a name="a001"></a><em>inproc</em> transport<a name="a002"></a><a name="a003"></a>intra-process provides communication support between
sockets within the same process.
This may be used as an alternative
to slower transports when data must be moved within the same process.</p>
<p>This transport tries hard to avoid copying data, and thus is very
light-weight.</p>
<h2 id="uri-format"><a class="header" href="#uri-format">URI Format</a></h2>
<p>This transport uses URIs using the scheme <a name="a004"></a><code>inproc://</code>, followed by
an arbitrary string of text, terminated by a <code>NUL</code> byte.</p>
<p>Multiple URIs can be used within the
same application, and they will not interfere with one another.</p>
<p>Two applications may also use the same URI without interfering with each
other, and they will be unable to communicate with each other using
that URI.</p>
<h2 id="socket-address"><a class="header" href="#socket-address">Socket Address</a></h2>
<p>When using an <a href="tran/TODO.html"><code>nng_sockaddr</code></a> structure,
the actual structure is of type
<a href="tran/TODO.html"><code>nng_sockaddr_inproc</code></a>.</p>
<h2 id="transport-options"><a class="header" href="#transport-options">Transport Options</a></h2>
<p>The <em>inproc</em> transport has no special options.</p>
<div class="mdbook-alerts mdbook-alerts-note">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
note
</p>
<p>While <em>inproc</em> accepts the option <code>NNG_OPT_RECVMAXSZ</code> for
compatibility, the value of the option is ignored with no enforcement.
As <em>inproc</em> peers are in the same address space, they are implicitly
trusted, so the protection afforded by <code>NNG_OPT_RECVMAXSZ</code> is unnecessary.</p>
</div>
<h2 id="mixing-implementations"><a class="header" href="#mixing-implementations">Mixing Implementations</a></h2>
<p>When mixing the <em>NNG</em> library with other implementations of these
protocols in the same process (such as the <em>mangos</em>
or <em>libnanomsg</em> implementations), it will not be possible to utilize
the <em>inproc</em> transport to communicate across this boundary.</p>
<p>This limitation also extends to using different instances of the <em>NNG</em>
library within the same process.</p>
<div style="break-before: page; page-break-before: always;"></div><style>
.mdbook-alerts {
padding: 8px 16px;
margin-bottom: 16px;
border-left: 0.25em solid var(--mdbook-alerts-color);
}
.mdbook-alerts > *:first-child {
margin-top: 0;
}
.mdbook-alerts > *:last-child {
margin-bottom: 0;
}
.mdbook-alerts-title {
display: flex;
font-weight: 600;
align-items: center;
line-height: 1;
color: var(--mdbook-alerts-color);
text-transform: capitalize;
}
.mdbook-alerts-icon {
display: inline-block;
width: 1em;
height: 1em;
margin-right: 0.2em;
background-color: currentColor;
-webkit-mask: no-repeat center / 100%;
mask: no-repeat center / 100%;
-webkit-mask-image: var(--mdbook-alerts-icon);
mask-image: var(--mdbook-alerts-icon);
}
.mdbook-alerts-note {
--mdbook-alerts-color: rgb(9, 105, 218);
/* https://icon-sets.iconify.design/material-symbols/info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16v-4q0-.425-.288-.712T12 11q-.425 0-.712.288T11 12v4q0 .425.288.713T12 17m0-8q.425 0 .713-.288T13 8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8q0 .425.288.713T12 9m0 13q-2.075 0-3.9-.788t-3.175-2.137q-1.35-1.35-2.137-3.175T2 12q0-2.075.788-3.9t2.137-3.175q1.35-1.35 3.175-2.137T12 2q2.075 0 3.9.788t3.175 2.137q1.35 1.35 2.138 3.175T22 12q0 2.075-.788 3.9t-2.137 3.175q-1.35 1.35-3.175 2.138T12 22m0-2q3.35 0 5.675-2.325T20 12q0-3.35-2.325-5.675T12 4Q8.65 4 6.325 6.325T4 12q0 3.35 2.325 5.675T12 20m0-8"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-tip {
--mdbook-alerts-color: rgb(26, 127, 55);
/* https://icon-sets.iconify.design/material-symbols/lightbulb-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 22q-.825 0-1.412-.587T10 20h4q0 .825-.587 1.413T12 22m-3-3q-.425 0-.712-.288T8 18q0-.425.288-.712T9 17h6q.425 0 .713.288T16 18q0 .425-.288.713T15 19zm-.75-3q-1.725-1.025-2.738-2.75T4.5 9.5q0-3.125 2.188-5.312T12 2q3.125 0 5.313 2.188T19.5 9.5q0 2.025-1.012 3.75T15.75 16zm.6-2h6.3q1.125-.8 1.738-1.975T17.5 9.5q0-2.3-1.6-3.9T12 4Q9.7 4 8.1 5.6T6.5 9.5q0 1.35.613 2.525T8.85 14M12 14"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-important {
--mdbook-alerts-color: rgb(130, 80, 223);
/* https://icon-sets.iconify.design/material-symbols/chat-info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 7q.425 0 .713-.288T13 6q0-.425-.288-.712T12 5q-.425 0-.712.288T11 6q0 .425.288.713T12 7m0 8q.425 0 .713-.288T13 14v-4q0-.425-.288-.712T12 9q-.425 0-.712.288T11 10v4q0 .425.288.713T12 15m-6 3l-2.3 2.3q-.475.475-1.088.213T2 19.575V4q0-.825.588-1.412T4 2h16q.825 0 1.413.588T22 4v12q0 .825-.587 1.413T20 18zm-.85-2H20V4H4v13.125zM4 16V4z"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-warning {
--mdbook-alerts-color: rgb(154, 103, 0);
/* https://icon-sets.iconify.design/material-symbols/warning-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M2.725 21q-.275 0-.5-.137t-.35-.363q-.125-.225-.137-.488t.137-.512l9.25-16q.15-.25.388-.375T12 3q.25 0 .488.125t.387.375l9.25 16q.15.25.138.513t-.138.487q-.125.225-.35.363t-.5.137zm1.725-2h15.1L12 6zM12 18q.425 0 .713-.288T13 17q0-.425-.288-.712T12 16q-.425 0-.712.288T11 17q0 .425.288.713T12 18m0-3q.425 0 .713-.288T13 14v-3q0-.425-.288-.712T12 10q-.425 0-.712.288T11 11v3q0 .425.288.713T12 15m0-2.5"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-caution {
--mdbook-alerts-color: rgb(207, 34, 46);
/* https://icon-sets.iconify.design/material-symbols/brightness-alert-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16q0-.425-.288-.712T12 15q-.425 0-.712.288T11 16q0 .425.288.713T12 17m0-4q.425 0 .713-.288T13 12V8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8v4q0 .425.288.713T12 13m-3.35 7H6q-.825 0-1.412-.587T4 18v-2.65L2.075 13.4q-.275-.3-.425-.662T1.5 12q0-.375.15-.737t.425-.663L4 8.65V6q0-.825.588-1.412T6 4h2.65l1.95-1.925q.3-.275.663-.425T12 1.5q.375 0 .738.15t.662.425L15.35 4H18q.825 0 1.413.588T20 6v2.65l1.925 1.95q.275.3.425.663t.15.737q0 .375-.15.738t-.425.662L20 15.35V18q0 .825-.587 1.413T18 20h-2.65l-1.95 1.925q-.3.275-.662.425T12 22.5q-.375 0-.737-.15t-.663-.425zm.85-2l2.5 2.5l2.5-2.5H18v-3.5l2.5-2.5L18 9.5V6h-3.5L12 3.5L9.5 6H6v3.5L3.5 12L6 14.5V18zm2.5-6"%2F%3E%3C%2Fsvg%3E');
}
</style>
<h1 id="ipc-transport"><a class="header" href="#ipc-transport">IPC Transport</a></h1>
<h2 id="description-1"><a class="header" href="#description-1">DESCRIPTION</a></h2>
<p>The <a name="a001"></a><em>ipc</em> transport<a name="a002"></a> provides communication support between
sockets within different processes on the same host.
For POSIX platforms, this is implemented using <a name="a003"></a>UNIX domain sockets.
For Windows, this is implemented using Windows <a name="a004"></a>named pipes.
Other platforms may have different implementation strategies.</p>
<h3 id="uri-formats"><a class="header" href="#uri-formats">URI Formats</a></h3>
<h4 id="traditional-names"><a class="header" href="#traditional-names">Traditional Names</a></h4>
<p>This transport uses URIs using the scheme <a name="a005"></a><code>ipc://</code>, followed by a path
name in the file system where the socket or named pipe should be created.</p>
<div class="mdbook-alerts mdbook-alerts-tip">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
tip
</p>
<p>On Windows, all names are prefixed by <code>\\.\pipe\</code> and do not
reside in the normal file system.
On POSIX platforms, the path is taken literally, and is relative to
the current directory, unless it begins with <code>/</code>, in which case it is
relative to the root directory.</p>
</div>
<div class="mdbook-alerts mdbook-alerts-note">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
note
</p>
<p>When using relative paths on POSIX systems, the address used and returned
in properties like <code>NNG_OPT_LOCADDR</code> will also be relative.
Consequently, they will only be interpreted the same by processes that have
the same working directory.
To ensure maximum portability and safety, absolute paths are recommended
whenever possible.</p>
</div>
<div class="mdbook-alerts mdbook-alerts-note">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
note
</p>
<p>If compatibility with legacy <em>nanomsg</em> applications is required,
then path names must not be longer than 122 bytes, including the final
<code>NUL</code> byte.
This is because legacy versions of <em>nanomsg</em> cannot express URLs
longer than 128 bytes, including the <code>ipc://</code> prefix.</p>
</div>
<h4 id="unix-aliases"><a class="header" href="#unix-aliases">UNIX Aliases</a></h4>
<p>The <a name="a006"></a><code>unix://</code> scheme is an alias for <code>ipc://</code> and can be used inter-changeably, but only on POSIX systems.
<sup><a name="to-footnote-1"><a href="tran/ipc.html#footnote-1">1</a></a></sup></p>
<h4 id="abstract-names"><a class="header" href="#abstract-names">Abstract Names</a></h4>
<p>On Linux, this transport also can support <a name="a007"></a>abstract sockets.
Abstract sockets use a URI-encoded name after the <a name="a008"></a><code>abstract://</code> scheme, which allows arbitrary values to be conveyed
in the path, including embedded <code>NUL</code> bytes.
For example, the name <code>"a\0b"</code> would be represented as <code>abstract://a%00b</code>.</p>
<div class="mdbook-alerts mdbook-alerts-tip">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
tip
</p>
<p>An empty name may be used with a listener to request “auto bind” be used to select a name.
In this case the system will allocate a free name.
The name assigned may be retrieved using <a href="tran/TODO.html"><a name="a009"></a><code>NNG_OPT_LOCADDR</code></a>.</p>
</div>
<p>Abstract names do not include the leading <code>NUL</code> byte used in the low-level socket address.</p>
<p>Abstract sockets do not have any representation in the file system, and are automatically freed by
the system when no longer in use.</p>
<p>Abstract sockets ignore socket permissions, but it is still possible to determine the credentials
of the peer with <a href="tran/TODO.html"><a name="a010"></a><code>NNG_OPT_PEER_UID</code></a>, and similar options.
<sup><a name="to-footnote-2"><a href="tran/ipc.html#footnote-2">2</a></a></sup></p>
<h3 id="socket-address-1"><a class="header" href="#socket-address-1">Socket Address</a></h3>
<p>When using an <a href="tran/TODO.html"><code>nng_sockaddr</code></a> structure,
the actual structure is of type <a href="tran/TODO.html"><code>nng_sockaddr_ipc</code></a>,
except for abstract sockets, which use <a href="tran/TODO.html"><code>nng_sockaddr_abstract</code></a>.</p>
<h3 id="transport-options-1"><a class="header" href="#transport-options-1">Transport Options</a></h3>
<p>The following transport options are supported by this transport,
where supported by the underlying platform.</p>
<ul>
<li><a href="tran/TODO.html"><code>NNG_OPT_IPC_PERMISSIONS</code></a></li>
<li><a href="tran/TODO.html"><code>NNG_OPT_IPC_SECURITY_DESCRIPTOR</code></a></li>
<li><a href="tran/TODO.html"><code>NNG_OPT_LOCADDR</code></a></li>
<li><a href="tran/TODO.html"><code>NNG_OPT_REMADDR</code></a></li>
<li><a href="tran/TODO.html"><code>NNG_OPT_PEER_GID</code></a></li>
<li><a href="tran/TODO.html"><code>NNG_OPT_PEER_PID</code></a></li>
<li><a href="tran/TODO.html"><code>NNG_OPT_PEER_UID</code></a></li>
<li><a href="tran/TODO.html"><code>NNG_OPT_PEER_ZONEID</code></a></li>
</ul>
<p><hr/>
<p><a name="footnote-1"><a href="tran/ipc.html#to-footnote-1">1</a></a>: The purpose of this scheme is to support a future transport making use of <code>AF_UNIX</code>
on Windows systems, at which time it will be necessary to discriminate between the Named Pipes and the <code>AF_UNIX</code> based transports.</p>
<p><a name="footnote-2"><a href="tran/ipc.html#to-footnote-2">2</a></a>: This property makes it important that names be chosen randomly to
prevent unauthorized access, or that checks against the peer credentials are made, or ideally, both.</p>
<div style="break-before: page; page-break-before: always;"></div><style>
.mdbook-alerts {
padding: 8px 16px;
margin-bottom: 16px;
border-left: 0.25em solid var(--mdbook-alerts-color);
}
.mdbook-alerts > *:first-child {
margin-top: 0;
}
.mdbook-alerts > *:last-child {
margin-bottom: 0;
}
.mdbook-alerts-title {
display: flex;
font-weight: 600;
align-items: center;
line-height: 1;
color: var(--mdbook-alerts-color);
text-transform: capitalize;
}
.mdbook-alerts-icon {
display: inline-block;
width: 1em;
height: 1em;
margin-right: 0.2em;
background-color: currentColor;
-webkit-mask: no-repeat center / 100%;
mask: no-repeat center / 100%;
-webkit-mask-image: var(--mdbook-alerts-icon);
mask-image: var(--mdbook-alerts-icon);
}
.mdbook-alerts-note {
--mdbook-alerts-color: rgb(9, 105, 218);
/* https://icon-sets.iconify.design/material-symbols/info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16v-4q0-.425-.288-.712T12 11q-.425 0-.712.288T11 12v4q0 .425.288.713T12 17m0-8q.425 0 .713-.288T13 8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8q0 .425.288.713T12 9m0 13q-2.075 0-3.9-.788t-3.175-2.137q-1.35-1.35-2.137-3.175T2 12q0-2.075.788-3.9t2.137-3.175q1.35-1.35 3.175-2.137T12 2q2.075 0 3.9.788t3.175 2.137q1.35 1.35 2.138 3.175T22 12q0 2.075-.788 3.9t-2.137 3.175q-1.35 1.35-3.175 2.138T12 22m0-2q3.35 0 5.675-2.325T20 12q0-3.35-2.325-5.675T12 4Q8.65 4 6.325 6.325T4 12q0 3.35 2.325 5.675T12 20m0-8"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-tip {
--mdbook-alerts-color: rgb(26, 127, 55);
/* https://icon-sets.iconify.design/material-symbols/lightbulb-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 22q-.825 0-1.412-.587T10 20h4q0 .825-.587 1.413T12 22m-3-3q-.425 0-.712-.288T8 18q0-.425.288-.712T9 17h6q.425 0 .713.288T16 18q0 .425-.288.713T15 19zm-.75-3q-1.725-1.025-2.738-2.75T4.5 9.5q0-3.125 2.188-5.312T12 2q3.125 0 5.313 2.188T19.5 9.5q0 2.025-1.012 3.75T15.75 16zm.6-2h6.3q1.125-.8 1.738-1.975T17.5 9.5q0-2.3-1.6-3.9T12 4Q9.7 4 8.1 5.6T6.5 9.5q0 1.35.613 2.525T8.85 14M12 14"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-important {
--mdbook-alerts-color: rgb(130, 80, 223);
/* https://icon-sets.iconify.design/material-symbols/chat-info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 7q.425 0 .713-.288T13 6q0-.425-.288-.712T12 5q-.425 0-.712.288T11 6q0 .425.288.713T12 7m0 8q.425 0 .713-.288T13 14v-4q0-.425-.288-.712T12 9q-.425 0-.712.288T11 10v4q0 .425.288.713T12 15m-6 3l-2.3 2.3q-.475.475-1.088.213T2 19.575V4q0-.825.588-1.412T4 2h16q.825 0 1.413.588T22 4v12q0 .825-.587 1.413T20 18zm-.85-2H20V4H4v13.125zM4 16V4z"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-warning {
--mdbook-alerts-color: rgb(154, 103, 0);
/* https://icon-sets.iconify.design/material-symbols/warning-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M2.725 21q-.275 0-.5-.137t-.35-.363q-.125-.225-.137-.488t.137-.512l9.25-16q.15-.25.388-.375T12 3q.25 0 .488.125t.387.375l9.25 16q.15.25.138.513t-.138.487q-.125.225-.35.363t-.5.137zm1.725-2h15.1L12 6zM12 18q.425 0 .713-.288T13 17q0-.425-.288-.712T12 16q-.425 0-.712.288T11 17q0 .425.288.713T12 18m0-3q.425 0 .713-.288T13 14v-3q0-.425-.288-.712T12 10q-.425 0-.712.288T11 11v3q0 .425.288.713T12 15m0-2.5"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-caution {
--mdbook-alerts-color: rgb(207, 34, 46);
/* https://icon-sets.iconify.design/material-symbols/brightness-alert-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16q0-.425-.288-.712T12 15q-.425 0-.712.288T11 16q0 .425.288.713T12 17m0-4q.425 0 .713-.288T13 12V8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8v4q0 .425.288.713T12 13m-3.35 7H6q-.825 0-1.412-.587T4 18v-2.65L2.075 13.4q-.275-.3-.425-.662T1.5 12q0-.375.15-.737t.425-.663L4 8.65V6q0-.825.588-1.412T6 4h2.65l1.95-1.925q.3-.275.663-.425T12 1.5q.375 0 .738.15t.662.425L15.35 4H18q.825 0 1.413.588T20 6v2.65l1.925 1.95q.275.3.425.663t.15.737q0 .375-.15.738t-.425.662L20 15.35V18q0 .825-.587 1.413T18 20h-2.65l-1.95 1.925q-.3.275-.662.425T12 22.5q-.375 0-.737-.15t-.663-.425zm.85-2l2.5 2.5l2.5-2.5H18v-3.5l2.5-2.5L18 9.5V6h-3.5L12 3.5L9.5 6H6v3.5L3.5 12L6 14.5V18zm2.5-6"%2F%3E%3C%2Fsvg%3E');
}
</style>
<h1 id="socket-transport-experimental"><a class="header" href="#socket-transport-experimental">Socket Transport (Experimental)</a></h1>
<h2 id="description-2"><a class="header" href="#description-2">Description</a></h2>
<p>The <a name="a001"></a><em>socket</em> transport supports communication between
peers across arbitrary BSD sockets, such as those that are
created with <a href="tran/../../api/misc.html#create-socket-pair"><code>nng_socket_pair</code></a>.</p>
<p>This transport only supports <a href="tran/%5BTODO.html">listeners</a>,
using <a href="tran/%5BTODO.html"><code>nng_listener_create</code></a>.</p>
<div class="mdbook-alerts mdbook-alerts-note">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
note
</p>
<p>Attempts to create <a href="tran/%5BTODO.html">dialers</a> using this transport will result in <code>NNG_ENOTSUP</code>.</p>
</div>
<p>The socket file descriptor is passed to the listener using
the <a name="a002"></a><code>NNG_OPT_SOCKET_FD</code> option (as an integer).
Setting this option will cause the listener to create a <a href="tran/%5BTODO.html">pipe</a>
backed by the file descriptor.</p>
<p>The protocol between peers using this transport is compatible with the protocol used
for the <a href="tran/%5Btcp.html"><em>tcp</em></a> transport, but this is an implementation detail and subject to change without notice.
<sup><a name="to-footnote-1"><a href="tran/socket.html#footnote-1">1</a></a></sup></p>
<div class="mdbook-alerts mdbook-alerts-note">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
note
</p>
<p>This transport is <em>experimental</em>, and at present is only supported on POSIX platforms.
<sup><a name="to-footnote-2"><a href="tran/socket.html#footnote-2">2</a></a></sup></p>
</div>
<h2 id="registration"><a class="header" href="#registration">Registration</a></h2>
<p>No special action is necessary to register this transport.</p>
<h2 id="uri-format-1"><a class="header" href="#uri-format-1">URI Format</a></h2>
<p>This transport uses the URL <a name="a003"></a><code>socket://</code>, without further qualification.</p>
<h2 id="socket-address-2"><a class="header" href="#socket-address-2">Socket Address</a></h2>
<p>The socket address will be of family <a name="a004"></a><code>NNG_AF_UNSPEC</code>.
There are no further socket details available.</p>
<h2 id="transport-options-2"><a class="header" href="#transport-options-2">Transport Options</a></h2>
<p>The following transport option is available:</p>
<ul>
<li><a name="a005"></a><code>NNG_OPT_SOCKET_FD</code>: <br />
(int) <br />
<br />
This is a write-only option, that may be set multiple times on a listener.
Each time this is set, the listener will create a <a href="tran/%5BTODO.html">pipe</a> backed by the given file
descriptor passed as an argument.</li>
</ul>
<p>Additionally, the following options may be supported on pipes when the platform supports them:</p>
<ul>
<li><a href="tran/%5BTODO.html"><code>NNG_OPT_PEER_GID</code></a></li>
<li><a href="tran/%5BTODO.html"><code>NNG_OPT_PEER_PID</code></a></li>
<li><a href="tran/%5BTODO.html"><code>NNG_OPT_PEER_UID</code></a></li>
<li><a href="tran/%5BTODO.html"><code>NNG_OPT_PEER_ZONEID</code></a></li>
</ul>
<p><hr/>
<p><a name="footnote-1"><a href="tran/socket.html#to-footnote-1">1</a></a>: Specifically it is not compatible with the <a href="tran/%5Bipc.html"><em>ipc</em></a> transport.</p>
<p><a name="footnote-2"><a href="tran/socket.html#to-footnote-2">2</a></a>: Windows lacks a suitable <code>socketpair</code> equivalent function we could use.</p>
<div style="break-before: page; page-break-before: always;"></div><style>
.mdbook-alerts {
padding: 8px 16px;
margin-bottom: 16px;
border-left: 0.25em solid var(--mdbook-alerts-color);
}
.mdbook-alerts > *:first-child {
margin-top: 0;
}
.mdbook-alerts > *:last-child {
margin-bottom: 0;
}
.mdbook-alerts-title {
display: flex;
font-weight: 600;
align-items: center;
line-height: 1;
color: var(--mdbook-alerts-color);
text-transform: capitalize;
}
.mdbook-alerts-icon {
display: inline-block;
width: 1em;
height: 1em;
margin-right: 0.2em;
background-color: currentColor;
-webkit-mask: no-repeat center / 100%;
mask: no-repeat center / 100%;
-webkit-mask-image: var(--mdbook-alerts-icon);
mask-image: var(--mdbook-alerts-icon);
}
.mdbook-alerts-note {
--mdbook-alerts-color: rgb(9, 105, 218);
/* https://icon-sets.iconify.design/material-symbols/info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16v-4q0-.425-.288-.712T12 11q-.425 0-.712.288T11 12v4q0 .425.288.713T12 17m0-8q.425 0 .713-.288T13 8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8q0 .425.288.713T12 9m0 13q-2.075 0-3.9-.788t-3.175-2.137q-1.35-1.35-2.137-3.175T2 12q0-2.075.788-3.9t2.137-3.175q1.35-1.35 3.175-2.137T12 2q2.075 0 3.9.788t3.175 2.137q1.35 1.35 2.138 3.175T22 12q0 2.075-.788 3.9t-2.137 3.175q-1.35 1.35-3.175 2.138T12 22m0-2q3.35 0 5.675-2.325T20 12q0-3.35-2.325-5.675T12 4Q8.65 4 6.325 6.325T4 12q0 3.35 2.325 5.675T12 20m0-8"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-tip {
--mdbook-alerts-color: rgb(26, 127, 55);
/* https://icon-sets.iconify.design/material-symbols/lightbulb-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 22q-.825 0-1.412-.587T10 20h4q0 .825-.587 1.413T12 22m-3-3q-.425 0-.712-.288T8 18q0-.425.288-.712T9 17h6q.425 0 .713.288T16 18q0 .425-.288.713T15 19zm-.75-3q-1.725-1.025-2.738-2.75T4.5 9.5q0-3.125 2.188-5.312T12 2q3.125 0 5.313 2.188T19.5 9.5q0 2.025-1.012 3.75T15.75 16zm.6-2h6.3q1.125-.8 1.738-1.975T17.5 9.5q0-2.3-1.6-3.9T12 4Q9.7 4 8.1 5.6T6.5 9.5q0 1.35.613 2.525T8.85 14M12 14"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-important {
--mdbook-alerts-color: rgb(130, 80, 223);
/* https://icon-sets.iconify.design/material-symbols/chat-info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 7q.425 0 .713-.288T13 6q0-.425-.288-.712T12 5q-.425 0-.712.288T11 6q0 .425.288.713T12 7m0 8q.425 0 .713-.288T13 14v-4q0-.425-.288-.712T12 9q-.425 0-.712.288T11 10v4q0 .425.288.713T12 15m-6 3l-2.3 2.3q-.475.475-1.088.213T2 19.575V4q0-.825.588-1.412T4 2h16q.825 0 1.413.588T22 4v12q0 .825-.587 1.413T20 18zm-.85-2H20V4H4v13.125zM4 16V4z"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-warning {
--mdbook-alerts-color: rgb(154, 103, 0);
/* https://icon-sets.iconify.design/material-symbols/warning-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M2.725 21q-.275 0-.5-.137t-.35-.363q-.125-.225-.137-.488t.137-.512l9.25-16q.15-.25.388-.375T12 3q.25 0 .488.125t.387.375l9.25 16q.15.25.138.513t-.138.487q-.125.225-.35.363t-.5.137zm1.725-2h15.1L12 6zM12 18q.425 0 .713-.288T13 17q0-.425-.288-.712T12 16q-.425 0-.712.288T11 17q0 .425.288.713T12 18m0-3q.425 0 .713-.288T13 14v-3q0-.425-.288-.712T12 10q-.425 0-.712.288T11 11v3q0 .425.288.713T12 15m0-2.5"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-caution {
--mdbook-alerts-color: rgb(207, 34, 46);
/* https://icon-sets.iconify.design/material-symbols/brightness-alert-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16q0-.425-.288-.712T12 15q-.425 0-.712.288T11 16q0 .425.288.713T12 17m0-4q.425 0 .713-.288T13 12V8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8v4q0 .425.288.713T12 13m-3.35 7H6q-.825 0-1.412-.587T4 18v-2.65L2.075 13.4q-.275-.3-.425-.662T1.5 12q0-.375.15-.737t.425-.663L4 8.65V6q0-.825.588-1.412T6 4h2.65l1.95-1.925q.3-.275.663-.425T12 1.5q.375 0 .738.15t.662.425L15.35 4H18q.825 0 1.413.588T20 6v2.65l1.925 1.95q.275.3.425.663t.15.737q0 .375-.15.738t-.425.662L20 15.35V18q0 .825-.587 1.413T18 20h-2.65l-1.95 1.925q-.3.275-.662.425T12 22.5q-.375 0-.737-.15t-.663-.425zm.85-2l2.5 2.5l2.5-2.5H18v-3.5l2.5-2.5L18 9.5V6h-3.5L12 3.5L9.5 6H6v3.5L3.5 12L6 14.5V18zm2.5-6"%2F%3E%3C%2Fsvg%3E');
}
</style>
<h1 id="udp-transport-experimental"><a class="header" href="#udp-transport-experimental">UDP Transport (Experimental)</a></h1>
<h2 id="description-3"><a class="header" href="#description-3">Description</a></h2>
<p>The <a name="a001"></a><em>udp</em> transport supports communication between peers using <a name="a002"></a>UDP.</p>
<p>UDP is a very light-weight connection-less, unreliable, unordered delivery mechanism.</p>
<p>Both <a name="a003"></a>IPv4 and <a name="a004"></a>IPv6 are supported when the underlying platform also supports it.</p>
<p>This transport adds an ordering guarantee, so that messages will always be received in
the correct order. Messages that arrive out of order, or are duplicated, will be
dropped. There may be gaps in the messages received, so applications should not assume
that all messages sent will arrive.</p>
<div class="mdbook-alerts mdbook-alerts-note">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
note
</p>
<p>This transport is <em>experimental</em>.</p>
</div>
<h2 id="uri-format-2"><a class="header" href="#uri-format-2">URI Format</a></h2>
<p>This transport uses URIs using the scheme <a name="a005"></a><code>udp://</code>, followed by
an IP address or hostname, followed by a colon and finally a
UDP <a name="a006"></a>port number.
For example, to contact port 8001 on the localhost either of the following URIs
could be used: <code>udp://127.0.0.1:8001</code> or <code>udp://localhost:8001</code>.</p>
<p>A URI may be restricted to IPv6 using the scheme <code>udp6://</code>, and may
be restricted to IPv4 using the scheme <code>udp4://</code>.</p>
<div class="mdbook-alerts mdbook-alerts-note">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
note
</p>
<p>Specifying <code>udp6://</code> may not prevent IPv4 hosts from being used with
IPv4-in-IPv6 addresses, particularly when using a wildcard hostname with
listeners.
The details of this varies across operating systems.</p>
</div>
<div class="mdbook-alerts mdbook-alerts-tip">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
tip
</p>
<p>We recommend using either numeric IP addresses, or names that are
specific to either IPv4 or IPv6 to prevent confusion and surprises.</p>
</div>
<p>When specifying IPv6 addresses, the address must be enclosed in
square brackets (<code>[]</code>) to avoid confusion with the final colon
separating the port.</p>
<p>For example, the same port 8001 on the IPv6 loopback address (<code>::1</code>) would
be specified as <code>udp://[::1]:8001</code>.</p>
<p>The special value of 0 (<a name="a007"></a><code>INADDR_ANY</code>)
can be used for a listener to indicate that it should listen on all
interfaces on the host.
A short-hand for this form is to either omit the address, or specify
the asterisk (<code>*</code>) character.
For example, the following three URIs are all equivalent,
and could be used to listen to port 9999 on the host:</p>
<ol>
<li><code>udp://0.0.0.0:9999</code></li>
<li><code>udp://*:9999</code></li>
<li><code>udp://:9999</code></li>
</ol>
<h2 id="socket-address-3"><a class="header" href="#socket-address-3">Socket Address</a></h2>
<p>When using an <a href="tran/%5BTODO.html"><code>nng_sockaddr</code></a> structure,
the actual structure is either of type
<a href="tran/%5BTODO.html"><code>nng_sockaddr_in</code></a> (for IPv4) or
<a href="tran/%5BTODO.html"><code>nng_sockaddr_in6</code></a> (for IPv6).</p>
<h2 id="transport-options-3"><a class="header" href="#transport-options-3">Transport Options</a></h2>
<p>The following transport options are supported by this transport,
where supported by the underlying platform.</p>
<ul>
<li><a href="tran/%5BTODO.html"><code>NNG_OPT_LOCADDR</code></a></li>
<li><a href="tran/%5BTODO.html"><code>NNG_OPT_REMADDR</code></a></li>
</ul>
<p>TODO: Document other options.</p>
<h2 id="maximum-message-size"><a class="header" href="#maximum-message-size">Maximum Message Size</a></h2>
<p>This transport maps each SP message to a single UDP packet.
In order to allow room for network headers, we thus limit the maximum
message size to 65000 bytes, minus the overhead for any SP protocol headers.</p>
<p>However, applications are <em>strongly</em> encouraged to only use this transport for
very much smaller messages, ideally those that will fit within a single network
packet without requiring fragmentation and reassembly.</p>
<p>For Ethernet without jumbo frames, this typically means an <a name="a008"></a>MTU of a little
less than 1500 bytes. (Specifically, 1452, which allows 28 bytes for IP and UDP,
and 20 bytes for the this transport).
Other link layers may have different MTUs.</p>
<p>The maximum message size is negotiated as part of establishing a peering relationship,
and oversize messages will be dropped by the sender before going to the network.</p>
<p>The maximum message size to receive can be configured with the
<a href="tran/%5BTODO.html"><code>NNG_OPT_RECVMAXSZ</code></a> option.</p>
<h2 id="keep-alive"><a class="header" href="#keep-alive">Keep Alive</a></h2>
<p>This transports maintains a logical “connection” with each peer, to provide a rough
facsimile of a connection based semantic. This requires some resource on each peer.
In order to ensure that resources are reclaimed when a peer vanishes unexpectedly, a
keep-alive mechanism is implemented.</p>
<p>TODO: Document the tunables for this.</p>
<div style="break-before: page; page-break-before: always;"></div><style>
.mdbook-alerts {
padding: 8px 16px;
margin-bottom: 16px;
border-left: 0.25em solid var(--mdbook-alerts-color);
}
.mdbook-alerts > *:first-child {
margin-top: 0;
}
.mdbook-alerts > *:last-child {
margin-bottom: 0;
}
.mdbook-alerts-title {
display: flex;
font-weight: 600;
align-items: center;
line-height: 1;
color: var(--mdbook-alerts-color);
text-transform: capitalize;
}
.mdbook-alerts-icon {
display: inline-block;
width: 1em;
height: 1em;
margin-right: 0.2em;
background-color: currentColor;
-webkit-mask: no-repeat center / 100%;
mask: no-repeat center / 100%;
-webkit-mask-image: var(--mdbook-alerts-icon);
mask-image: var(--mdbook-alerts-icon);
}
.mdbook-alerts-note {
--mdbook-alerts-color: rgb(9, 105, 218);
/* https://icon-sets.iconify.design/material-symbols/info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16v-4q0-.425-.288-.712T12 11q-.425 0-.712.288T11 12v4q0 .425.288.713T12 17m0-8q.425 0 .713-.288T13 8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8q0 .425.288.713T12 9m0 13q-2.075 0-3.9-.788t-3.175-2.137q-1.35-1.35-2.137-3.175T2 12q0-2.075.788-3.9t2.137-3.175q1.35-1.35 3.175-2.137T12 2q2.075 0 3.9.788t3.175 2.137q1.35 1.35 2.138 3.175T22 12q0 2.075-.788 3.9t-2.137 3.175q-1.35 1.35-3.175 2.138T12 22m0-2q3.35 0 5.675-2.325T20 12q0-3.35-2.325-5.675T12 4Q8.65 4 6.325 6.325T4 12q0 3.35 2.325 5.675T12 20m0-8"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-tip {
--mdbook-alerts-color: rgb(26, 127, 55);
/* https://icon-sets.iconify.design/material-symbols/lightbulb-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 22q-.825 0-1.412-.587T10 20h4q0 .825-.587 1.413T12 22m-3-3q-.425 0-.712-.288T8 18q0-.425.288-.712T9 17h6q.425 0 .713.288T16 18q0 .425-.288.713T15 19zm-.75-3q-1.725-1.025-2.738-2.75T4.5 9.5q0-3.125 2.188-5.312T12 2q3.125 0 5.313 2.188T19.5 9.5q0 2.025-1.012 3.75T15.75 16zm.6-2h6.3q1.125-.8 1.738-1.975T17.5 9.5q0-2.3-1.6-3.9T12 4Q9.7 4 8.1 5.6T6.5 9.5q0 1.35.613 2.525T8.85 14M12 14"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-important {
--mdbook-alerts-color: rgb(130, 80, 223);
/* https://icon-sets.iconify.design/material-symbols/chat-info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 7q.425 0 .713-.288T13 6q0-.425-.288-.712T12 5q-.425 0-.712.288T11 6q0 .425.288.713T12 7m0 8q.425 0 .713-.288T13 14v-4q0-.425-.288-.712T12 9q-.425 0-.712.288T11 10v4q0 .425.288.713T12 15m-6 3l-2.3 2.3q-.475.475-1.088.213T2 19.575V4q0-.825.588-1.412T4 2h16q.825 0 1.413.588T22 4v12q0 .825-.587 1.413T20 18zm-.85-2H20V4H4v13.125zM4 16V4z"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-warning {
--mdbook-alerts-color: rgb(154, 103, 0);
/* https://icon-sets.iconify.design/material-symbols/warning-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M2.725 21q-.275 0-.5-.137t-.35-.363q-.125-.225-.137-.488t.137-.512l9.25-16q.15-.25.388-.375T12 3q.25 0 .488.125t.387.375l9.25 16q.15.25.138.513t-.138.487q-.125.225-.35.363t-.5.137zm1.725-2h15.1L12 6zM12 18q.425 0 .713-.288T13 17q0-.425-.288-.712T12 16q-.425 0-.712.288T11 17q0 .425.288.713T12 18m0-3q.425 0 .713-.288T13 14v-3q0-.425-.288-.712T12 10q-.425 0-.712.288T11 11v3q0 .425.288.713T12 15m0-2.5"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-caution {
--mdbook-alerts-color: rgb(207, 34, 46);
/* https://icon-sets.iconify.design/material-symbols/brightness-alert-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16q0-.425-.288-.712T12 15q-.425 0-.712.288T11 16q0 .425.288.713T12 17m0-4q.425 0 .713-.288T13 12V8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8v4q0 .425.288.713T12 13m-3.35 7H6q-.825 0-1.412-.587T4 18v-2.65L2.075 13.4q-.275-.3-.425-.662T1.5 12q0-.375.15-.737t.425-.663L4 8.65V6q0-.825.588-1.412T6 4h2.65l1.95-1.925q.3-.275.663-.425T12 1.5q.375 0 .738.15t.662.425L15.35 4H18q.825 0 1.413.588T20 6v2.65l1.925 1.95q.275.3.425.663t.15.737q0 .375-.15.738t-.425.662L20 15.35V18q0 .825-.587 1.413T18 20h-2.65l-1.95 1.925q-.3.275-.662.425T12 22.5q-.375 0-.737-.15t-.663-.425zm.85-2l2.5 2.5l2.5-2.5H18v-3.5l2.5-2.5L18 9.5V6h-3.5L12 3.5L9.5 6H6v3.5L3.5 12L6 14.5V18zm2.5-6"%2F%3E%3C%2Fsvg%3E');
}
</style>
<h1 id="migration-guides"><a class="header" href="#migration-guides">Migration Guides</a></h1>
<p>This section provides some guides to aid in migrating software from
earlier versions <em>NNG</em> or <em>libnanomsg</em>.</p>
<ul>
<li><a href="migrate/./migrate/nng1.html">Migrating from NNG 1.x</a></li>
<li><a href="migrate/./migrate/nanomsg.html">Migrating from libnanomsg</a></li>
</ul>
<div style="break-before: page; page-break-before: always;"></div><style>
.mdbook-alerts {
padding: 8px 16px;
margin-bottom: 16px;
border-left: 0.25em solid var(--mdbook-alerts-color);
}
.mdbook-alerts > *:first-child {
margin-top: 0;
}
.mdbook-alerts > *:last-child {
margin-bottom: 0;
}
.mdbook-alerts-title {
display: flex;
font-weight: 600;
align-items: center;
line-height: 1;
color: var(--mdbook-alerts-color);
text-transform: capitalize;
}
.mdbook-alerts-icon {
display: inline-block;
width: 1em;
height: 1em;
margin-right: 0.2em;
background-color: currentColor;
-webkit-mask: no-repeat center / 100%;
mask: no-repeat center / 100%;
-webkit-mask-image: var(--mdbook-alerts-icon);
mask-image: var(--mdbook-alerts-icon);
}
.mdbook-alerts-note {
--mdbook-alerts-color: rgb(9, 105, 218);
/* https://icon-sets.iconify.design/material-symbols/info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16v-4q0-.425-.288-.712T12 11q-.425 0-.712.288T11 12v4q0 .425.288.713T12 17m0-8q.425 0 .713-.288T13 8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8q0 .425.288.713T12 9m0 13q-2.075 0-3.9-.788t-3.175-2.137q-1.35-1.35-2.137-3.175T2 12q0-2.075.788-3.9t2.137-3.175q1.35-1.35 3.175-2.137T12 2q2.075 0 3.9.788t3.175 2.137q1.35 1.35 2.138 3.175T22 12q0 2.075-.788 3.9t-2.137 3.175q-1.35 1.35-3.175 2.138T12 22m0-2q3.35 0 5.675-2.325T20 12q0-3.35-2.325-5.675T12 4Q8.65 4 6.325 6.325T4 12q0 3.35 2.325 5.675T12 20m0-8"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-tip {
--mdbook-alerts-color: rgb(26, 127, 55);
/* https://icon-sets.iconify.design/material-symbols/lightbulb-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 22q-.825 0-1.412-.587T10 20h4q0 .825-.587 1.413T12 22m-3-3q-.425 0-.712-.288T8 18q0-.425.288-.712T9 17h6q.425 0 .713.288T16 18q0 .425-.288.713T15 19zm-.75-3q-1.725-1.025-2.738-2.75T4.5 9.5q0-3.125 2.188-5.312T12 2q3.125 0 5.313 2.188T19.5 9.5q0 2.025-1.012 3.75T15.75 16zm.6-2h6.3q1.125-.8 1.738-1.975T17.5 9.5q0-2.3-1.6-3.9T12 4Q9.7 4 8.1 5.6T6.5 9.5q0 1.35.613 2.525T8.85 14M12 14"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-important {
--mdbook-alerts-color: rgb(130, 80, 223);
/* https://icon-sets.iconify.design/material-symbols/chat-info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 7q.425 0 .713-.288T13 6q0-.425-.288-.712T12 5q-.425 0-.712.288T11 6q0 .425.288.713T12 7m0 8q.425 0 .713-.288T13 14v-4q0-.425-.288-.712T12 9q-.425 0-.712.288T11 10v4q0 .425.288.713T12 15m-6 3l-2.3 2.3q-.475.475-1.088.213T2 19.575V4q0-.825.588-1.412T4 2h16q.825 0 1.413.588T22 4v12q0 .825-.587 1.413T20 18zm-.85-2H20V4H4v13.125zM4 16V4z"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-warning {
--mdbook-alerts-color: rgb(154, 103, 0);
/* https://icon-sets.iconify.design/material-symbols/warning-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M2.725 21q-.275 0-.5-.137t-.35-.363q-.125-.225-.137-.488t.137-.512l9.25-16q.15-.25.388-.375T12 3q.25 0 .488.125t.387.375l9.25 16q.15.25.138.513t-.138.487q-.125.225-.35.363t-.5.137zm1.725-2h15.1L12 6zM12 18q.425 0 .713-.288T13 17q0-.425-.288-.712T12 16q-.425 0-.712.288T11 17q0 .425.288.713T12 18m0-3q.425 0 .713-.288T13 14v-3q0-.425-.288-.712T12 10q-.425 0-.712.288T11 11v3q0 .425.288.713T12 15m0-2.5"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-caution {
--mdbook-alerts-color: rgb(207, 34, 46);
/* https://icon-sets.iconify.design/material-symbols/brightness-alert-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16q0-.425-.288-.712T12 15q-.425 0-.712.288T11 16q0 .425.288.713T12 17m0-4q.425 0 .713-.288T13 12V8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8v4q0 .425.288.713T12 13m-3.35 7H6q-.825 0-1.412-.587T4 18v-2.65L2.075 13.4q-.275-.3-.425-.662T1.5 12q0-.375.15-.737t.425-.663L4 8.65V6q0-.825.588-1.412T6 4h2.65l1.95-1.925q.3-.275.663-.425T12 1.5q.375 0 .738.15t.662.425L15.35 4H18q.825 0 1.413.588T20 6v2.65l1.925 1.95q.275.3.425.663t.15.737q0 .375-.15.738t-.425.662L20 15.35V18q0 .825-.587 1.413T18 20h-2.65l-1.95 1.925q-.3.275-.662.425T12 22.5q-.375 0-.737-.15t-.663-.425zm.85-2l2.5 2.5l2.5-2.5H18v-3.5l2.5-2.5L18 9.5V6h-3.5L12 3.5L9.5 6H6v3.5L3.5 12L6 14.5V18zm2.5-6"%2F%3E%3C%2Fsvg%3E');
}
</style>
<h1 id="migrating-from-nng-1x"><a class="header" href="#migrating-from-nng-1x">Migrating from NNG 1.x</a></h1>
<p>There are some incompatibities from NNG 1.x.
This guide should help in migrating applications to use NNG 2.0.</p>
<h2 id="nanomsg-compatibility"><a class="header" href="#nanomsg-compatibility">Nanomsg Compatibility</a></h2>
<p>Applications using the legacy <code>libnanomsg</code> API will have to be updated to native <em>NNG</em> interfaces.
See the <a href="migrate/nanomsg.html">Migrating From libnanomsg</a> chapter for details.</p>
<h2 id="library-initialization"><a class="header" href="#library-initialization">Library Initialization</a></h2>
<p>It is now required for applications to initialize the library explicitly before using it.
This is done using the <a href="migrate//api/init.html#initialization"><code>nng_init</code></a> function.</p>
<h2 id="transport-specific-functions"><a class="header" href="#transport-specific-functions">Transport Specific Functions</a></h2>
<p>Transports have not needed to be registered for a long time now,
and the functions for doing so have been removed. These functions
can be simply removed from your application:</p>
<ul>
<li><code>nng_inproc_register</code></li>
<li><code>nng_ipc_register</code></li>
<li><code>nng_tls_register</code></li>
<li><code>nng_tcp_register</code></li>
<li><code>nng_ws_register</code></li>
<li><code>nng_wss_register</code></li>
<li><code>nng_zt_register</code></li>
</ul>
<p>Additionally, the header files containing these functions have been removed, such as
<code>nng/transport/ipc/ipc.h</code>. Simply remove <code>#include</code> references to those files.</p>
<p>(Special exception: The options for ZeroTier are still located in the
<code>nng/transport/zerotier/zerotier.h</code>.)</p>
<p>The <code>NNG_OPT_WSS_REQUEST_HEADERS</code> and <code>NNG_OPT_WSS_RESPONSE_HEADERS</code> aliases for
<code>NNG_OPT_WS_OPT_WS_REQUEST_HEADERS</code> and <code>NNG_OPT_WS_RESPONSE_HEADERS</code> have been removed.
Just convert any use of them to <code>NNG_OPT_WS_REQUEST_HEADERS</code> or
<code>NNG_OPT_WS_RESPONSE_HEADERS</code> as appropriate.</p>
<h2 id="tls-configuration"><a class="header" href="#tls-configuration">TLS Configuration</a></h2>
<p>The support for configuring TLS via <code>NNG_OPT_TLS_CONFIG</code>, <code>NNG_TLS_AUTH_MODE</code>, <code>NNG_OPT_TLS_CA_FILE</code>,
<code>NNG_OPT_TLS_SERVER_NAME</code>, and similar has been removed.</p>
<p>Instead configuration must be performed by allocating
a <code>nng_tls_config</code> object, and then setting fields on it using the appropriate functions,
after which it may be configured on a listener or dialer using the <a href="migrate//TODO.html"><code>nng_listener_set_tls</code></a>
or <a href="migrate//TODO.html"><code>nng_dialer_set_tls</code></a> functions.</p>
<p>Likewise, when using the streams API, use the <a href="migrate//TODO.html"><code>nng_stream_listener_set_tls</code></a> or
<a href="migrate//TODO.html"><code>nng_stream_dialer_set_tls</code></a> functions.</p>
<p>Note that the declarations needed for TLS configuration are now available in <code><nng/nng.h></code>,
rather than the supplemental header.</p>
<h2 id="old-tls-versions-removed"><a class="header" href="#old-tls-versions-removed">Old TLS Versions Removed</a></h2>
<p>Support for very old TLS versions 1.0 and 1.1 is removed.
Further, the <code>NNG_TLS_1_0</code> and <code>NNG_TLS_1_1</code> constants are also removed.
Applications should use <code>NNG_TLS_1_2</code> or even <code>NNG_TLS_1_3</code> instead.</p>
<h2 id="only-one-tls-keycert-per-configuration"><a class="header" href="#only-one-tls-keycert-per-configuration">Only One TLS Key/Cert Per Configuration</a></h2>
<p>The ability to configure multiple keys and certificates for a given TLS configuration object is removed.
(The <a href="migrate//TODO.html"><code>nng_tls_config_own_cert</code></a> will return <a href="migrate//api/errors.html#NNG_EBUSY"><code>NNG_EBUSY</code></a> if it has already been called for the configuration.)
The intended purpose was to support alternative cryptographic algorithms, but this is not necessary, was never
used, and was error prone.</p>
<h2 id="support-for-local-addresses-in-dial-urls-removed"><a class="header" href="#support-for-local-addresses-in-dial-urls-removed">Support for Local Addresses in Dial URLs Removed</a></h2>
<p>NNG 1.x had an undocumented ability to specify the local address to bind
to when dialing, by using the local address in front of the destination
address separated by a semicolon. This was provided for legacy libnanomsg
compatilibility, and is no longer offered. The correct way to specify a
local address is by setting <code>NNG_OPT_LOCADDR</code> on the dialer.</p>
<h2 id="option-functions"><a class="header" href="#option-functions">Option Functions</a></h2>
<p>The previously deprecated <code>nng_pipe_getopt_xxx</code> family of functions is removed.
Applications should use <code>nng_pipe_get</code> and related functions instead.</p>
<p>The socket option function families for <code>nng_getopt</code> and <code>nng_setopt</code> have been removed as well.
In this case, use the <code>nng_socket_get</code> and <code>nng_socket_set</code> functions as appropriate.</p>
<p>The <code>_getopt</code> and <code>_setopt</code> functions for contexts, listeners, and dialers are no longer
present. Simply changing <code>_getopt</code> to <code>_get</code> or <code>_setopt</code> to <code>_set</code> in the function name
should be sufficient in most cases.</p>
<p>The following functions served no useful purpose (after other changes described in this document),
and are thus removed:</p>
<ul>
<li><code>nng_ctx_get_string</code></li>
<li><code>nng_ctx_set_string</code></li>
<li><code>nng_socket_get_ptr</code></li>
<li><code>nng_socket_set_ptr</code></li>
<li><code>nng_socket_get_string</code></li>
<li><code>nng_socket_set_string</code></li>
<li><code>nng_ctx_get_ptr</code> (not documented)</li>
<li><code>nng_ctx_set_ptr</code> (not documented)</li>
</ul>
<h2 id="untyped-option-functions-removed"><a class="header" href="#untyped-option-functions-removed">Untyped Option Functions Removed</a></h2>
<p>The following functions are removed. To access options, use a proper typed access function,
such as one ending in a suffix like <code>_bool</code> (to access a <code>bool</code> typed option).</p>
<ul>
<li><code>nng_ctx_get</code></li>
<li><code>nng_ctx_set</code></li>
<li><code>nng_dialer_get</code></li>
<li><code>nng_dialer_set</code></li>
<li><code>nng_listener_get</code></li>
<li><code>nng_listener_set</code></li>
<li><code>nng_pipe_get</code></li>
<li><code>nng_socket_get</code></li>
<li><code>nng_socket_set</code></li>
<li><code>nng_stream_get</code></li>
<li><code>nng_stream_set</code></li>
<li><code>nng_stream_dialer_get</code></li>
<li><code>nng_stream_dialer_set</code></li>
<li><code>nng_stream_listener_get</code></li>
<li><code>nng_stream_listener_set</code></li>
</ul>
<h2 id="stream-options"><a class="header" href="#stream-options">Stream Options</a></h2>
<p>The ability to set options on streams after they have been created is no longer present.
(It turns out that this was not very useful.) All functions <code>nng_stream_set_xxx</code> are removed.
For tuning the <code>NNG_OPT_TCP_NODELAY</code> or similar properties, set the option on the listener
or dialer that creates the stream instead.</p>
<h2 id="transport-options-4"><a class="header" href="#transport-options-4">Transport Options</a></h2>
<p>A number of transport options can no longer be set on the socket. Instead these
options must be set on the endpoint (dialer or listener) using the appropriate
<code>nng_dialer_set</code> or <code>nng_listener_set</code> option. This likely means that it is necessary
to allocate and configure the endpoint before attaching it to the socket. This will
also afford a much more fine-grained level of control over transport options.</p>
<p>The following options are copied from the socket when creating a dialer or listener,
but afterwards will not be changed on the dialer or listener if the socket
changes. It is recommended to set them properly on the socket before
creating dialers or listeners, or set them explicitly on the dialer or listener
directly:</p>
<ul>
<li><code>NNG_OPT_RECONNMINT</code></li>
<li><code>NNG_OPT_RECONNMAXT</code></li>
<li><code>NNG_OPT_RECVMAXSZ</code></li>
</ul>
<p>The latter option is a hint for transports and intended to facilitate early
detection (and possibly avoidance of extra allocations) of oversize messages,
before bringing them into the socket itself.</p>
<h2 id="socket-options"><a class="header" href="#socket-options">Socket Options</a></h2>
<p>The <code>NNG_OPT_PROTO</code>, <code>NNG_OPT_PROTONAME</code>, <code>NNG_OPT_PEER</code>, and <code>NNG_OPT_PEERNAME</code> options
have been replaced by functions instead of options.
Use <a href="migrate//api/sock.html#socket-identity"><code>nng_socket_proto_id</code></a>, <a href="migrate//api/sock.html#socket-identity"><code>nng_socket_peer_id</code></a>, <a href="migrate//api/sock.html#socket-identity"><code>nng_socket_proto_name</code></a>, and <a href="migrate//api/sock.html#socket-identity"><code>nng_socket_peer_name</code></a> instead.
Note that the new functions provide a reference to a static string, and thus do not require
allocation, and the returned strings should not be freed. Also the IDs are provided as <code>uint16_t</code>,
matching the actual wire protocol values, instead of <code>int</code>.</p>
<p>The <code>NNG_OPT_RAW</code> option has aso been replaced by a function, <a href="migrate//api/sock.html#socket-identity"><code>nng_socket_raw</code></a>.</p>
<p>The <code>NNG_OPT_SENDFD</code> and <code>NNG_OPT_RECVFD</code> options have been replaced by
<a href="migrate//api/sock.html#polling-socket-events"><code>nng_socket_get_send_poll_fd</code></a> and <a href="migrate//api/sock.html#polling-socket-events"><code>nng_socket_get_recv_poll_fd</code></a> respectively.</p>
<p>The <code>NNG_OPT_SOCKNAME</code> function is removed. This was provided for application use, and never used internally by NNG.
Applications should keep track of this information separately.</p>
<h2 id="subscriptions"><a class="header" href="#subscriptions">Subscriptions</a></h2>
<p>The <code>NNG_OPT_SUB_SUBSCRIBE</code> and <code>NNG_OPT_SUB_UNSUBCRIBE</code> options have been replaced by
the following functions: <a href="migrate//TODO.html"><code>nng_sub0_socket_subscribe</code></a>, <a href="migrate//TODO.html"><code>nng_sub0_socket_unsubscribe</code></a>,
<a href="migrate//TODO.html"><code>nng_sub0_ctx_subscribe</code></a> and <a href="migrate//TODO.html"><code>nng_sub0_ctx_unsubscribe</code></a>. These functions, like the options
they replace, are only applicable to SUB sockets.</p>
<h2 id="statistics-use-constified-pointers"><a class="header" href="#statistics-use-constified-pointers">Statistics Use Constified Pointers</a></h2>
<p>A number of the <a href="migrate//api/stats.html">statistics</a> functions take, or return, <code>const nng_stat *</code> instead
of plain <code>nng_stat *</code>. The ABI has not changed, but it may be necessary to declare
certain methods variables <code>const</code> to avoid warnings about misuse of <code>const</code>.</p>
<h2 id="wildcards-not-valid-in-urls"><a class="header" href="#wildcards-not-valid-in-urls">Wildcards Not Valid in URLs</a></h2>
<p>The use of <code>*</code> to act as a wild card meaning all local interface addresses
is removed. The empty string already performs this function, and unlike
<code>*</code> is RFC compliant.</p>
<h2 id="url-option-removed"><a class="header" href="#url-option-removed">URL Option Removed</a></h2>
<p>The <code>NNG_OPT_URL</code> option has been removed.
It is replaced by the type safe <a href="migrate//TODO.html"><code>nng_dialer_get_url</code></a> and
<a href="migrate//TODO.html"><code>nng_listener_get_url</code></a> functions, which return an <a href="migrate//api/url.html#url-structure"><code>nng_url</code></a>
structure instead of a string.</p>
<h2 id="url-structure-changes"><a class="header" href="#url-structure-changes">URL Structure Changes</a></h2>
<p>The details of <a href="migrate//api/url.html#url-structure"><code>nng_url</code></a> have changed significantly, and direct
access of the structure is no longer permitted. Intead new
accessors functions are provided:</p>
<ul>
<li><code>u_scheme</code> is replaced by [<code>nng_url_scheme</code>].</li>
<li><code>u_port</code> is replaced by [<code>nng_url_port</code>], but this returns a <code>uint16_t</code>.</li>
<li><code>u_hostname</code> is replaced by [<code>nng_url_hostname</code>].</li>
<li><code>u_path</code> is replaced by [<code>nng_url_path</code>].</li>
<li><code>u_query</code> is replaced by [<code>nng_url_query</code>].</li>
<li><code>u_fragment</code> is replaced by [<code>nng_url_fragment</code>].</li>
<li><code>u_userinfo</code> is replaced by [<code>nng_url_userinfo</code>].</li>
<li><code>u_requri</code> is removed - it can be easily formulated from the other fields.</li>
<li><code>u_host</code> is removed - use [<code>nng_url_hostname</code>] and [<code>nng_url_port</code>] to construct if needed</li>
<li><code>u_rawurl</code> is removed - a “cooked” URL can be obtained from the new <a href="migrate//api/url.html#format-a-url"><code>nng_url_sprintf</code></a> function.</li>
</ul>
<!-- Symbol cross reference -->
<!-- Macros -->
<!-- Protocols -->
<!-- Transports -->
<!-- Concept index -->
<div style="break-before: page; page-break-before: always;"></div><style>
.mdbook-alerts {
padding: 8px 16px;
margin-bottom: 16px;
border-left: 0.25em solid var(--mdbook-alerts-color);
}
.mdbook-alerts > *:first-child {
margin-top: 0;
}
.mdbook-alerts > *:last-child {
margin-bottom: 0;
}
.mdbook-alerts-title {
display: flex;
font-weight: 600;
align-items: center;
line-height: 1;
color: var(--mdbook-alerts-color);
text-transform: capitalize;
}
.mdbook-alerts-icon {
display: inline-block;
width: 1em;
height: 1em;
margin-right: 0.2em;
background-color: currentColor;
-webkit-mask: no-repeat center / 100%;
mask: no-repeat center / 100%;
-webkit-mask-image: var(--mdbook-alerts-icon);
mask-image: var(--mdbook-alerts-icon);
}
.mdbook-alerts-note {
--mdbook-alerts-color: rgb(9, 105, 218);
/* https://icon-sets.iconify.design/material-symbols/info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16v-4q0-.425-.288-.712T12 11q-.425 0-.712.288T11 12v4q0 .425.288.713T12 17m0-8q.425 0 .713-.288T13 8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8q0 .425.288.713T12 9m0 13q-2.075 0-3.9-.788t-3.175-2.137q-1.35-1.35-2.137-3.175T2 12q0-2.075.788-3.9t2.137-3.175q1.35-1.35 3.175-2.137T12 2q2.075 0 3.9.788t3.175 2.137q1.35 1.35 2.138 3.175T22 12q0 2.075-.788 3.9t-2.137 3.175q-1.35 1.35-3.175 2.138T12 22m0-2q3.35 0 5.675-2.325T20 12q0-3.35-2.325-5.675T12 4Q8.65 4 6.325 6.325T4 12q0 3.35 2.325 5.675T12 20m0-8"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-tip {
--mdbook-alerts-color: rgb(26, 127, 55);
/* https://icon-sets.iconify.design/material-symbols/lightbulb-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 22q-.825 0-1.412-.587T10 20h4q0 .825-.587 1.413T12 22m-3-3q-.425 0-.712-.288T8 18q0-.425.288-.712T9 17h6q.425 0 .713.288T16 18q0 .425-.288.713T15 19zm-.75-3q-1.725-1.025-2.738-2.75T4.5 9.5q0-3.125 2.188-5.312T12 2q3.125 0 5.313 2.188T19.5 9.5q0 2.025-1.012 3.75T15.75 16zm.6-2h6.3q1.125-.8 1.738-1.975T17.5 9.5q0-2.3-1.6-3.9T12 4Q9.7 4 8.1 5.6T6.5 9.5q0 1.35.613 2.525T8.85 14M12 14"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-important {
--mdbook-alerts-color: rgb(130, 80, 223);
/* https://icon-sets.iconify.design/material-symbols/chat-info-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 7q.425 0 .713-.288T13 6q0-.425-.288-.712T12 5q-.425 0-.712.288T11 6q0 .425.288.713T12 7m0 8q.425 0 .713-.288T13 14v-4q0-.425-.288-.712T12 9q-.425 0-.712.288T11 10v4q0 .425.288.713T12 15m-6 3l-2.3 2.3q-.475.475-1.088.213T2 19.575V4q0-.825.588-1.412T4 2h16q.825 0 1.413.588T22 4v12q0 .825-.587 1.413T20 18zm-.85-2H20V4H4v13.125zM4 16V4z"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-warning {
--mdbook-alerts-color: rgb(154, 103, 0);
/* https://icon-sets.iconify.design/material-symbols/warning-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M2.725 21q-.275 0-.5-.137t-.35-.363q-.125-.225-.137-.488t.137-.512l9.25-16q.15-.25.388-.375T12 3q.25 0 .488.125t.387.375l9.25 16q.15.25.138.513t-.138.487q-.125.225-.35.363t-.5.137zm1.725-2h15.1L12 6zM12 18q.425 0 .713-.288T13 17q0-.425-.288-.712T12 16q-.425 0-.712.288T11 17q0 .425.288.713T12 18m0-3q.425 0 .713-.288T13 14v-3q0-.425-.288-.712T12 10q-.425 0-.712.288T11 11v3q0 .425.288.713T12 15m0-2.5"%2F%3E%3C%2Fsvg%3E');
}
.mdbook-alerts-caution {
--mdbook-alerts-color: rgb(207, 34, 46);
/* https://icon-sets.iconify.design/material-symbols/brightness-alert-outline-rounded/ */
--mdbook-alerts-icon: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cpath fill="currentColor" d="M12 17q.425 0 .713-.288T13 16q0-.425-.288-.712T12 15q-.425 0-.712.288T11 16q0 .425.288.713T12 17m0-4q.425 0 .713-.288T13 12V8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8v4q0 .425.288.713T12 13m-3.35 7H6q-.825 0-1.412-.587T4 18v-2.65L2.075 13.4q-.275-.3-.425-.662T1.5 12q0-.375.15-.737t.425-.663L4 8.65V6q0-.825.588-1.412T6 4h2.65l1.95-1.925q.3-.275.663-.425T12 1.5q.375 0 .738.15t.662.425L15.35 4H18q.825 0 1.413.588T20 6v2.65l1.925 1.95q.275.3.425.663t.15.737q0 .375-.15.738t-.425.662L20 15.35V18q0 .825-.587 1.413T18 20h-2.65l-1.95 1.925q-.3.275-.662.425T12 22.5q-.375 0-.737-.15t-.663-.425zm.85-2l2.5 2.5l2.5-2.5H18v-3.5l2.5-2.5L18 9.5V6h-3.5L12 3.5L9.5 6H6v3.5L3.5 12L6 14.5V18zm2.5-6"%2F%3E%3C%2Fsvg%3E');
}
</style>
<h1 id="migrating-from-libnanomsg"><a class="header" href="#migrating-from-libnanomsg">Migrating from libnanomsg</a></h1>
<p>Previous version of NNG offered direct API compatibility with <em>libnanomsg</em>,
but that support is no longer offered in this version.</p>
<p>If your application is still using legacy <em>libnanomsg</em> APIs, you will need to
update it for this version of NNG.</p>
<h2 id="header-files"><a class="header" href="#header-files">Header Files</a></h2>
<p>Most applications can replace all <code>#include <nn/*.h></code> statements with <code>#include <nng/nng.h></code>.</p>
<h2 id="link-libraries"><a class="header" href="#link-libraries">Link Libraries</a></h2>
<p>Replace <code>-lnanomsg</code> with <code>-lnng</code>.
It may be necessary to include additional system libraries, such as <code>-lpthread</code>, depending on your system.</p>
<h2 id="initialization-1"><a class="header" href="#initialization-1">Initialization</a></h2>
<p>It is necessary to explicitly initialize the library, using the <a href="migrate//api/init.html#initialization"><code>nng_init</code></a> function.
This must be called before any other function.</p>
<h2 id="types"><a class="header" href="#types">Types</a></h2>
<p>Sockets, dialers, and listeners in <em>libnanomsg</em> are simple integers.
In NNG, these are <code>struct</code> types.</p>
<p>Messages are quite different in NNG, with the absence of the POSIX message control
headers.</p>
<p>The <code>struct nn_msghdr</code> structure has no equivalent. See <code>nng_msg</code> for the
NNG approach to messages. Likewise there is no <code>struct nn_cmsghdr</code> equivalent.</p>
<h2 id="api-conversions"><a class="header" href="#api-conversions">API Conversions</a></h2>
<div class="table-wrapper"><table><thead><tr><th>Nanomsg API</th><th>NNG Equivalent</th><th>Notes</th></tr></thead><tbody>
<tr><td><code>nn_strerror</code></td><td><a href="migrate//api/errors.html#human-readable-error-message"><code>nng_strerror</code></a></td><td></td></tr>
<tr><td><code>nn_errno</code></td><td>None</td><td>Errors are returned directly rather than through <code>errno</code>.</td></tr>
<tr><td><code>nn_socket</code></td><td>Various</td><td>Use the appropriate protocol constructor, such as <code>nng_req0_open</code>.</td></tr>
<tr><td><code>nn_close</code></td><td><code>nng_close</code></td><td></td></tr>
<tr><td><code>nn_bind</code></td><td><code>nng_listen</code>, <code>nng_listener_create</code></td><td>Allocating a listener with <code>nng_lister_create</code> and configuring it offers more capabilities.</td></tr>
<tr><td><code>nn_connect</code></td><td><code>nng_dial</code>, <code>nng_dialer_create</code></td><td>Allocating a dialer with <code>nng_dialer_create</code> and configuring it offers more capabilities.</td></tr>
<tr><td><code>nn_shutdown</code></td><td><code>nng_lister_close</code>, <code>nng_dialer_close</code></td><td></td></tr>
<tr><td><code>nn_allocmsg</code></td><td><a href="migrate//api/msg.html#create-a-message"><code>nng_msg_alloc</code></a></td><td>There are significant semantic differences.</td></tr>
<tr><td><code>nn_freemsg</code></td><td><a href="migrate//api/msg.html#destroy-a-message"><code>nng_msg_free</code></a></td><td></td></tr>
<tr><td><code>nn_reallocmsg</code></td><td><a href="migrate//api/msg.html#message-size-and-capacity"><code>nng_msg_realloc</code></a></td><td></td></tr>
<tr><td><code>nn_send</code></td><td><code>nng_send</code></td><td></td></tr>
<tr><td><code>nn_recv</code></td><td><code>nng_recv</code></td><td></td></tr>
<tr><td><code>nn_sendmsg</code></td><td><code>nng_sendmsg</code></td><td></td></tr>
<tr><td><code>nn_getsockopt</code></td><td><code>nng_socket_get</code></td><td>NNG has typed accessors for options, and also separate functions for dialers and listeners.</td></tr>
<tr><td><code>nn_setsockopt</code></td><td><code>nng_socket_set</code></td><td></td></tr>
<tr><td><code>nn_device</code></td><td><code>nng_device</code></td><td></td></tr>
<tr><td><code>nn_poll</code></td><td>None</td><td>Can be constructed using <code>nng_aio</code>. Few if any applications ever used this API.</td></tr>
<tr><td><code>nn_term</code></td><td>None</td><td>The <code>nng_fini</code> API can do this, but is not recommended except when debugging memory leaks.</td></tr>
<tr><td><code>nn_get_statistic</code></td><td><code>nng_stats_get</code></td><td>The statistics in NNG are completely different, with different semantics and no stability guarantees.</td></tr>
<tr><td><code>NN_POLLIN</code></td><td>None</td><td>Used only with <code>nn_poll</code>.</td></tr>
<tr><td><code>NN_POLLOUT</code></td><td>None</td><td>Used only with <code>nn_poll</code>.</td></tr>
<tr><td><code>NN_MSG</code></td><td><code>NNG_FLAG_ALLOC</code></td><td>See <code>nng_send</code> and <code>nng_recv</code> for details.</td></tr>
<tr><td><code>NN_CMSG_ALIGN</code></td><td>None</td><td></td></tr>
<tr><td><code>NN_CMSG_FIRSTHDR</code></td><td>None</td><td></td></tr>
<tr><td><code>NN_CMSG_NXTHDR</code></td><td>None</td><td></td></tr>
<tr><td><code>NN_CMSG_DATA</code></td><td>None</td><td></td></tr>
<tr><td><code>NN_CMSG_LEN</code></td><td>None</td><td></td></tr>
<tr><td><code>NN_CMSG_SPACE</code></td><td>None</td><td></td></tr>
<tr><td><code>struct nn_iovec</code></td><td><code>nng_iov</code></td><td></td></tr>
<tr><td><code>struct nn_msghdr</code></td><td><a href="migrate//api/msg.html#message-structure"><code>nng_msg</code></a></td><td></td></tr>
<tr><td><code>struct nn_cmsghdr</code></td><td><a href="migrate//api/msg.html#message-structure"><code>nng_msg</code></a> and <a href="migrate//api/msg.html#message-header"><code>nng_msg_header</code></a></td><td></td></tr>
</tbody></table>
</div>
<h2 id="options"><a class="header" href="#options">Options</a></h2>
<p>The following options are changed.</p>
<div class="table-wrapper"><table><thead><tr><th>Nanomsg Option</th><th>NNG Eqvaivalent</th><th>Notes</th></tr></thead><tbody>
<tr><td><code>NN_LINGER</code></td><td>None</td><td>NNG does not support tuning this.</td></tr>
<tr><td><code>NN_SNDBUF</code></td><td><code>NNG_OPT_SENDBUF</code></td><td>NNG value is given in messages, not bytes.</td></tr>
<tr><td><code>NN_RCVBUF</code></td><td><code>NNG_OPT_RECVBUF</code></td><td>NNG value is given in messages, not bytes.</td></tr>
<tr><td><code>NN_SNDTIMEO</code></td><td><code>NNG_OPT_SENDTIMEO</code></td><td></td></tr>
<tr><td><code>NN_RCVTIMEO</code></td><td><code>NNG_OPT_RECVTIMEO</code></td><td></td></tr>
<tr><td><code>NN_RECONNECT_IVL</code></td><td><code>NNG_OPT_RECONNMINT</code></td><td></td></tr>
<tr><td><code>NN_RECONNECT_IVL_MAX</code></td><td><code>NNG_OPT_RECONNMAXT</code></td><td></td></tr>
<tr><td><code>NN_SNDPRIO</code></td><td>None</td><td>Not supported in NNG yet.</td></tr>
<tr><td><code>NN_RCVPRIO</code></td><td>None</td><td>Not supported in NNG yet.</td></tr>
<tr><td><code>NN_RCVFD</code></td><td><a href="migrate//api/sock.html#polling-socket-events"><code>nng_socket_get_recv_poll_fd</code></a></td><td>No longer an option, use a function call.</td></tr>
<tr><td><code>NN_SNDFD</code></td><td><a href="migrate//api/sock.html#polling-socket-events"><code>nng_socket_get_send_poll_fd</code></a></td><td>No longer an option, use a function call.</td></tr>
<tr><td><code>NN_DOMAIN</code></td><td>None</td><td>NNG options are not divided by domain or protocol.</td></tr>
<tr><td><code>NN_PROTOCOL</code></td><td><a href="migrate//api/sock.html#socket-identity"><code>nng_socket_proto_id</code></a></td><td>No longer an option. See also <code>nng_socket_proto_name</code>.</td></tr>
<tr><td><code>NN_IPV4ONLY</code></td><td>None</td><td>Use URL such as <code>tcp4://</code> to obtain this functionality.</td></tr>
<tr><td><code>NN_SOCKET_NAME</code></td><td>None</td><td>Removed from NNG.</td></tr>
<tr><td><code>NN_MAXTTL</code></td><td><code>NNG_OPT_MAXTTL</code></td><td></td></tr>
<tr><td><code>NN_SUB_SUBSCRIBE</code></td><td><a href="migrate//TODO.html"><code>nng_sub0_socket_subscribe</code></a></td><td>No longer an option, use a function call.</td></tr>
<tr><td><code>NN_SUB_UNSUBSCRIBE</code></td><td><a href="migrate//TODO.html"><code>nng_sub0_socket_unsubscribe</code></a></td><td>No longer an option, use a function call.</td></tr>
</tbody></table>
</div>
<h2 id="error-codes"><a class="header" href="#error-codes">Error Codes</a></h2>
<p>Most of the error codes have similar names in NNG, just prefixed with <code>NNG_</code>.
There are some exceptions. Be aware that the numeric values are <em>not</em> the same.</p>
<div class="table-wrapper"><table><thead><tr><th>Nanomsg Error</th><th>NNG Error</th><th>Notes</th></tr></thead><tbody>
<tr><td><code>EINTR</code></td><td><a href="migrate//api/errors.html#NNG_EINTR"><code>NNG_EINTR</code></a></td><td></td></tr>
<tr><td><code>ENOMEM</code></td><td><a href="migrate//api/errors.html#NNG_ENOMEM"><code>NNG_ENOMEM</code></a></td><td></td></tr>
<tr><td><code>EINVAL</code></td><td><a href="migrate//api/errors.html#NNG_EINVAL"><code>NNG_EINVAL</code></a>, <a href="migrate//api/errors.html#NNG_EADDRINVAL"><code>NNG_EADDRINVAL</code></a>, <a href="migrate//api/errors.html#NNG_EBADTYPE"><code>NNG_EBADTYPE</code></a>, <a href="migrate//api/errors.html#NNG_EAMBIGUOUS"><code>NNG_EAMBIGUOUS</code></a></td><td>NNG discrimates between different types of errors.</td></tr>
<tr><td><code>EBUSY</code></td><td><a href="migrate//api/errors.html#NNG_EBUSY"><code>NNG_EBUSY</code></a></td><td></td></tr>
<tr><td><code>ETIMEDOUT</code></td><td><a href="migrate//api/errors.html#NNG_ETIMEDOUT"><code>NNG_ETIMEDOUT</code></a></td><td></td></tr>
<tr><td><code>ECONNREFUSED</code></td><td><a href="migrate//api/errors.html#NNG_ECONNREFUSED"><code>NNG_ECONNREFUSED</code></a></td><td></td></tr>
<tr><td><code>EBADF</code></td><td><a href="migrate//api/errors.html#NNG_ECLOSED"><code>NNG_ECLOSED</code></a>, <a href="migrate//api/errors.html#NNG_ECANCELED"><code>NNG_ECANCELED</code></a></td><td>Canceling an operation returns differently than using an invalid or closed object.</td></tr>
<tr><td><code>EAGAIN</code></td><td><a href="migrate//api/errors.html#NNG_EAGAIN"><code>NNG_EAGAIN</code></a></td><td></td></tr>
<tr><td><code>ENOTSUP</code></td><td><a href="migrate//api/errors.html#NNG_ENOTSUP"><code>NNG_ENOTSUP</code></a></td><td></td></tr>
<tr><td><code>EADDRINUSE</code></td><td><a href="migrate//api/errors.html#NNG_EADDRINUSE"><code>NNG_EADDRINUSE</code></a></td><td></td></tr>
<tr><td><code>EFSM</code></td><td><a href="migrate//api/errors.html#NNG_ESTATE"><code>NNG_ESTATE</code></a></td><td>Not a legal POSIX <em>errno</em> value.</td></tr>
<tr><td><code>ENOENT</code></td><td><a href="migrate//api/errors.html#NNG_ENOENT"><code>NNG_ENOENT</code></a></td><td></td></tr>
<tr><td><code>EPROTO</code></td><td><a href="migrate//api/errors.html#NNG_EPROTO"><code>NNG_EPROTO</code></a></td><td></td></tr>
<tr><td><code>EHOSTUNREACH</code></td><td><a href="migrate//api/errors.html#NNG_EUNREACHABLE"><code>NNG_EUNREACHABLE</code></a></td><td></td></tr>
<tr><td><code>EACCCES</code></td><td><a href="migrate//api/errors.html#NNG_EPERM"><code>NNG_EPERM</code></a>, <a href="migrate//api/errors.html#NNG_EWRITEONLY"><code>NNG_EWRITEONLY</code></a>, <a href="migrate//api/errors.html#NNG_EREADONLY"><code>NNG_EREADONLY</code></a>, <a href="migrate//api/errors.html#NNG_ECRYPTO"><code>NNG_ECRYPTO</code></a>, <a href="migrate//api/errors.html#NNG_EPEERAUTH"><code>NNG_EPEERAUTH</code></a></td><td>NNG has more fine grained reasons for access failures.</td></tr>
<tr><td><code>EMSGSIZE</code></td><td><a href="migrate//api/errors.html#NNG_EMSGSIZE"><code>NNG_EMSGSIZE</code></a></td><td></td></tr>
<tr><td><code>ECONNABORTED</code></td><td><a href="migrate//api/errors.html#NNG_ECONNABORTED"><code>NNG_ECONNABORTED</code></a></td><td></td></tr>
<tr><td><code>ECONNRESET</code></td><td><a href="migrate//api/errors.html#NNG_ECONNRESET"><code>NNG_ECONNRESET</code></a></td><td></td></tr>
<tr><td><code>EEXIST</code></td><td><a href="migrate//api/errors.html#NNG_EEXIST"><code>NNG_EEXIST</code></a></td><td></td></tr>
<tr><td><code>EMFILE</code></td><td><a href="migrate//api/errors.html#NNG_ENOFILES"><code>NNG_ENOFILES</code></a></td><td></td></tr>
<tr><td><code>ENOSPC</code></td><td><a href="migrate//api/errors.html#NNG_ENOSPC"><code>NNG_ENOSPC</code></a></td><td></td></tr>
</tbody></table>
</div>
<h2 id="local-addresses-for-dialing"><a class="header" href="#local-addresses-for-dialing">Local Addresses for Dialing</a></h2>
<p>The ability to specify the source address in the UROL,to use when
using <code>nn_dial</code> inside the URL is not present in NNG. The correct
way to specify the local address is using the <code>NNG_OPT_LOCADDR</code> option on the
dialer before starting to dial.</p>
<!-- Symbol cross reference -->
<!-- Macros -->
<!-- Protocols -->
<!-- Transports -->
<!-- Concept index -->
<div style="break-before: page; page-break-before: always;"></div><h1 id="index"><a class="header" href="#index">Index</a></h1>
<p>ABI, <a href="api/misc.html#a009">1</a><br/>
abstract sockets, <a href="tran/ipc.html#a007">1</a><br/>
<code>abstract://</code>, <a href="tran/ipc.html#a008">1</a><br/>
<code>AF_UNIX</code>, <a href="api/misc.html#a003">1</a><br/>
aio, <a href="api/aio.html#a002">1</a><br/>
allocations, <a href="api/memory.html#a002">1</a><br/>
application binary interface, <a href="api/misc.html#a010">1</a><br/>
asynchronous I/O, <a href="api/aio.html#a003">1</a><br/>
back-pressure, <a href="proto/index.html#a005">1</a><br/>
backtrace, <a href="proto/rep.html#a004">1</a>, <a href="proto/req.html#a008">2</a>, <a href="proto/respondent.html#a004">3</a>, <a href="proto/surveyor.html#a008">4</a><br/>
best-effort, <a href="proto/bus.html#a003">1</a><br/>
body, <a href="api/msg.html#a002">1</a><br/>
<em>BUS</em>, <a href="proto/bus.html#a002">1</a><br/>
<em>BUS</em> protocol, <a href="proto/bus.html#a001">1</a><br/>
callback, <a href="api/aio.html#a005">1</a><br/>
clock, <a href="api/time.html#a008">1</a><br/>
command-line arguments, <a href="api/cmd_opts.html#a002">1</a><br/>
concurrency, <a href="api/thread.html#a002">1</a><br/>
condition variable, <a href="api/synch.html#a009">1</a><br/>
CPU-bound, <a href="api/thread.html#a003">1</a><br/>
duration, <a href="api/time.html#a003">1</a><br/>
error message, <a href="api/errors.html#a002">1</a><br/>
event loop, <a href="api/sock.html#a009">1</a><br/>
flow control, <a href="proto/index.html#a006">1</a><br/>
<code>getopt</code>, <a href="api/cmd_opts.html#a003">1</a><br/>
half-duplex, <a href="proto/index.html#a004">1</a><br/>
header, <a href="api/msg.html#a003">1</a><br/>
idempotent, <a href="proto/req.html#a004">1</a><br/>
<code>INADDR_ANY</code>, <a href="tran/udp.html#a007">1</a><br/>
<em>inproc</em>, <a href="tran/inproc.html#a002">1</a><br/>
<em>inproc</em> transport, <a href="tran/inproc.html#a001">1</a><br/>
<code>inproc://</code>, <a href="tran/inproc.html#a004">1</a><br/>
intra-process, <a href="tran/inproc.html#a003">1</a><br/>
<em>ipc</em>, <a href="tran/ipc.html#a002">1</a><br/>
<em>ipc</em> transport, <a href="tran/ipc.html#a001">1</a><br/>
<code>ipc://</code>, <a href="tran/ipc.html#a005">1</a><br/>
IPv4, <a href="tran/udp.html#a003">1</a><br/>
IPv6, <a href="tran/udp.html#a004">1</a><br/>
leader election, <a href="proto/surveyor.html#a005">1</a><br/>
load-balancing, <a href="proto/pull.html#a004">1</a>, <a href="proto/push.html#a004">2</a>, <a href="proto/req.html#a005">3</a><br/>
Log handlers, <a href="api/logging.html#a007">1</a><br/>
memory, <a href="api/memory.html#a001">1</a><br/>
messages, <a href="api/msg.html#a001">1</a><br/>
MTU, <a href="tran/udp.html#a008">1</a><br/>
mutex, <a href="api/synch.html#a002">1</a><br/>
named pipes, <a href="tran/ipc.html#a004">1</a><br/>
<code>NNG_AF_UNSPEC</code>, <a href="tran/socket.html#a004">1</a><br/>
<code>nng_aio</code>, <a href="api/aio.html#a001">1</a><br/>
<code>nng_aio_abort</code>, <a href="api/aio.html#a008">1</a><br/>
<code>nng_aio_alloc</code>, <a href="api/aio.html#a004">1</a><br/>
<code>nng_aio_busy</code>, <a href="api/aio.html#a015">1</a><br/>
<code>nng_aio_cancel</code>, <a href="api/aio.html#a009">1</a><br/>
<code>nng_aio_count</code>, <a href="api/aio.html#a017">1</a><br/>
<code>nng_aio_free</code>, <a href="api/aio.html#a006">1</a><br/>
<code>nng_aio_get_msg</code>, <a href="api/aio.html#a018">1</a><br/>
<code>nng_aio_reap</code>, <a href="api/aio.html#a007">1</a><br/>
<code>nng_aio_result</code>, <a href="api/aio.html#a016">1</a><br/>
<code>nng_aio_set_expire</code>, <a href="api/aio.html#a013">1</a><br/>
<code>nng_aio_set_iov</code>, <a href="api/aio.html#a021">1</a><br/>
<code>nng_aio_set_msg</code>, <a href="api/aio.html#a019">1</a><br/>
<code>nng_aio_stop</code>, <a href="api/aio.html#a011">1</a><br/>
<code>nng_aio_wait</code>, <a href="api/aio.html#a014">1</a><br/>
<code>nng_alloc</code>, <a href="api/memory.html#a003">1</a><br/>
<code>nng_clock</code>, <a href="api/time.html#a007">1</a><br/>
<code>nng_cv</code>, <a href="api/synch.html#a008">1</a><br/>
<code>nng_cv_alloc</code>, <a href="api/synch.html#a010">1</a><br/>
<code>nng_cv_free</code>, <a href="api/synch.html#a011">1</a><br/>
<code>nng_cv_until</code>, <a href="api/synch.html#a012">1</a><br/>
<code>nng_cv_wait</code>, <a href="api/synch.html#a013">1</a><br/>
<code>nng_cv_wake</code>, <a href="api/synch.html#a014">1</a><br/>
<code>nng_cv_wake1</code>, <a href="api/synch.html#a015">1</a><br/>
<code>nng_duration</code>, <a href="api/time.html#a002">1</a><br/>
<code>NNG_DURATION_DEFAULT</code>, <a href="api/time.html#a005">1</a><br/>
<code>NNG_DURATION_INFINITE</code>, <a href="api/time.html#a004">1</a><br/>
<code>NNG_DURATION_ZERO</code>, <a href="api/time.html#a006">1</a><br/>
<code>NNG_ECANCELED</code>, <a href="api/aio.html#a010">1</a><br/>
<code>nng_fini</code>, <a href="api/init.html#a002">1</a><br/>
<code>nng_free</code>, <a href="api/memory.html#a004">1</a><br/>
<code>nng_id_alloc</code>, <a href="api/id_map.html#a006">1</a><br/>
<code>nng_id_get</code>, <a href="api/id_map.html#a005">1</a><br/>
<code>nng_id_map</code>, <a href="api/id_map.html#a001">1</a><br/>
<code>nng_id_map_alloc</code>, <a href="api/id_map.html#a002">1</a><br/>
<code>nng_id_map_free</code>, <a href="api/id_map.html#a003">1</a><br/>
<code>nng_id_map_set</code>, <a href="api/id_map.html#a004">1</a><br/>
<code>nng_id_remove</code>, <a href="api/id_map.html#a007">1</a><br/>
<code>nng_id_visit</code>, <a href="api/id_map.html#a008">1</a><br/>
<code>nng_init</code>, <a href="api/init.html#a001">1</a><br/>
<code>nng_iov</code>, <a href="api/aio.html#a020">1</a><br/>
<code>nng_log</code>, <a href="api/logging.html#a001">1</a><br/>
<code>nng_log_auth</code>, <a href="api/logging.html#a002">1</a><br/>
<code>nng_log_get_level</code>, <a href="api/logging.html#a005">1</a><br/>
<code>nng_log_level</code>, <a href="api/logging.html#a003">1</a><br/>
<code>nng_log_set_facility</code>, <a href="api/logging.html#a006">1</a><br/>
<code>nng_log_set_level</code>, <a href="api/logging.html#a004">1</a><br/>
<code>nng_log_set_logger</code>, <a href="api/logging.html#a008">1</a><br/>
<code>nng_logger</code>, <a href="api/logging.html#a009">1</a><br/>
<code>NNG_MAJOR_VERSION</code>, <a href="api/misc.html#a006">1</a><br/>
<code>NNG_MINOR_VERSION</code>, <a href="api/misc.html#a007">1</a><br/>
<code>nng_msg</code>, <a href="api/msg.html#a004">1</a><br/>
<code>nng_msg_alloc</code>, <a href="api/msg.html#a005">1</a><br/>
<code>nng_msg_append</code>, <a href="api/msg.html#a014">1</a><br/>
<code>nng_msg_body</code>, <a href="api/msg.html#a011">1</a><br/>
<code>nng_msg_capacity</code>, <a href="api/msg.html#a008">1</a><br/>
<code>nng_msg_chop</code>, <a href="api/msg.html#a016">1</a><br/>
<code>nng_msg_clear</code>, <a href="api/msg.html#a013">1</a><br/>
<code>nng_msg_dup</code>, <a href="api/msg.html#a007">1</a><br/>
<code>nng_msg_free</code>, <a href="api/msg.html#a006">1</a><br/>
<code>nng_msg_get_pipe</code>, <a href="api/msg.html#a026">1</a><br/>
<code>nng_msg_header</code>, <a href="api/msg.html#a018">1</a><br/>
<code>nng_msg_header_append</code>, <a href="api/msg.html#a021">1</a><br/>
<code>nng_msg_header_chop</code>, <a href="api/msg.html#a024">1</a><br/>
<code>nng_msg_header_clear</code>, <a href="api/msg.html#a020">1</a><br/>
<code>nng_msg_header_insert</code>, <a href="api/msg.html#a022">1</a><br/>
<code>nng_msg_header_len</code>, <a href="api/msg.html#a019">1</a><br/>
<code>nng_msg_header_trim</code>, <a href="api/msg.html#a023">1</a><br/>
<code>nng_msg_insert</code>, <a href="api/msg.html#a015">1</a><br/>
<code>nng_msg_len</code>, <a href="api/msg.html#a012">1</a><br/>
<code>nng_msg_realloc</code>, <a href="api/msg.html#a009">1</a><br/>
<code>nng_msg_reserve</code>, <a href="api/msg.html#a010">1</a><br/>
<code>nng_msg_set_pipe</code>, <a href="api/msg.html#a025">1</a><br/>
<code>nng_msg_trim</code>, <a href="api/msg.html#a017">1</a><br/>
<code>nng_msleep</code>, <a href="api/time.html#a009">1</a><br/>
<code>nng_mtx</code>, <a href="api/synch.html#a003">1</a><br/>
<code>nng_mtx_free</code>, <a href="api/synch.html#a005">1</a><br/>
<code>nng_mtx_lock</code>, <a href="api/synch.html#a004">1</a>, <a href="api/synch.html#a006">2</a><br/>
<code>nng_mtx_unlock</code>, <a href="api/synch.html#a007">1</a><br/>
<code>nng_null_logger</code>, <a href="api/logging.html#a010">1</a><br/>
<code>NNG_OPT_LOCADDR</code>, <a href="tran/ipc.html#a009">1</a><br/>
<code>NNG_OPT_PEER_UID</code>, <a href="tran/ipc.html#a010">1</a><br/>
<code>NNG_OPT_REQ_RESENDTICK</code>, <a href="proto/req.html#a007">1</a><br/>
<code>NNG_OPT_REQ_RESENDTIME</code>, <a href="proto/req.html#a006">1</a><br/>
<code>NNG_OPT_SOCKET_FD</code>, <a href="tran/socket.html#a002">1</a>, <a href="tran/socket.html#a005">2</a><br/>
<code>NNG_OPT_SUB_PREFNEW</code>, <a href="proto/sub.html#a004">1</a><br/>
<code>NNG_OPT_SURVEYOR_SURVEYTIME</code>, <a href="proto/surveyor.html#a007">1</a><br/>
<code>nng_opts_parse</code>, <a href="api/cmd_opts.html#a001">1</a><br/>
<code>nng_optspec</code>, <a href="api/cmd_opts.html#a004">1</a><br/>
<code>NNG_PATCH_VERSION</code>, <a href="api/misc.html#a008">1</a><br/>
<code>nng_random</code>, <a href="api/misc.html#a001">1</a><br/>
<code>nng_sleep_aio</code>, <a href="api/time.html#a011">1</a><br/>
<code>nng_socket</code>, <a href="api/sock.html#a002">1</a><br/>
<code>nng_socket_get_recv_poll_fd</code>, <a href="api/sock.html#a010">1</a><br/>
<code>nng_socket_get_send_poll_fd</code>, <a href="api/sock.html#a011">1</a><br/>
<code>nng_socket_id</code>, <a href="api/sock.html#a003">1</a><br/>
<code>nng_socket_peer_id</code>, <a href="api/sock.html#a005">1</a><br/>
<code>nng_socket_peer_name</code>, <a href="api/sock.html#a007">1</a><br/>
<code>nng_socket_proto_id</code>, <a href="api/sock.html#a004">1</a><br/>
<code>nng_socket_proto_name</code>, <a href="api/sock.html#a006">1</a><br/>
<code>nng_socket_raw</code>, <a href="api/sock.html#a008">1</a><br/>
<code>nng_stat</code>, <a href="api/stats.html#a002">1</a><br/>
<code>nng_stat_bool</code>, <a href="api/stats.html#a021">1</a><br/>
<code>NNG_STAT_BOOLEAN</code>, <a href="api/stats.html#a018">1</a><br/>
<code>nng_stat_child</code>, <a href="api/stats.html#a005">1</a><br/>
<code>NNG_STAT_COUNTER</code>, <a href="api/stats.html#a015">1</a><br/>
<code>nng_stat_desc</code>, <a href="api/stats.html#a012">1</a><br/>
<code>nng_stat_find</code>, <a href="api/stats.html#a007">1</a><br/>
<code>nng_stat_find_dialer</code>, <a href="api/stats.html#a008">1</a><br/>
<code>nng_stat_find_listener</code>, <a href="api/stats.html#a009">1</a><br/>
<code>nng_stat_find_socket</code>, <a href="api/stats.html#a010">1</a><br/>
<code>NNG_STAT_ID</code>, <a href="api/stats.html#a019">1</a><br/>
<code>NNG_STAT_LEVEL</code>, <a href="api/stats.html#a016">1</a><br/>
<code>nng_stat_name</code>, <a href="api/stats.html#a011">1</a><br/>
<code>nng_stat_next</code>, <a href="api/stats.html#a006">1</a><br/>
<code>NNG_STAT_SCOPE</code>, <a href="api/stats.html#a014">1</a><br/>
<code>NNG_STAT_STRING</code>, <a href="api/stats.html#a017">1</a><br/>
<code>nng_stat_string</code>, <a href="api/stats.html#a022">1</a><br/>
<code>nng_stat_timestamp</code>, <a href="api/stats.html#a029">1</a><br/>
<code>nng_stat_type</code>, <a href="api/stats.html#a013">1</a><br/>
<code>nng_stat_unit</code>, <a href="api/stats.html#a023">1</a><br/>
<code>nng_stat_value</code>, <a href="api/stats.html#a020">1</a><br/>
<code>nng_stats_free</code>, <a href="api/stats.html#a004">1</a><br/>
<code>nng_stats_get</code>, <a href="api/stats.html#a003">1</a><br/>
<code>nng_stderr_logger</code>, <a href="api/logging.html#a011">1</a><br/>
<code>nng_strdup</code>, <a href="api/memory.html#a005">1</a><br/>
<code>nng_strerror</code>, <a href="api/errors.html#a001">1</a><br/>
<code>nng_strfree</code>, <a href="api/memory.html#a006">1</a><br/>
<code>nng_system_logger</code>, <a href="api/logging.html#a012">1</a><br/>
<code>nng_thread</code>, <a href="api/thread.html#a004">1</a><br/>
<code>nng_thread_create</code>, <a href="api/thread.html#a005">1</a><br/>
<code>nng_thread_destroy</code>, <a href="api/thread.html#a006">1</a><br/>
<code>nng_thread_set_name</code>, <a href="api/thread.html#a007">1</a><br/>
<code>nng_time</code>, <a href="api/time.html#a001">1</a><br/>
<code>NNG_UNIT_BYTES</code>, <a href="api/stats.html#a025">1</a><br/>
<code>NNG_UNIT_EVENTS</code>, <a href="api/stats.html#a028">1</a><br/>
<code>NNG_UNIT_MESSAGES</code>, <a href="api/stats.html#a026">1</a><br/>
<code>NNG_UNIT_MILLIS</code>, <a href="api/stats.html#a027">1</a><br/>
<code>NNG_UNIT_NONE</code>, <a href="api/stats.html#a024">1</a><br/>
<code>nng_url_clone</code>, <a href="api/url.html#a012">1</a><br/>
<code>nng_url_fragment</code>, <a href="api/url.html#a009">1</a><br/>
<code>nng_url_free</code>, <a href="api/url.html#a013">1</a><br/>
<code>nng_url_hostname</code>, <a href="api/url.html#a005">1</a><br/>
<code>nng_url_parse</code>, <a href="api/url.html#a011">1</a><br/>
<code>nng_url_path</code>, <a href="api/url.html#a007">1</a><br/>
<code>nng_url_port</code>, <a href="api/url.html#a006">1</a><br/>
<code>nng_url_query</code>, <a href="api/url.html#a008">1</a><br/>
<code>nng_url_scheme</code>, <a href="api/url.html#a003">1</a><br/>
<code>nng_url_sprintf</code>, <a href="api/url.html#a010">1</a><br/>
<code>nng_url_userinfo</code>, <a href="api/url.html#a004">1</a><br/>
<code>nng_version</code>, <a href="api/misc.html#a004">1</a><br/>
<em>PAIR</em>, <a href="proto/pair.html#a002">1</a><br/>
<em>PAIR</em> protocol, <a href="proto/pair.html#a001">1</a><br/>
pipeline pattern, <a href="proto/pull.html#a003">1</a>, <a href="proto/push.html#a003">2</a>, <a href="proto/index.html#a003">3</a><br/>
polyamorous mode, <a href="proto/pair.html#a003">1</a><br/>
port number, <a href="tran/udp.html#a006">1</a><br/>
protocol, <a href="proto/index.html#a001">1</a><br/>
<em>PUB</em>, <a href="proto/pub.html#a002">1</a><br/>
<em>PUB</em> protocol, <a href="proto/pub.html#a001">1</a><br/>
publisher, <a href="proto/pub.html#a003">1</a><br/>
<em>PULL</em>, <a href="proto/pull.html#a002">1</a><br/>
<em>PULL</em> protocol, <a href="proto/pull.html#a001">1</a><br/>
<em>PUSH</em>, <a href="proto/push.html#a002">1</a><br/>
<em>PUSH</em> protocol, <a href="proto/push.html#a001">1</a><br/>
random number, <a href="api/misc.html#a002">1</a><br/>
<em>REP</em>, <a href="proto/rep.html#a002">1</a><br/>
<em>REP</em> protocol, <a href="proto/rep.html#a001">1</a><br/>
<em>REQ</em>, <a href="proto/req.html#a002">1</a><br/>
<em>REQ</em> protocol, <a href="proto/req.html#a001">1</a><br/>
request/reply pattern, <a href="proto/rep.html#a003">1</a>, <a href="proto/req.html#a003">2</a>, <a href="proto/index.html#a002">3</a><br/>
<em>RESPONDENT</em>, <a href="proto/respondent.html#a002">1</a><br/>
<em>RESPONDENT</em> protocol, <a href="proto/respondent.html#a001">1</a><br/>
scheduling, <a href="api/time.html#a010">1</a><br/>
service discovery, <a href="proto/surveyor.html#a006">1</a><br/>
socket, <a href="api/sock.html#a001">1</a><br/>
<em>socket</em> transport, <a href="tran/socket.html#a001">1</a><br/>
<code>socket://</code>, <a href="tran/socket.html#a003">1</a><br/>
statistics, <a href="api/stats.html#a001">1</a><br/>
<em>SUB</em>, <a href="proto/sub.html#a002">1</a><br/>
<em>SUB</em> protocol, <a href="proto/sub.html#a001">1</a><br/>
subscriber, <a href="proto/sub.html#a003">1</a><br/>
survey pattern, <a href="proto/respondent.html#a003">1</a>, <a href="proto/surveyor.html#a003">2</a><br/>
<em>SURVEYOR</em>, <a href="proto/surveyor.html#a002">1</a><br/>
<em>SURVEYOR</em> protocol, <a href="proto/surveyor.html#a001">1</a><br/>
synchronization primitives, <a href="api/synch.html#a001">1</a><br/>
threads, <a href="api/thread.html#a001">1</a><br/>
thundering herd, <a href="api/synch.html#a016">1</a><br/>
timeout, <a href="api/aio.html#a012">1</a><br/>
UDP, <a href="tran/udp.html#a002">1</a><br/>
<em>udp</em> transport, <a href="tran/udp.html#a001">1</a><br/>
<code>udp://</code>, <a href="tran/udp.html#a005">1</a><br/>
Universal Resource Locator, <a href="api/url.html#a001">1</a><br/>
UNIX domain sockets, <a href="tran/ipc.html#a003">1</a><br/>
<code>unix://</code>, <a href="tran/ipc.html#a006">1</a><br/>
URL, <a href="api/url.html#a002">1</a><br/>
version number, <a href="api/misc.html#a005">1</a><br/>
voting, <a href="proto/surveyor.html#a004">1</a><br/></p>
</main>
<nav class="nav-wrapper" aria-label="Page navigation">
<!-- Mobile navigation buttons -->
<div style="clear: both"></div>
</nav>
</div>
</div>
<nav class="nav-wide-wrapper" aria-label="Page navigation">
</nav>
</div>
<script>
window.playground_copyable = true;
</script>
<script src="elasticlunr.min.js"></script>
<script src="mark.min.js"></script>
<script src="searcher.js"></script>
<script src="clipboard.min.js"></script>
<script src="highlight.js"></script>
<script src="book.js"></script>
<!-- Custom JS scripts -->
<script src="theme/pagetoc.js"></script>
<script>
window.addEventListener('load', function() {
window.setTimeout(window.print, 100);
});
</script>
</div>
</body>
</html>
|