-
Notifications
You must be signed in to change notification settings - Fork 157
/
libdill.h
1123 lines (984 loc) · 34.4 KB
/
libdill.h
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
/*
Copyright (c) 2017 Martin Sustrik
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:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
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.
*/
#ifndef LIBDILL_H_INCLUDED
#define LIBDILL_H_INCLUDED
#include <errno.h>
#include <setjmp.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>
#if defined __linux__
#include <alloca.h>
#endif
/******************************************************************************/
/* ABI versioning support */
/******************************************************************************/
/* Don't change this unless you know exactly what you're doing and have */
/* read and understood the following documents: */
/* www.gnu.org/software/libtool/manual/html_node/Libtool-versioning.html */
/* www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html */
/* The current interface version. */
#define DILL_VERSION_CURRENT 25
/* The latest revision of the current interface. */
#define DILL_VERSION_REVISION 0
/* How many past interface versions are still supported. */
#define DILL_VERSION_AGE 5
/******************************************************************************/
/* Symbol visibility */
/******************************************************************************/
#if !defined __GNUC__ && !defined __clang__
#error "Unsupported compiler!"
#endif
#if DILL_NO_EXPORTS
#define DILL_EXPORT
#else
#define DILL_EXPORT __attribute__ ((visibility("default")))
#endif
/* Old versions of GCC don't support visibility attribute. */
#if defined __GNUC__ && __GNUC__ < 4
#undef DILL_EXPORT
#define DILL_EXPORT
#endif
#ifdef __cplusplus
extern "C" {
#endif
/******************************************************************************/
/* Memory alignment */
/******************************************************************************/
/* Opaque structures will violate alignments and cause crashes on certain
architectures
*/
#if (defined __arm__) || (defined __thumb__)
#define DILL_ALIGN __attribute__ ((aligned(__SIZEOF_POINTER__)))
#else
#define DILL_ALIGN
#endif
/******************************************************************************/
/* Helpers */
/******************************************************************************/
DILL_EXPORT int dill_fdclean(int fd);
DILL_EXPORT int dill_fdin(int fd, int64_t deadline);
DILL_EXPORT int dill_fdout(int fd, int64_t deadline);
DILL_EXPORT int64_t dill_now(void);
DILL_EXPORT int dill_msleep(int64_t deadline);
#if !defined DILL_DISABLE_RAW_NAMES
#define fdclean dill_fdclean
#define fdin dill_fdin
#define fdout dill_fdout
#define now dill_now
#define msleep dill_msleep
#endif
/******************************************************************************/
/* Handles */
/******************************************************************************/
DILL_EXPORT int dill_hown(int h);
DILL_EXPORT int dill_hclose(int h);
#if !defined DILL_DISABLE_RAW_NAMES
#define hown dill_hown
#define hclose dill_hclose
#endif
/******************************************************************************/
/* Coroutines */
/******************************************************************************/
#define dill_coroutine __attribute__((noinline))
DILL_EXPORT extern volatile void *dill_unoptimisable;
DILL_EXPORT __attribute__((noinline)) int dill_prologue(sigjmp_buf **ctx,
void **ptr, size_t len, int bndl, const char *file, int line);
DILL_EXPORT __attribute__((noinline)) void dill_epilogue(void);
/* The following macros use alloca(sizeof(size_t)) because clang
doesn't support alloca with size zero. */
/* This assembly setjmp/longjmp mechanism is in the same order as glibc and
musl, but glibc implements pointer mangling, which is hard to support.
This should be binary-compatible with musl, though. */
/* Stack-switching on X86-64. */
#if defined(__x86_64__) && !defined DILL_ARCH_FALLBACK
#define dill_setjmp(ctx) __extension__ ({\
int ret;\
asm("lea LJMPRET%=(%%rip), %%rcx\n\t"\
"xor %%rax, %%rax\n\t"\
"mov %%rbx, (%%rdx)\n\t"\
"mov %%rbp, 8(%%rdx)\n\t"\
"mov %%r12, 16(%%rdx)\n\t"\
"mov %%r13, 24(%%rdx)\n\t"\
"mov %%r14, 32(%%rdx)\n\t"\
"mov %%r15, 40(%%rdx)\n\t"\
"mov %%rsp, 48(%%rdx)\n\t"\
"mov %%rcx, 56(%%rdx)\n\t"\
"LJMPRET%=:\n\t"\
: "=a" (ret)\
: "d" (ctx)\
: "memory", "rcx", "rsi", "rdi", "r8", "r9", "r10", "r11", "cc");\
ret;\
})
#define dill_longjmp(ctx) \
asm("movq 56(%%rdx), %%rcx\n\t"\
"movq 48(%%rdx), %%rsp\n\t"\
"movq 40(%%rdx), %%r15\n\t"\
"movq 32(%%rdx), %%r14\n\t"\
"movq 24(%%rdx), %%r13\n\t"\
"movq 16(%%rdx), %%r12\n\t"\
"movq 8(%%rdx), %%rbp\n\t"\
"movq (%%rdx), %%rbx\n\t"\
".cfi_def_cfa %%rdx, 0 \n\t"\
".cfi_offset %%rbx, 0 \n\t"\
".cfi_offset %%rbp, 8 \n\t"\
".cfi_offset %%r12, 16 \n\t"\
".cfi_offset %%r13, 24 \n\t"\
".cfi_offset %%r14, 32 \n\t"\
".cfi_offset %%r15, 40 \n\t"\
".cfi_offset %%rsp, 48 \n\t"\
".cfi_offset %%rip, 56 \n\t"\
"jmp *%%rcx\n\t"\
: : "d" (ctx), "a" (1))
#define dill_setsp(x) \
asm(""::"r"(alloca(sizeof(size_t))));\
asm volatile("leaq (%%rax), %%rsp"::"rax"(x));
/* Stack switching on X86. */
#elif defined(__i386__) && !defined DILL_ARCH_FALLBACK
#define dill_setjmp(ctx) __extension__ ({\
int ret;\
asm("movl $LJMPRET%=, %%ecx\n\t"\
"movl %%ebx, (%%edx)\n\t"\
"movl %%esi, 4(%%edx)\n\t"\
"movl %%edi, 8(%%edx)\n\t"\
"movl %%ebp, 12(%%edx)\n\t"\
"movl %%esp, 16(%%edx)\n\t"\
"movl %%ecx, 20(%%edx)\n\t"\
"xorl %%eax, %%eax\n\t"\
"LJMPRET%=:\n\t"\
: "=a" (ret) : "d" (ctx) : "memory");\
ret;\
})
#define dill_longjmp(ctx) \
asm("movl (%%edx), %%ebx\n\t"\
"movl 4(%%edx), %%esi\n\t"\
"movl 8(%%edx), %%edi\n\t"\
"movl 12(%%edx), %%ebp\n\t"\
"movl 16(%%edx), %%esp\n\t"\
"movl 20(%%edx), %%ecx\n\t"\
".cfi_def_cfa %%edx, 0 \n\t"\
".cfi_offset %%ebx, 0 \n\t"\
".cfi_offset %%esi, 4 \n\t"\
".cfi_offset %%edi, 8 \n\t"\
".cfi_offset %%ebp, 12 \n\t"\
".cfi_offset %%esp, 16 \n\t"\
".cfi_offset %%eip, 20 \n\t"\
"jmp *%%ecx\n\t"\
: : "d" (ctx), "a" (1))
#define dill_setsp(x) \
asm(""::"r"(alloca(sizeof(size_t))));\
asm volatile("leal (%%eax), %%esp"::"eax"(x));
/* Stack-switching on other microarchitectures. */
#else
#define dill_setjmp(ctx) sigsetjmp(ctx, 0)
#define dill_longjmp(ctx) siglongjmp(ctx, 1)
/* For newer GCCs, -fstack-protector breaks on this; use -fno-stack-protector.
Alternatively, implement a custom dill_setsp for your microarchitecture. */
#define dill_setsp(x) \
dill_unoptimisable = alloca((char*)alloca(sizeof(size_t)) - (char*)(x));
#endif
/* Statement expressions are a gcc-ism but they are also supported by clang.
Given that there's no other way to do this, screw other compilers for now.
See https://gcc.gnu.org/onlinedocs/gcc-3.2/gcc/Statement-Exprs.html */
/* A bug in gcc have been observed where name clash between variable in the
outer scope and a local variable in this macro causes the variable to
get weird values. To avoid that, we use fancy names (dill_*__). */
#define dill_go_(fn, ptr, len, bndl) \
__extension__ ({\
sigjmp_buf *dill_ctx__;\
void *dill_stk__ = (ptr);\
int dill_handle__ = dill_prologue(&dill_ctx__, &dill_stk__, (len),\
(bndl), __FILE__, __LINE__);\
if(dill_handle__ >= 0) {\
if(!dill_setjmp(*dill_ctx__)) {\
dill_setsp(dill_stk__);\
fn;\
dill_epilogue();\
}\
}\
dill_handle__;\
})
#define dill_go(fn) dill_go_(fn, NULL, 0, -1)
#define dill_go_mem(fn, ptr, len) dill_go_(fn, ptr, len, -1)
#define dill_bundle_go(bndl, fn) dill_go_(fn, NULL, 0, bndl)
#define dill_bundle_go_mem(bndl, fn, ptr, len) dill_go_(fn, ptr, len, bndl)
struct dill_bundle_storage {char _[64];} DILL_ALIGN;
DILL_EXPORT int dill_bundle(void);
DILL_EXPORT int dill_bundle_mem(struct dill_bundle_storage *mem);
DILL_EXPORT int dill_bundle_wait(int h, int64_t deadline);
DILL_EXPORT int dill_yield(void);
#if !defined DILL_DISABLE_RAW_NAMES
#define coroutine dill_coroutine
#define go dill_go
#define go_mem dill_go_mem
#define bundle_go dill_bundle_go
#define bundle_go_mem dill_bundle_go_mem
#define bundle_storage dill_bundle_storage
#define bundle dill_bundle
#define bundle_mem dill_bundle_mem
#define bundle_wait dill_bundle_wait
#define yield dill_yield
#endif
/******************************************************************************/
/* Channels */
/******************************************************************************/
#define DILL_CHSEND 1
#define DILL_CHRECV 2
struct dill_chclause {
int op;
int ch;
void *val;
size_t len;
};
struct dill_chstorage {char _[144];} DILL_ALIGN;
DILL_EXPORT int dill_chmake(
int chv[2]);
DILL_EXPORT int dill_chmake_mem(
struct dill_chstorage *mem,
int chv[2]);
DILL_EXPORT int dill_chsend(
int ch,
const void *val,
size_t len,
int64_t deadline);
DILL_EXPORT int dill_chrecv(
int ch,
void *val,
size_t len,
int64_t deadline);
DILL_EXPORT int dill_chdone(
int ch);
DILL_EXPORT int dill_choose(
struct dill_chclause *clauses,
int nclauses,
int64_t deadline);
#if !defined DILL_DISABLE_RAW_NAMES
#define CHSEND DILL_CHSEND
#define CHRECV DILL_CHRECV
#define chclause dill_chclause
#define chstorage dill_chstorage
#define chmake dill_chmake
#define chmake_mem dill_chmake_mem
#define chsend dill_chsend
#define chrecv dill_chrecv
#define chdone dill_chdone
#define choose dill_choose
#endif
#if !defined DILL_DISABLE_SOCKETS
/******************************************************************************/
/* Gather/scatter list. */
/******************************************************************************/
struct dill_iolist {
void *iol_base;
size_t iol_len;
struct dill_iolist *iol_next;
int iol_rsvd;
};
#if !defined DILL_DISABLE_RAW_NAMES
#define iolist dill_iolist
#endif
/******************************************************************************/
/* Bytestream sockets. */
/******************************************************************************/
DILL_EXPORT int dill_bsend(
int s,
const void *buf,
size_t len,
int64_t deadline);
DILL_EXPORT int dill_brecv(
int s,
void *buf,
size_t len,
int64_t deadline);
DILL_EXPORT int dill_bsendl(
int s,
struct dill_iolist *first,
struct dill_iolist *last,
int64_t deadline);
DILL_EXPORT int dill_brecvl(
int s,
struct dill_iolist *first,
struct dill_iolist *last,
int64_t deadline);
#if !defined DILL_DISABLE_RAW_NAMES
#define bsend dill_bsend
#define brecv dill_brecv
#define bsendl dill_bsendl
#define brecvl dill_brecvl
#endif
/******************************************************************************/
/* Message sockets. */
/******************************************************************************/
DILL_EXPORT int dill_msend(
int s,
const void *buf,
size_t len,
int64_t deadline);
DILL_EXPORT ssize_t dill_mrecv(
int s,
void *buf,
size_t len,
int64_t deadline);
DILL_EXPORT int dill_msendl(
int s,
struct dill_iolist *first,
struct dill_iolist *last,
int64_t deadline);
DILL_EXPORT ssize_t dill_mrecvl(
int s,
struct dill_iolist *first,
struct dill_iolist *last,
int64_t deadline);
#if !defined DILL_DISABLE_RAW_NAMES
#define msend dill_msend
#define mrecv dill_mrecv
#define msendl dill_msendl
#define mrecvl dill_mrecvl
#endif
/******************************************************************************/
/* IP address resolution. */
/******************************************************************************/
struct sockaddr;
#define DILL_IPADDR_IPV4 1
#define DILL_IPADDR_IPV6 2
#define DILL_IPADDR_PREF_IPV4 3
#define DILL_IPADDR_PREF_IPV6 4
#define DILL_IPADDR_MAXSTRLEN 46
struct dill_ipaddr {char _[32];};
DILL_EXPORT int dill_ipaddr_local(
struct dill_ipaddr *addr,
const char *name,
int port,
int mode);
DILL_EXPORT int dill_ipaddr_remote(
struct dill_ipaddr *addr,
const char *name,
int port,
int mode,
int64_t deadline);
DILL_EXPORT int dill_ipaddr_remotes(
struct dill_ipaddr *addrs,
int naddrs,
const char *name,
int port,
int mode,
int64_t deadline);
DILL_EXPORT const char *dill_ipaddr_str(
const struct dill_ipaddr *addr,
char *ipstr);
DILL_EXPORT int dill_ipaddr_family(
const struct dill_ipaddr *addr);
DILL_EXPORT const struct sockaddr *dill_ipaddr_sockaddr(
const struct dill_ipaddr *addr);
DILL_EXPORT int dill_ipaddr_len(
const struct dill_ipaddr *addr);
DILL_EXPORT int dill_ipaddr_port(
const struct dill_ipaddr *addr);
DILL_EXPORT void dill_ipaddr_setport(
struct dill_ipaddr *addr,
int port);
DILL_EXPORT int dill_ipaddr_equal(
const struct dill_ipaddr *addr1,
const struct dill_ipaddr *addr2,
int ignore_port);
#if !defined DILL_DISABLE_RAW_NAMES
#define IPADDR_IPV4 DILL_IPADDR_IPV4
#define IPADDR_IPV6 DILL_IPADDR_IPV6
#define IPADDR_PREF_IPV4 DILL_IPADDR_PREF_IPV4
#define IPADDR_PREF_IPV6 DILL_IPADDR_PREF_IPV6
#define IPADDR_MAXSTRLEN DILL_IPADDR_MAXSTRLEN
#define ipaddr dill_ipaddr
#define ipaddr_local dill_ipaddr_local
#define ipaddr_remote dill_ipaddr_remote
#define ipaddr_remotes dill_ipaddr_remotes
#define ipaddr_str dill_ipaddr_str
#define ipaddr_family dill_ipaddr_family
#define ipaddr_sockaddr dill_ipaddr_sockaddr
#define ipaddr_len dill_ipaddr_len
#define ipaddr_port dill_ipaddr_port
#define ipaddr_setport dill_ipaddr_setport
#define ipaddr_equal dill_ipaddr_equal
#endif
/******************************************************************************/
/* TCP protocol. */
/******************************************************************************/
struct dill_tcp_listener_storage {char _[56];} DILL_ALIGN;
struct dill_tcp_storage {char _[72];} DILL_ALIGN;
DILL_EXPORT int dill_tcp_listen(
struct dill_ipaddr *addr,
int backlog);
DILL_EXPORT int dill_tcp_listen_mem(
struct dill_ipaddr *addr,
int backlog,
struct dill_tcp_listener_storage *mem);
DILL_EXPORT int dill_tcp_accept(
int s,
struct dill_ipaddr *addr,
int64_t deadline);
DILL_EXPORT int dill_tcp_accept_mem(
int s,
struct dill_ipaddr *addr,
struct dill_tcp_storage *mem,
int64_t deadline);
DILL_EXPORT int dill_tcp_connect(
const struct dill_ipaddr *addr,
int64_t deadline);
DILL_EXPORT int dill_tcp_connect_mem(
const struct dill_ipaddr *addr,
struct dill_tcp_storage *mem,
int64_t deadline);
DILL_EXPORT int dill_tcp_done(
int s,
int64_t deadline);
DILL_EXPORT int dill_tcp_close(
int s,
int64_t deadline);
DILL_EXPORT int dill_tcp_listener_fromfd(
int fd);
DILL_EXPORT int dill_tcp_listener_fromfd_mem(
int fd,
struct dill_tcp_listener_storage *mem);
DILL_EXPORT int dill_tcp_fromfd(
int fd);
DILL_EXPORT int dill_tcp_fromfd_mem(
int fd,
struct dill_tcp_storage *mem);
#if !defined DILL_DISABLE_RAW_NAMES
#define tcp_listener_storage dill_tcp_listener_storage
#define tcp_storage dill_tcp_storage
#define tcp_listen dill_tcp_listen
#define tcp_listen_mem dill_tcp_listen_mem
#define tcp_accept dill_tcp_accept
#define tcp_accept_mem dill_tcp_accept_mem
#define tcp_connect dill_tcp_connect
#define tcp_connect_mem dill_tcp_connect_mem
#define tcp_done dill_tcp_done
#define tcp_close dill_tcp_close
#define tcp_listener_fromfd dill_tcp_listener_fromfd
#define tcp_listener_fromfd_mem dill_tcp_listener_fromfd_mem
#define tcp_fromfd dill_tcp_fromfd
#define tcp_fromfd_mem dill_tcp_fromfd_mem
#endif
/******************************************************************************/
/* IPC protocol. */
/******************************************************************************/
struct dill_ipc_listener_storage {char _[24];} DILL_ALIGN;
struct dill_ipc_storage {char _[72];} DILL_ALIGN;
struct dill_ipc_pair_storage {char _[144];} DILL_ALIGN;
DILL_EXPORT int dill_ipc_listen(
const char *addr,
int backlog);
DILL_EXPORT int dill_ipc_listen_mem(
const char *addr,
int backlog,
struct dill_ipc_listener_storage *mem);
DILL_EXPORT int dill_ipc_accept(
int s,
int64_t deadline);
DILL_EXPORT int dill_ipc_accept_mem(
int s,
struct dill_ipc_storage *mem,
int64_t deadline);
DILL_EXPORT int dill_ipc_connect(
const char *addr,
int64_t deadline);
DILL_EXPORT int dill_ipc_connect_mem(
const char *addr,
struct dill_ipc_storage *mem,
int64_t deadline);
DILL_EXPORT int dill_ipc_sendfd(
int s,
int fd,
int64_t deadline);
DILL_EXPORT int dill_ipc_recvfd(
int s,
int64_t deadline);
DILL_EXPORT int dill_ipc_done(
int s,
int64_t deadline);
DILL_EXPORT int dill_ipc_close(
int s,
int64_t deadline);
DILL_EXPORT int dill_ipc_listener_fromfd(
int fd);
DILL_EXPORT int dill_ipc_listener_fromfd_mem(
int fd,
struct dill_ipc_listener_storage *mem);
DILL_EXPORT int dill_ipc_fromfd(
int fd);
DILL_EXPORT int dill_ipc_fromfd_mem(
int fd,
struct dill_ipc_storage *mem);
DILL_EXPORT int dill_ipc_pair(
int s[2]);
DILL_EXPORT int dill_ipc_pair_mem(
struct dill_ipc_pair_storage *mem,
int s[2]);
#if !defined DILL_DISABLE_RAW_NAMES
#define ipc_listener_storage dill_ipc_listener_storage
#define ipc_storage dill_ipc_storage
#define ipc_pair_storage dill_ipc_pair_storage
#define ipc_listen dill_ipc_listen
#define ipc_listen_mem dill_ipc_listen_mem
#define ipc_accept dill_ipc_accept
#define ipc_accept_mem dill_ipc_accept_mem
#define ipc_connect dill_ipc_connect
#define ipc_connect_mem dill_ipc_connect_mem
#define ipc_sendfd dill_ipc_sendfd
#define ipc_recvfd dill_ipc_recvfd
#define ipc_done dill_ipc_done
#define ipc_close dill_ipc_close
#define ipc_listener_fromfd dill_ipc_listener_fromfd
#define ipc_listener_fromfd_mem dill_ipc_listener_fromfd_mem
#define ipc_fromfd dill_ipc_fromfd
#define ipc_fromfd_mem dill_ipc_fromfd_mem
#define ipc_pair dill_ipc_pair
#define ipc_pair_mem dill_ipc_pair_mem
#endif
/******************************************************************************/
/* PREFIX protocol. */
/* Messages are prefixed by size. */
/******************************************************************************/
struct dill_prefix_storage {char _[56];} DILL_ALIGN;
#define DILL_PREFIX_BIG_ENDIAN 0
#define DILL_PREFIX_LITTLE_ENDIAN 1
DILL_EXPORT int dill_prefix_attach(
int s,
size_t hdrlen,
int flags);
DILL_EXPORT int dill_prefix_attach_mem(
int s,
size_t hdrlen,
int flags,
struct dill_prefix_storage *mem);
DILL_EXPORT int dill_prefix_detach(
int s);
#if !defined DILL_DISABLE_RAW_NAMES
#define PREFIX_BIG_ENDIAN DILL_PREFIX_BIG_ENDIAN
#define PREFIX_LITTLE_ENDIAN DILL_PREFIX_LITTLE_ENDIAN
#define prefix_storage dill_prefix_storage
#define prefix_attach dill_prefix_attach
#define prefix_attach_mem dill_prefix_attach_mem
#define prefix_detach dill_prefix_detach
#endif
/******************************************************************************/
/* SUFFIX protocol. */
/* Messages are suffixed by specified string of bytes. */
/******************************************************************************/
struct dill_suffix_storage {char _[128];} DILL_ALIGN;
DILL_EXPORT int dill_suffix_attach(
int s,
const void *suffix,
size_t suffixlen);
DILL_EXPORT int dill_suffix_attach_mem(
int s,
const void *suffix,
size_t suffixlen,
struct dill_suffix_storage *mem);
DILL_EXPORT int dill_suffix_detach(
int s,
int64_t deadline);
#if !defined DILL_DISABLE_RAW_NAMES
#define suffix_storage dill_suffix_storage
#define suffix_attach dill_suffix_attach
#define suffix_attach_mem dill_suffix_attach_mem
#define suffix_detach dill_suffix_detach
#endif
/******************************************************************************/
/* UDP protocol. */
/* Each UDP packet is treated as a separate message. */
/******************************************************************************/
struct dill_udp_storage {char _[72];} DILL_ALIGN;
DILL_EXPORT int dill_udp_open(
struct dill_ipaddr *local,
const struct dill_ipaddr *remote);
DILL_EXPORT int dill_udp_open_mem(
struct dill_ipaddr *local,
const struct dill_ipaddr *remote,
struct dill_udp_storage *mem);
DILL_EXPORT int dill_udp_send(
int s,
const struct dill_ipaddr *addr,
const void *buf,
size_t len);
DILL_EXPORT ssize_t dill_udp_recv(
int s,
struct dill_ipaddr *addr,
void *buf,
size_t len,
int64_t deadline);
DILL_EXPORT int dill_udp_sendl(
int s,
const struct dill_ipaddr *addr,
struct dill_iolist *first,
struct dill_iolist *last);
DILL_EXPORT ssize_t dill_udp_recvl(
int s,
struct dill_ipaddr *addr,
struct dill_iolist *first,
struct dill_iolist *last,
int64_t deadline);
#if !defined DILL_DISABLE_RAW_NAMES
#define udp_storage dill_udp_storage
#define udp_open dill_udp_open
#define udp_open_mem dill_udp_open_mem
#define udp_send dill_udp_send
#define udp_recv dill_udp_recv
#define udp_sendl dill_udp_sendl
#define udp_recvl dill_udp_recvl
#endif
/******************************************************************************/
/* HTTP */
/******************************************************************************/
struct dill_http_storage {char _[1296];} DILL_ALIGN;
DILL_EXPORT int dill_http_attach(
int s);
DILL_EXPORT int dill_http_attach_mem(
int s,
struct dill_http_storage *mem);
DILL_EXPORT int dill_http_done(
int s,
int64_t deadline);
DILL_EXPORT int dill_http_detach(
int s,
int64_t deadline);
DILL_EXPORT int dill_http_sendrequest(
int s,
const char *command,
const char *resource,
int64_t deadline);
DILL_EXPORT int dill_http_recvrequest(
int s,
char *command,
size_t commandlen,
char *resource,
size_t resourcelen,
int64_t deadline);
DILL_EXPORT int dill_http_sendstatus(
int s,
int status,
const char *reason,
int64_t deadline);
DILL_EXPORT int dill_http_recvstatus(
int s,
char *reason,
size_t reasonlen,
int64_t deadline);
DILL_EXPORT int dill_http_sendfield(
int s,
const char *name,
const char *value,
int64_t deadline);
DILL_EXPORT int dill_http_recvfield(
int s,
char *name,
size_t namelen,
char *value,
size_t valuelen,
int64_t deadline);
#if !defined DILL_DISABLE_RAW_NAMES
#define http_storage dill_http_storage
#define http_attach dill_http_attach
#define http_attach_mem dill_http_attach_mem
#define http_done dill_http_done
#define http_detach dill_http_detach
#define http_sendrequest dill_http_sendrequest
#define http_recvrequest dill_http_recvrequest
#define http_sendstatus dill_http_sendstatus
#define http_recvstatus dill_http_recvstatus
#define http_sendfield dill_http_sendfield
#define http_recvfield dill_http_recvfield
#endif
#if !defined DILL_DISABLE_TLS
/******************************************************************************/
/* TLS protocol. */
/******************************************************************************/
struct dill_tls_storage {char _[72];} DILL_ALIGN;
DILL_EXPORT int dill_tls_attach_server(
int s,
const char *cert,
const char *pkey,
int64_t deadline);
DILL_EXPORT int dill_tls_attach_server_mem(
int s,
const char *cert,
const char *pkey,
struct dill_tls_storage *mem,
int64_t deadline);
DILL_EXPORT int dill_tls_attach_client(
int s,
int64_t deadline);
DILL_EXPORT int dill_tls_attach_client_mem(
int s,
struct dill_tls_storage *mem,
int64_t deadline);
DILL_EXPORT int dill_tls_done(
int s,
int64_t deadline);
DILL_EXPORT int dill_tls_detach(
int s,
int64_t deadline);
#if !defined DILL_DISABLE_RAW_NAMES
#define tls_storage dill_tls_storage
#define tls_attach_server dill_tls_attach_server
#define tls_attach_server_mem dill_tls_attach_server_mem
#define tls_attach_client dill_tls_attach_client
#define tls_attach_client_mem dill_tls_attach_client_mem
#define tls_done dill_tls_done
#define tls_detach dill_tls_detach
#endif
/******************************************************************************/
/* DTLS protocol. */
/******************************************************************************/
struct dill_dtls_storage {char _[88];} DILL_ALIGN;
DILL_EXPORT int dill_dtls_attach_server(
int s,
const char *cert,
const char *pkey,
int64_t deadline);
DILL_EXPORT int dill_dtls_attach_server_mem(
int s,
const char *cert,
const char *pkey,
struct dill_dtls_storage *mem,
int64_t deadline);
DILL_EXPORT int dill_dtls_attach_client(
int s,
int64_t deadline);
DILL_EXPORT int dill_dtls_attach_client_mem(
int s,
struct dill_dtls_storage *mem,
int64_t deadline);
DILL_EXPORT int dill_dtls_done(
int s,
int64_t deadline);
DILL_EXPORT int dill_dtls_detach(
int s,
int64_t deadline);
#if !defined DILL_DISABLE_RAW_NAMES
#define dtls_storage dill_dtls_storage
#define dtls_attach_server dill_dtls_attach_server
#define dtls_attach_server_mem dill_dtls_attach_server_mem
#define dtls_attach_client dill_dtls_attach_client
#define dtls_attach_client_mem dill_dtls_attach_client_mem
#define dtls_done dill_dtls_done
#define dtls_detach dill_dtls_detach
#endif
#endif
/******************************************************************************/
/* WebSockets protocol. */
/******************************************************************************/
struct dill_ws_storage {char _[176];} DILL_ALIGN;
#define DILL_WS_BINARY 0
#define DILL_WS_TEXT 1
#define DILL_WS_NOHTTP 2
DILL_EXPORT int dill_ws_attach_client(
int s,
int flags,
const char *resource,
const char *host,
int64_t deadline);
DILL_EXPORT int dill_ws_attach_client_mem(
int s,
int flags,
const char *resource,
const char *host,
struct dill_ws_storage *mem,
int64_t deadline);
DILL_EXPORT int dill_ws_attach_server(
int s,
int flags,
char *resource,
size_t resourcelen,
char *host,
size_t hostlen,
int64_t deadline);
DILL_EXPORT int dill_ws_attach_server_mem(
int s,
int flags,
char *resource,
size_t resourcelen,
char *host,
size_t hostlen,
struct dill_ws_storage *mem,
int64_t deadline);
DILL_EXPORT int dill_ws_send(
int s,
int flags,
const void *buf,
size_t len,
int64_t deadline);
DILL_EXPORT ssize_t dill_ws_recv(
int s,
int *flags,
void *buf,
size_t len,
int64_t deadline);
DILL_EXPORT int dill_ws_sendl(
int s,
int flags,
struct dill_iolist *first,
struct dill_iolist *last,
int64_t deadline);
DILL_EXPORT ssize_t dill_ws_recvl(
int s,
int *flags,
struct dill_iolist *first,
struct dill_iolist *last,
int64_t deadline);
DILL_EXPORT int dill_ws_done(
int s,
int status,
const void *buf,
size_t len,
int64_t deadline);
DILL_EXPORT int dill_ws_detach(
int s,
int status,
const void *buf,
size_t len,
int64_t deadline);
DILL_EXPORT ssize_t dill_ws_status(
int s,
int *status,
void *buf,
size_t len);
/* Helper functions for those who want to implement HTTP exchange by hand. */
#define WS_KEY_SIZE 32
DILL_EXPORT int dill_ws_request_key(
char *request_key);
DILL_EXPORT int dill_ws_response_key(
const char *request_key,
char *response_key);
#if !defined DILL_DISABLE_RAW_NAMES
#define WS_BINARY DILL_WS_BINARY
#define WS_TEXT DILL_WS_TEXT
#define WS_NOHTTP DILL_WS_NOHTTP
#define ws_storage dill_ws_storage
#define ws_attach_server dill_ws_attach_server
#define ws_attach_server_mem dill_ws_attach_server_mem
#define ws_attach_client dill_ws_attach_client
#define ws_attach_client_mem dill_ws_attach_client_mem
#define ws_send dill_ws_send
#define ws_recv dill_ws_recv
#define ws_sendl dill_ws_sendl
#define ws_recvl dill_ws_recvl
#define ws_done dill_ws_done
#define ws_detach dill_ws_detach
#define ws_status dill_ws_status
#define ws_request_key dill_ws_request_key
#define ws_response_key dill_ws_response_key
#endif