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
|
.TH "event2/event.h" 3 "Tue Jan 27 2015" "libevent" \" -*- nroff -*-
.ad l
.nh
.SH NAME
event2/event.h \-
.PP
Core functions for waiting for and receiving events, and using event bases\&.
.SH SYNOPSIS
.br
.PP
\fC#include <event2/event-config\&.h>\fP
.br
\fC#include <stdio\&.h>\fP
.br
\fC#include <event2/util\&.h>\fP
.br
.SS "Data Structures"
.in +1c
.ti -1c
.RI "struct \fBevent\fP"
.br
.RI "\fIStructure to represent a single event\&. \fP"
.ti -1c
.RI "struct \fBevent_base\fP"
.br
.RI "\fIStructure to hold information and state for a Libevent dispatch loop\&. \fP"
.ti -1c
.RI "struct \fBevent_config\fP"
.br
.RI "\fIConfiguration for an \fBevent_base\fP\&. \fP"
.in -1c
.SS "Macros"
.in +1c
.ti -1c
.RI "#define \fB_EVENT_LOG_DEBUG\fP EVENT_LOG_DEBUG"
.br
.ti -1c
.RI "#define \fB_EVENT_LOG_ERR\fP EVENT_LOG_ERR"
.br
.ti -1c
.RI "#define \fB_EVENT_LOG_MSG\fP EVENT_LOG_MSG"
.br
.ti -1c
.RI "#define \fB_EVENT_LOG_WARN\fP EVENT_LOG_WARN"
.br
.ti -1c
.RI "#define \fBevent_get_signal\fP(ev) ((int)\fBevent_get_fd\fP(ev))"
.br
.RI "\fIGet the signal number assigned to a signal event\&. \fP"
.ti -1c
.RI "#define \fBEVENT_MAX_PRIORITIES\fP 256"
.br
.RI "\fILargest number of priorities that Libevent can support\&. \fP"
.ti -1c
.RI "#define \fBEVENT_SET_MEM_FUNCTIONS_IMPLEMENTED\fP"
.br
.RI "\fIThis definition is present if Libevent was built with support for \fBevent_set_mem_functions()\fP \fP"
.ti -1c
.RI "#define \fBLIBEVENT_VERSION\fP _EVENT_VERSION"
.br
.RI "\fIAs event_get_version, but gives the version of Libevent's headers\&. \fP"
.ti -1c
.RI "#define \fBLIBEVENT_VERSION_NUMBER\fP _EVENT_NUMERIC_VERSION"
.br
.RI "\fIAs event_get_version_number, but gives the version number of Libevent's headers\&. \fP"
.in -1c
.PP
.RI "\fBLog severities\fP"
.br
.in +1c
.in +1c
.ti -1c
.RI "#define \fBEVENT_LOG_DEBUG\fP 0"
.br
.ti -1c
.RI "#define \fBEVENT_LOG_MSG\fP 1"
.br
.ti -1c
.RI "#define \fBEVENT_LOG_WARN\fP 2"
.br
.ti -1c
.RI "#define \fBEVENT_LOG_ERR\fP 3"
.br
.in -1c
.in -1c
.PP
.RI "\fBLoop flags\fP"
.br
These flags control the behavior of \fBevent_base_loop()\fP\&.
.PP
.in +1c
.in +1c
.ti -1c
.RI "#define \fBEVLOOP_ONCE\fP 0x01"
.br
.RI "\fIBlock until we have an active event, then exit once all active events have had their callbacks run\&. \fP"
.ti -1c
.RI "#define \fBEVLOOP_NONBLOCK\fP 0x02"
.br
.RI "\fIDo not block: see which events are ready now, run the callbacks of the highest-priority ones, then exit\&. \fP"
.in -1c
.in -1c
.PP
.RI "\fBevent flags\fP"
.br
Flags to pass to \fBevent_new()\fP, \fBevent_assign()\fP, \fBevent_pending()\fP, and anything else with an argument of the form 'short events'
.PP
.in +1c
.in +1c
.ti -1c
.RI "#define \fBEV_TIMEOUT\fP 0x01"
.br
.RI "\fIIndicates that a timeout has occurred\&. \fP"
.ti -1c
.RI "#define \fBEV_READ\fP 0x02"
.br
.RI "\fIWait for a socket or FD to become readable\&. \fP"
.ti -1c
.RI "#define \fBEV_WRITE\fP 0x04"
.br
.RI "\fIWait for a socket or FD to become writeable\&. \fP"
.ti -1c
.RI "#define \fBEV_SIGNAL\fP 0x08"
.br
.RI "\fIWait for a POSIX signal to be raised\&. \fP"
.ti -1c
.RI "#define \fBEV_PERSIST\fP 0x10"
.br
.RI "\fIPersistent event: won't get removed automatically when activated\&. \fP"
.ti -1c
.RI "#define \fBEV_ET\fP 0x20"
.br
.RI "\fISelect edge-triggered behavior, if supported by the backend\&. \fP"
.in -1c
.in -1c
.PP
.RI "\fBevtimer_* macros\fP"
.br
Aliases for working with one-shot timer events
.PP
.in +1c
.in +1c
.ti -1c
.RI "#define \fBevtimer_assign\fP(ev, b, cb, arg) \fBevent_assign\fP((ev), (b), -1, 0, (cb), (arg))"
.br
.ti -1c
.RI "#define \fBevtimer_new\fP(b, cb, arg) \fBevent_new\fP((b), -1, 0, (cb), (arg))"
.br
.ti -1c
.RI "#define \fBevtimer_add\fP(ev, tv) \fBevent_add\fP((ev), (tv))"
.br
.ti -1c
.RI "#define \fBevtimer_del\fP(ev) \fBevent_del\fP(ev)"
.br
.ti -1c
.RI "#define \fBevtimer_pending\fP(ev, tv) \fBevent_pending\fP((ev), \fBEV_TIMEOUT\fP, (tv))"
.br
.ti -1c
.RI "#define \fBevtimer_initialized\fP(ev) \fBevent_initialized\fP(ev)"
.br
.in -1c
.in -1c
.PP
.RI "\fBevsignal_* macros\fP"
.br
Aliases for working with signal events
.PP
.in +1c
.in +1c
.ti -1c
.RI "#define \fBevsignal_add\fP(ev, tv) \fBevent_add\fP((ev), (tv))"
.br
.ti -1c
.RI "#define \fBevsignal_assign\fP(ev, b, x, cb, arg) \fBevent_assign\fP((ev), (b), (x), \fBEV_SIGNAL\fP|\fBEV_PERSIST\fP, cb, (arg))"
.br
.ti -1c
.RI "#define \fBevsignal_new\fP(b, x, cb, arg) \fBevent_new\fP((b), (x), \fBEV_SIGNAL\fP|\fBEV_PERSIST\fP, (cb), (arg))"
.br
.ti -1c
.RI "#define \fBevsignal_del\fP(ev) \fBevent_del\fP(ev)"
.br
.ti -1c
.RI "#define \fBevsignal_pending\fP(ev, tv) \fBevent_pending\fP((ev), \fBEV_SIGNAL\fP, (tv))"
.br
.ti -1c
.RI "#define \fBevsignal_initialized\fP(ev) \fBevent_initialized\fP(ev)"
.br
.in -1c
.in -1c
.SS "Typedefs"
.in +1c
.ti -1c
.RI "typedef void(* \fBevent_callback_fn\fP )(\fBevutil_socket_t\fP, short, void *)"
.br
.RI "\fIA callback function for an event\&. \fP"
.ti -1c
.RI "typedef void(* \fBevent_fatal_cb\fP )(int err)"
.br
.RI "\fIA function to be called if Libevent encounters a fatal internal error\&. \fP"
.ti -1c
.RI "typedef void(* \fBevent_log_cb\fP )(int severity, const char *msg)"
.br
.RI "\fIA callback function used to intercept Libevent's log messages\&. \fP"
.in -1c
.SS "Enumerations"
.in +1c
.ti -1c
.RI "enum \fBevent_base_config_flag\fP { \fBEVENT_BASE_FLAG_NOLOCK\fP = 0x01, \fBEVENT_BASE_FLAG_IGNORE_ENV\fP = 0x02, \fBEVENT_BASE_FLAG_STARTUP_IOCP\fP = 0x04, \fBEVENT_BASE_FLAG_NO_CACHE_TIME\fP = 0x08, \fBEVENT_BASE_FLAG_EPOLL_USE_CHANGELIST\fP = 0x10 }"
.br
.RI "\fIA flag passed to \fBevent_config_set_flag()\fP\&. \fP"
.ti -1c
.RI "enum \fBevent_method_feature\fP { \fBEV_FEATURE_ET\fP = 0x01, \fBEV_FEATURE_O1\fP = 0x02, \fBEV_FEATURE_FDS\fP = 0x04 }"
.br
.RI "\fIA flag used to describe which features an \fBevent_base\fP (must) provide\&. \fP"
.in -1c
.SS "Functions"
.in +1c
.ti -1c
.RI "void \fBevent_active\fP (struct \fBevent\fP *ev, int res, short ncalls)"
.br
.RI "\fIMake an event active\&. \fP"
.ti -1c
.RI "int \fBevent_add\fP (struct \fBevent\fP *ev, const struct timeval *timeout)"
.br
.RI "\fIAdd an event to the set of pending events\&. \fP"
.ti -1c
.RI "int \fBevent_assign\fP (struct \fBevent\fP *, struct \fBevent_base\fP *, \fBevutil_socket_t\fP, short, \fBevent_callback_fn\fP, void *)"
.br
.RI "\fIPrepare a new, already-allocated event structure to be added\&. \fP"
.ti -1c
.RI "int \fBevent_base_dispatch\fP (struct \fBevent_base\fP *)"
.br
.RI "\fIEvent dispatching loop\&. \fP"
.ti -1c
.RI "void \fBevent_base_dump_events\fP (struct \fBevent_base\fP *, FILE *)"
.br
.ti -1c
.RI "void \fBevent_base_free\fP (struct \fBevent_base\fP *)"
.br
.RI "\fIDeallocate all memory associated with an \fBevent_base\fP, and free the base\&. \fP"
.ti -1c
.RI "int \fBevent_base_get_features\fP (const struct \fBevent_base\fP *base)"
.br
.RI "\fIReturn a bitmask of the features implemented by an event base\&. \fP"
.ti -1c
.RI "const char * \fBevent_base_get_method\fP (const struct \fBevent_base\fP *)"
.br
.RI "\fIGet the kernel event notification mechanism used by Libevent\&. \fP"
.ti -1c
.RI "int \fBevent_base_gettimeofday_cached\fP (struct \fBevent_base\fP *base, struct timeval *tv)"
.br
.RI "\fISets 'tv' to the current time (as returned by gettimeofday()), looking at the cached value in 'base' if possible, and calling gettimeofday() or clock_gettime() as appropriate if there is no cached time\&. \fP"
.ti -1c
.RI "int \fBevent_base_got_break\fP (struct \fBevent_base\fP *)"
.br
.RI "\fIChecks if the event loop was told to abort immediately by \fBevent_loopbreak()\fP\&. \fP"
.ti -1c
.RI "int \fBevent_base_got_exit\fP (struct \fBevent_base\fP *)"
.br
.RI "\fIChecks if the event loop was told to exit by \fBevent_loopexit()\fP\&. \fP"
.ti -1c
.RI "const struct timeval * \fBevent_base_init_common_timeout\fP (struct \fBevent_base\fP *base, const struct timeval *duration)"
.br
.RI "\fIPrepare an \fBevent_base\fP to use a large number of timeouts with the same duration\&. \fP"
.ti -1c
.RI "int \fBevent_base_loop\fP (struct \fBevent_base\fP *, int)"
.br
.RI "\fIWait for events to become active, and run their callbacks\&. \fP"
.ti -1c
.RI "int \fBevent_base_loopbreak\fP (struct \fBevent_base\fP *)"
.br
.RI "\fIAbort the active \fBevent_base_loop()\fP immediately\&. \fP"
.ti -1c
.RI "int \fBevent_base_loopexit\fP (struct \fBevent_base\fP *, const struct timeval *)"
.br
.RI "\fIExit the event loop after the specified time\&. \fP"
.ti -1c
.RI "struct \fBevent_base\fP * \fBevent_base_new\fP (void)"
.br
.RI "\fICreate and return a new \fBevent_base\fP to use with the rest of Libevent\&. \fP"
.ti -1c
.RI "struct \fBevent_base\fP * \fBevent_base_new_with_config\fP (const struct \fBevent_config\fP *)"
.br
.RI "\fIInitialize the event API\&. \fP"
.ti -1c
.RI "int \fBevent_base_once\fP (struct \fBevent_base\fP *, \fBevutil_socket_t\fP, short, \fBevent_callback_fn\fP, void *, const struct timeval *)"
.br
.RI "\fISchedule a one-time event\&. \fP"
.ti -1c
.RI "int \fBevent_base_priority_init\fP (struct \fBevent_base\fP *, int)"
.br
.RI "\fISet the number of different event priorities\&. \fP"
.ti -1c
.RI "int \fBevent_base_set\fP (struct \fBevent_base\fP *, struct \fBevent\fP *)"
.br
.RI "\fIAssociate a different event base with an event\&. \fP"
.ti -1c
.RI "int \fBevent_config_avoid_method\fP (struct \fBevent_config\fP *cfg, const char *method)"
.br
.RI "\fIEnters an event method that should be avoided into the configuration\&. \fP"
.ti -1c
.RI "void \fBevent_config_free\fP (struct \fBevent_config\fP *cfg)"
.br
.RI "\fIDeallocates all memory associated with an event configuration object\&. \fP"
.ti -1c
.RI "struct \fBevent_config\fP * \fBevent_config_new\fP (void)"
.br
.RI "\fIAllocates a new event configuration object\&. \fP"
.ti -1c
.RI "int \fBevent_config_require_features\fP (struct \fBevent_config\fP *cfg, int feature)"
.br
.RI "\fIEnters a required event method feature that the application demands\&. \fP"
.ti -1c
.RI "int \fBevent_config_set_flag\fP (struct \fBevent_config\fP *cfg, int flag)"
.br
.RI "\fISets one or more flags to configure what parts of the eventual \fBevent_base\fP will be initialized, and how they'll work\&. \fP"
.ti -1c
.RI "int \fBevent_config_set_num_cpus_hint\fP (struct \fBevent_config\fP *cfg, int cpus)"
.br
.RI "\fIRecords a hint for the number of CPUs in the system\&. \fP"
.ti -1c
.RI "void \fBevent_debug_unassign\fP (struct \fBevent\fP *)"
.br
.RI "\fIWhen debugging mode is enabled, informs Libevent that an event should no longer be considered as assigned\&. \fP"
.ti -1c
.RI "int \fBevent_del\fP (struct \fBevent\fP *)"
.br
.RI "\fIRemove an event from the set of monitored events\&. \fP"
.ti -1c
.RI "void \fBevent_enable_debug_mode\fP (void)"
.br
.RI "\fIEnable some relatively expensive debugging checks in Libevent that would normally be turned off\&. \fP"
.ti -1c
.RI "void \fBevent_free\fP (struct \fBevent\fP *)"
.br
.RI "\fIDeallocate a struct event * returned by \fBevent_new()\fP\&. \fP"
.ti -1c
.RI "void \fBevent_get_assignment\fP (const struct \fBevent\fP *\fBevent\fP, struct \fBevent_base\fP **base_out, \fBevutil_socket_t\fP *fd_out, short *events_out, \fBevent_callback_fn\fP *callback_out, void **arg_out)"
.br
.RI "\fIExtract \fIall\fP of arguments given to construct a given event\&. \fP"
.ti -1c
.RI "struct \fBevent_base\fP * \fBevent_get_base\fP (const struct \fBevent\fP *ev)"
.br
.RI "\fIGet the \fBevent_base\fP associated with an event\&. \fP"
.ti -1c
.RI "\fBevent_callback_fn\fP \fBevent_get_callback\fP (const struct \fBevent\fP *ev)"
.br
.RI "\fIReturn the callback assigned to an event\&. \fP"
.ti -1c
.RI "void * \fBevent_get_callback_arg\fP (const struct \fBevent\fP *ev)"
.br
.RI "\fIReturn the callback argument assigned to an event\&. \fP"
.ti -1c
.RI "short \fBevent_get_events\fP (const struct \fBevent\fP *ev)"
.br
.RI "\fIReturn the events (EV_READ, EV_WRITE, etc) assigned to an event\&. \fP"
.ti -1c
.RI "\fBevutil_socket_t\fP \fBevent_get_fd\fP (const struct \fBevent\fP *ev)"
.br
.RI "\fIGet the socket or signal assigned to an event, or -1 if the event has no socket\&. \fP"
.ti -1c
.RI "size_t \fBevent_get_struct_event_size\fP (void)"
.br
.RI "\fIReturn the size of struct event that the Libevent library was compiled with\&. \fP"
.ti -1c
.RI "const char ** \fBevent_get_supported_methods\fP (void)"
.br
.RI "\fIGets all event notification mechanisms supported by Libevent\&. \fP"
.ti -1c
.RI "const char * \fBevent_get_version\fP (void)"
.br
.RI "\fIGet the Libevent version\&. \fP"
.ti -1c
.RI "ev_uint32_t \fBevent_get_version_number\fP (void)"
.br
.RI "\fIReturn a numeric representation of Libevent's version\&. \fP"
.ti -1c
.RI "int \fBevent_initialized\fP (const struct \fBevent\fP *ev)"
.br
.RI "\fITest if an event structure might be initialized\&. \fP"
.ti -1c
.RI "struct \fBevent\fP * \fBevent_new\fP (struct \fBevent_base\fP *, \fBevutil_socket_t\fP, short, \fBevent_callback_fn\fP, void *)"
.br
.RI "\fIAllocate and asssign a new event structure, ready to be added\&. \fP"
.ti -1c
.RI "int \fBevent_pending\fP (const struct \fBevent\fP *ev, short events, struct timeval *tv)"
.br
.RI "\fIChecks if a specific event is pending or scheduled\&. \fP"
.ti -1c
.RI "int \fBevent_priority_set\fP (struct \fBevent\fP *, int)"
.br
.RI "\fIAssign a priority to an event\&. \fP"
.ti -1c
.RI "int \fBevent_reinit\fP (struct \fBevent_base\fP *base)"
.br
.RI "\fIReinitialize the event base after a fork\&. \fP"
.ti -1c
.RI "void \fBevent_set_fatal_callback\fP (\fBevent_fatal_cb\fP cb)"
.br
.RI "\fIOverride Libevent's behavior in the event of a fatal internal error\&. \fP"
.ti -1c
.RI "void \fBevent_set_log_callback\fP (\fBevent_log_cb\fP cb)"
.br
.RI "\fIRedirect Libevent's log messages\&. \fP"
.ti -1c
.RI "void \fBevent_set_mem_functions\fP (void *(*malloc_fn)(size_t sz), void *(*realloc_fn)(void *ptr, size_t sz), void(*free_fn)(void *ptr))"
.br
.RI "\fIOverride the functions that Libevent uses for memory management\&. \fP"
.in -1c
.SH "Detailed Description"
.PP
Core functions for waiting for and receiving events, and using event bases\&.
.SH "Macro Definition Documentation"
.PP
.SS "#define EV_ET 0x20"
.PP
Select edge-triggered behavior, if supported by the backend\&.
.SS "#define EV_PERSIST 0x10"
.PP
Persistent event: won't get removed automatically when activated\&. When a persistent event with a timeout becomes activated, its timeout is reset to 0\&.
.SS "#define EV_TIMEOUT 0x01"
.PP
Indicates that a timeout has occurred\&. It's not necessary to pass this flag to event_for new()/event_assign() to get a timeout\&.
.SS "#define EVENT_MAX_PRIORITIES 256"
.PP
Largest number of priorities that Libevent can support\&.
.SS "#define EVLOOP_NONBLOCK 0x02"
.PP
Do not block: see which events are ready now, run the callbacks of the highest-priority ones, then exit\&.
.SS "#define EVLOOP_ONCE 0x01"
.PP
Block until we have an active event, then exit once all active events have had their callbacks run\&.
.SS "#define LIBEVENT_VERSION _EVENT_VERSION"
.PP
As event_get_version, but gives the version of Libevent's headers\&.
.SS "#define LIBEVENT_VERSION_NUMBER _EVENT_NUMERIC_VERSION"
.PP
As event_get_version_number, but gives the version number of Libevent's headers\&.
.SH "Typedef Documentation"
.PP
.SS "typedef void(* event_callback_fn)(\fBevutil_socket_t\fP, short, void *)"
.PP
A callback function for an event\&. It receives three arguments:
.PP
\fBParameters:\fP
.RS 4
\fIfd\fP An fd or signal
.br
\fIevents\fP One or more EV_* flags
.br
\fIarg\fP A user-supplied argument\&.
.RE
.PP
\fBSee also:\fP
.RS 4
\fBevent_new()\fP
.RE
.PP
.SS "typedef void(* event_fatal_cb)(int err)"
.PP
A function to be called if Libevent encounters a fatal internal error\&.
.PP
\fBSee also:\fP
.RS 4
\fBevent_set_fatal_callback\fP
.RE
.PP
.SS "typedef void(* event_log_cb)(int severity, const char *msg)"
.PP
A callback function used to intercept Libevent's log messages\&.
.PP
\fBSee also:\fP
.RS 4
\fBevent_set_log_callback\fP
.RE
.PP
.SH "Enumeration Type Documentation"
.PP
.SS "enum \fBevent_base_config_flag\fP"
.PP
A flag passed to \fBevent_config_set_flag()\fP\&. These flags change the behavior of an allocated \fBevent_base\fP\&.
.PP
\fBSee also:\fP
.RS 4
\fBevent_config_set_flag()\fP, \fBevent_base_new_with_config()\fP, \fBevent_method_feature\fP
.RE
.PP
.PP
\fBEnumerator\fP
.in +1c
.TP
\fB\fIEVENT_BASE_FLAG_NOLOCK \fP\fP
Do not allocate a lock for the event base, even if we have locking set up\&.
.TP
\fB\fIEVENT_BASE_FLAG_IGNORE_ENV \fP\fP
Do not check the EVENT_* environment variables when configuring an \fBevent_base\fP\&.
.TP
\fB\fIEVENT_BASE_FLAG_STARTUP_IOCP \fP\fP
Windows only: enable the IOCP dispatcher at startup\&. If this flag is set then \fBbufferevent_socket_new()\fP and evconn_listener_new() will use IOCP-backed implementations instead of the usual select-based one on Windows\&.
.TP
\fB\fIEVENT_BASE_FLAG_NO_CACHE_TIME \fP\fP
Instead of checking the current time every time the event loop is ready to run timeout callbacks, check after each timeout callback\&.
.TP
\fB\fIEVENT_BASE_FLAG_EPOLL_USE_CHANGELIST \fP\fP
If we are using the epoll backend, this flag says that it is safe to use Libevent's internal change-list code to batch up adds and deletes in order to try to do as few syscalls as possible\&. Setting this flag can make your code run faster, but it may trigger a Linux bug: it is not safe to use this flag if you have any fds cloned by dup() or its variants\&. Doing so will produce strange and hard-to-diagnose bugs\&.
.PP
This flag can also be activated by settnig the EVENT_EPOLL_USE_CHANGELIST environment variable\&.
.PP
This flag has no effect if you wind up using a backend other than epoll\&.
.SS "enum \fBevent_method_feature\fP"
.PP
A flag used to describe which features an \fBevent_base\fP (must) provide\&. Because of OS limitations, not every Libevent backend supports every possible feature\&. You can use this type with \fBevent_config_require_features()\fP to tell Libevent to only proceed if your \fBevent_base\fP implements a given feature, and you can receive this type from \fBevent_base_get_features()\fP to see which features are available\&.
.PP
\fBEnumerator\fP
.in +1c
.TP
\fB\fIEV_FEATURE_ET \fP\fP
Require an event method that allows edge-triggered events with EV_ET\&.
.TP
\fB\fIEV_FEATURE_O1 \fP\fP
Require an event method where having one event triggered among many is [approximately] an O(1) operation\&. This excludes (for example) select and poll, which are approximately O(N) for N equal to the total number of possible events\&.
.TP
\fB\fIEV_FEATURE_FDS \fP\fP
Require an event method that allows file descriptors as well as sockets\&.
.SH "Function Documentation"
.PP
.SS "void event_active (struct \fBevent\fP *ev, intres, shortncalls)"
.PP
Make an event active\&. You can use this function on a pending or a non-pending event to make it active, so that its callback will be run by \fBevent_base_dispatch()\fP or \fBevent_base_loop()\fP\&.
.PP
One common use in multithreaded programs is to wake the thread running \fBevent_base_loop()\fP from another thread\&.
.PP
\fBParameters:\fP
.RS 4
\fIev\fP an event to make active\&.
.br
\fIres\fP a set of flags to pass to the event's callback\&.
.br
\fIncalls\fP an obsolete argument: this is ignored\&.
.RE
.PP
.SS "int event_add (struct \fBevent\fP *ev, const struct timeval *timeout)"
.PP
Add an event to the set of pending events\&. The function \fBevent_add()\fP schedules the execution of the ev event when the event specified in \fBevent_assign()\fP/event_new() occurs, or when the time specified in timeout has elapesed\&. If atimeout is NULL, no timeout occurs and the function will only be called if a matching event occurs\&. The event in the ev argument must be already initialized by \fBevent_assign()\fP or \fBevent_new()\fP and may not be used in calls to \fBevent_assign()\fP until it is no longer pending\&.
.PP
If the event in the ev argument already has a scheduled timeout, calling \fBevent_add()\fP replaces the old timeout with the new one, or clears the old timeout if the timeout argument is NULL\&.
.PP
\fBParameters:\fP
.RS 4
\fIev\fP an event struct initialized via \fBevent_set()\fP
.br
\fItimeout\fP the maximum amount of time to wait for the event, or NULL to wait forever
.RE
.PP
\fBReturns:\fP
.RS 4
0 if successful, or -1 if an error occurred
.RE
.PP
\fBSee also:\fP
.RS 4
\fBevent_del()\fP, \fBevent_assign()\fP, \fBevent_new()\fP
.RE
.PP
.SS "int event_assign (struct \fBevent\fP *, struct \fBevent_base\fP *, \fBevutil_socket_t\fP, short, \fBevent_callback_fn\fP, void *)"
.PP
Prepare a new, already-allocated event structure to be added\&. The function \fBevent_assign()\fP prepares the event structure ev to be used in future calls to \fBevent_add()\fP and \fBevent_del()\fP\&. Unlike \fBevent_new()\fP, it doesn't allocate memory itself: it requires that you have already allocated a struct event, probably on the heap\&. Doing this will typically make your code depend on the size of the event structure, and thereby create incompatibility with future versions of Libevent\&.
.PP
The easiest way to avoid this problem is just to use \fBevent_new()\fP and \fBevent_free()\fP instead\&.
.PP
A slightly harder way to future-proof your code is to use \fBevent_get_struct_event_size()\fP to determine the required size of an event at runtime\&.
.PP
Note that it is NOT safe to call this function on an event that is active or pending\&. Doing so WILL corrupt internal data structures in Libevent, and lead to strange, hard-to-diagnose bugs\&. You \fIcan\fP use event_assign to change an existing event, but only if it is not active or pending!
.PP
The arguments for this function, and the behavior of the events that it makes, are as for \fBevent_new()\fP\&.
.PP
\fBParameters:\fP
.RS 4
\fIev\fP an event struct to be modified
.br
\fIbase\fP the event base to which ev should be attached\&.
.br
\fIfd\fP the file descriptor to be monitored
.br
\fIevents\fP desired events to monitor; can be EV_READ and/or EV_WRITE
.br
\fIcallback\fP callback function to be invoked when the event occurs
.br
\fIcallback_arg\fP an argument to be passed to the callback function
.RE
.PP
\fBReturns:\fP
.RS 4
0 if success, or -1 on invalid arguments\&.
.RE
.PP
\fBSee also:\fP
.RS 4
\fBevent_new()\fP, \fBevent_add()\fP, \fBevent_del()\fP, \fBevent_base_once()\fP, \fBevent_get_struct_event_size()\fP
.RE
.PP
.SS "int event_base_dispatch (struct \fBevent_base\fP *)"
.PP
Event dispatching loop\&. This loop will run the event base until either there are no more pending or active, or until something calls \fBevent_base_loopbreak()\fP or \fBevent_base_loopexit()\fP\&.
.PP
\fBParameters:\fP
.RS 4
\fIbase\fP the \fBevent_base\fP structure returned by \fBevent_base_new()\fP or \fBevent_base_new_with_config()\fP
.RE
.PP
\fBReturns:\fP
.RS 4
0 if successful, -1 if an error occurred, or 1 if we exited because no events were pending or active\&.
.RE
.PP
\fBSee also:\fP
.RS 4
\fBevent_base_loop()\fP
.RE
.PP
.SS "void event_base_free (struct \fBevent_base\fP *)"
.PP
Deallocate all memory associated with an \fBevent_base\fP, and free the base\&. Note that this function will not close any fds or free any memory passed to event_new as the argument to callback\&.
.PP
\fBParameters:\fP
.RS 4
\fIeb\fP an \fBevent_base\fP to be freed
.RE
.PP
.SS "int event_base_get_features (const struct \fBevent_base\fP *base)"
.PP
Return a bitmask of the features implemented by an event base\&. This will be a bitwise OR of one or more of the values of event_method_feature
.PP
\fBSee also:\fP
.RS 4
\fBevent_method_feature\fP
.RE
.PP
.SS "const char* event_base_get_method (const struct \fBevent_base\fP *)"
.PP
Get the kernel event notification mechanism used by Libevent\&.
.PP
\fBParameters:\fP
.RS 4
\fIeb\fP the \fBevent_base\fP structure returned by \fBevent_base_new()\fP
.RE
.PP
\fBReturns:\fP
.RS 4
a string identifying the kernel event mechanism (kqueue, epoll, etc\&.)
.RE
.PP
.SS "int event_base_gettimeofday_cached (struct \fBevent_base\fP *base, struct timeval *tv)"
.PP
Sets 'tv' to the current time (as returned by gettimeofday()), looking at the cached value in 'base' if possible, and calling gettimeofday() or clock_gettime() as appropriate if there is no cached time\&. Generally, this value will only be cached while actually processing event callbacks, and may be very inaccuate if your callbacks take a long time to execute\&.
.PP
Returns 0 on success, negative on failure\&.
.SS "int event_base_got_break (struct \fBevent_base\fP *)"
.PP
Checks if the event loop was told to abort immediately by \fBevent_loopbreak()\fP\&. This function will return true for an \fBevent_base\fP at every point after \fBevent_loopbreak()\fP is called, until the event loop is next entered\&.
.PP
\fBParameters:\fP
.RS 4
\fIeb\fP the \fBevent_base\fP structure returned by \fBevent_init()\fP
.RE
.PP
\fBReturns:\fP
.RS 4
true if \fBevent_base_loopbreak()\fP was called on this event base, or 0 otherwise
.RE
.PP
\fBSee also:\fP
.RS 4
\fBevent_base_loopbreak()\fP
.PP
\fBevent_base_got_exit()\fP
.RE
.PP
.SS "int event_base_got_exit (struct \fBevent_base\fP *)"
.PP
Checks if the event loop was told to exit by \fBevent_loopexit()\fP\&. This function will return true for an \fBevent_base\fP at every point after \fBevent_loopexit()\fP is called, until the event loop is next entered\&.
.PP
\fBParameters:\fP
.RS 4
\fIeb\fP the \fBevent_base\fP structure returned by \fBevent_init()\fP
.RE
.PP
\fBReturns:\fP
.RS 4
true if \fBevent_base_loopexit()\fP was called on this event base, or 0 otherwise
.RE
.PP
\fBSee also:\fP
.RS 4
\fBevent_base_loopexit()\fP
.PP
\fBevent_base_got_break()\fP
.RE
.PP
.SS "const struct timeval* event_base_init_common_timeout (struct \fBevent_base\fP *base, const struct timeval *duration)"
.PP
Prepare an \fBevent_base\fP to use a large number of timeouts with the same duration\&. Libevent's default scheduling algorithm is optimized for having a large number of timeouts with their durations more or less randomly distributed\&. But if you have a large number of timeouts that all have the same duration (for example, if you have a large number of connections that all have a 10-second timeout), then you can improve Libevent's performance by telling Libevent about it\&.
.PP
To do this, call this function with the common duration\&. It will return a pointer to a different, opaque timeout value\&. (Don't depend on its actual contents!) When you use this timeout value in \fBevent_add()\fP, Libevent will schedule the event more efficiently\&.
.PP
(This optimization probably will not be worthwhile until you have thousands or tens of thousands of events with the same timeout\&.)
.SS "int event_base_loop (struct \fBevent_base\fP *, int)"
.PP
Wait for events to become active, and run their callbacks\&. This is a more flexible version of \fBevent_base_dispatch()\fP\&.
.PP
By default, this loop will run the event base until either there are no more pending or active events, or until something calls \fBevent_base_loopbreak()\fP or \fBevent_base_loopexit()\fP\&. You can override this behavior with the 'flags' argument\&.
.PP
\fBParameters:\fP
.RS 4
\fIeb\fP the \fBevent_base\fP structure returned by \fBevent_base_new()\fP or \fBevent_base_new_with_config()\fP
.br
\fIflags\fP any combination of EVLOOP_ONCE | EVLOOP_NONBLOCK
.RE
.PP
\fBReturns:\fP
.RS 4
0 if successful, -1 if an error occurred, or 1 if we exited because no events were pending or active\&.
.RE
.PP
\fBSee also:\fP
.RS 4
\fBevent_base_loopexit()\fP, \fBevent_base_dispatch()\fP, \fBEVLOOP_ONCE\fP, \fBEVLOOP_NONBLOCK\fP
.RE
.PP
.SS "int event_base_loopbreak (struct \fBevent_base\fP *)"
.PP
Abort the active \fBevent_base_loop()\fP immediately\&. \fBevent_base_loop()\fP will abort the loop after the next event is completed; \fBevent_base_loopbreak()\fP is typically invoked from this event's callback\&. This behavior is analogous to the 'break;' statement\&.
.PP
Subsequent invocations of \fBevent_loop()\fP will proceed normally\&.
.PP
\fBParameters:\fP
.RS 4
\fIeb\fP the \fBevent_base\fP structure returned by \fBevent_init()\fP
.RE
.PP
\fBReturns:\fP
.RS 4
0 if successful, or -1 if an error occurred
.RE
.PP
\fBSee also:\fP
.RS 4
\fBevent_base_loopexit()\fP
.RE
.PP
.SS "int event_base_loopexit (struct \fBevent_base\fP *, const struct timeval *)"
.PP
Exit the event loop after the specified time\&. The next \fBevent_base_loop()\fP iteration after the given timer expires will complete normally (handling all queued events) then exit without blocking for events again\&.
.PP
Subsequent invocations of \fBevent_base_loop()\fP will proceed normally\&.
.PP
\fBParameters:\fP
.RS 4
\fIeb\fP the \fBevent_base\fP structure returned by \fBevent_init()\fP
.br
\fItv\fP the amount of time after which the loop should terminate, or NULL to exit after running all currently active events\&.
.RE
.PP
\fBReturns:\fP
.RS 4
0 if successful, or -1 if an error occurred
.RE
.PP
\fBSee also:\fP
.RS 4
\fBevent_base_loopbreak()\fP
.RE
.PP
.SS "struct \fBevent_base\fP* event_base_new (void)"
.PP
Create and return a new \fBevent_base\fP to use with the rest of Libevent\&.
.PP
\fBReturns:\fP
.RS 4
a new \fBevent_base\fP on success, or NULL on failure\&.
.RE
.PP
\fBSee also:\fP
.RS 4
\fBevent_base_free()\fP, \fBevent_base_new_with_config()\fP
.RE
.PP
.SS "struct \fBevent_base\fP* event_base_new_with_config (const struct \fBevent_config\fP *)"
.PP
Initialize the event API\&. Use \fBevent_base_new_with_config()\fP to initialize a new event base, taking the specified configuration under consideration\&. The configuration object can currently be used to avoid certain event notification mechanisms\&.
.PP
\fBParameters:\fP
.RS 4
\fIcfg\fP the event configuration object
.RE
.PP
\fBReturns:\fP
.RS 4
an initialized \fBevent_base\fP that can be used to registering events, or NULL if no event base can be created with the requested \fBevent_config\fP\&.
.RE
.PP
\fBSee also:\fP
.RS 4
\fBevent_base_new()\fP, \fBevent_base_free()\fP, \fBevent_init()\fP, \fBevent_assign()\fP
.RE
.PP
.SS "int event_base_once (struct \fBevent_base\fP *, \fBevutil_socket_t\fP, short, \fBevent_callback_fn\fP, void *, const struct timeval *)"
.PP
Schedule a one-time event\&. The function \fBevent_base_once()\fP is similar to \fBevent_set()\fP\&. However, it schedules a callback to be called exactly once, and does not require the caller to prepare an event structure\&.
.PP
Note that in Libevent 2\&.0 and earlier, if the event is never triggered, the internal memory used to hold it will never be freed\&. This may be fixed in a later version of Libevent\&.
.PP
\fBParameters:\fP
.RS 4
\fIbase\fP an \fBevent_base\fP
.br
\fIfd\fP a file descriptor to monitor, or -1 for no fd\&.
.br
\fIevents\fP \fBevent(s)\fP to monitor; can be any of EV_READ | EV_WRITE, or EV_TIMEOUT
.br
\fIcallback\fP callback function to be invoked when the event occurs
.br
\fIarg\fP an argument to be passed to the callback function
.br
\fItimeout\fP the maximum amount of time to wait for the event\&. NULL makes an EV_READ/EV_WRITE event make forever; NULL makes an EV_TIMEOUT event succees immediately\&.
.RE
.PP
\fBReturns:\fP
.RS 4
0 if successful, or -1 if an error occurred
.RE
.PP
.SS "int event_base_priority_init (struct \fBevent_base\fP *, int)"
.PP
Set the number of different event priorities\&. By default Libevent schedules all active events with the same priority\&. However, some time it is desirable to process some events with a higher priority than others\&. For that reason, Libevent supports strict priority queues\&. Active events with a lower priority are always processed before events with a higher priority\&.
.PP
The number of different priorities can be set initially with the \fBevent_base_priority_init()\fP function\&. This function should be called before the first call to \fBevent_base_dispatch()\fP\&. The \fBevent_priority_set()\fP function can be used to assign a priority to an event\&. By default, Libevent assigns the middle priority to all events unless their priority is explicitly set\&.
.PP
Note that urgent-priority events can starve less-urgent events: after running all urgent-priority callbacks, Libevent checks for more urgent events again, before running less-urgent events\&. Less-urgent events will not have their callbacks run until there are no events more urgent than them that want to be active\&.
.PP
\fBParameters:\fP
.RS 4
\fIeb\fP the \fBevent_base\fP structure returned by \fBevent_base_new()\fP
.br
\fInpriorities\fP the maximum number of priorities
.RE
.PP
\fBReturns:\fP
.RS 4
0 if successful, or -1 if an error occurred
.RE
.PP
\fBSee also:\fP
.RS 4
\fBevent_priority_set()\fP
.RE
.PP
.SS "int event_base_set (struct \fBevent_base\fP *, struct \fBevent\fP *)"
.PP
Associate a different event base with an event\&. The event to be associated must not be currently active or pending\&.
.PP
\fBParameters:\fP
.RS 4
\fIeb\fP the event base
.br
\fIev\fP the event
.RE
.PP
\fBReturns:\fP
.RS 4
0 on success, -1 on failure\&.
.RE
.PP
.SS "int event_config_avoid_method (struct \fBevent_config\fP *cfg, const char *method)"
.PP
Enters an event method that should be avoided into the configuration\&. This can be used to avoid event mechanisms that do not support certain file descriptor types, or for debugging to avoid certain event mechanisms\&. An application can make use of multiple event bases to accommodate incompatible file descriptor types\&.
.PP
\fBParameters:\fP
.RS 4
\fIcfg\fP the event configuration object
.br
\fImethod\fP the name of the event method to avoid
.RE
.PP
\fBReturns:\fP
.RS 4
0 on success, -1 on failure\&.
.RE
.PP
.SS "void event_config_free (struct \fBevent_config\fP *cfg)"
.PP
Deallocates all memory associated with an event configuration object\&.
.PP
\fBParameters:\fP
.RS 4
\fIcfg\fP the event configuration object to be freed\&.
.RE
.PP
.SS "struct \fBevent_config\fP* event_config_new (void)"
.PP
Allocates a new event configuration object\&. The event configuration object can be used to change the behavior of an event base\&.
.PP
\fBReturns:\fP
.RS 4
an \fBevent_config\fP object that can be used to store configuration, or NULL if an error is encountered\&.
.RE
.PP
\fBSee also:\fP
.RS 4
\fBevent_base_new_with_config()\fP, \fBevent_config_free()\fP, \fBevent_config\fP
.RE
.PP
.SS "int event_config_require_features (struct \fBevent_config\fP *cfg, intfeature)"
.PP
Enters a required event method feature that the application demands\&. Note that not every feature or combination of features is supported on every platform\&. Code that requests features should be prepared to handle the case where \fBevent_base_new_with_config()\fP returns NULL, as in:
.PP
.nf
event_config_require_features(cfg, EV_FEATURE_ET);
base = event_base_new_with_config(cfg);
if (base == NULL) {
// We can't get edge-triggered behavior here\&.
event_config_require_features(cfg, 0);
base = event_base_new_with_config(cfg);
}
.fi
.PP
.PP
\fBParameters:\fP
.RS 4
\fIcfg\fP the event configuration object
.br
\fIfeature\fP a bitfield of one or more event_method_feature values\&. Replaces values from previous calls to this function\&.
.RE
.PP
\fBReturns:\fP
.RS 4
0 on success, -1 on failure\&.
.RE
.PP
\fBSee also:\fP
.RS 4
\fBevent_method_feature\fP, \fBevent_base_new_with_config()\fP
.RE
.PP
.SS "int event_config_set_flag (struct \fBevent_config\fP *cfg, intflag)"
.PP
Sets one or more flags to configure what parts of the eventual \fBevent_base\fP will be initialized, and how they'll work\&.
.PP
\fBSee also:\fP
.RS 4
event_base_config_flags, \fBevent_base_new_with_config()\fP
.RE
.PP
.SS "int event_config_set_num_cpus_hint (struct \fBevent_config\fP *cfg, intcpus)"
.PP
Records a hint for the number of CPUs in the system\&. This is used for tuning thread pools, etc, for optimal performance\&. In Libevent 2\&.0, it is only on Windows, and only when IOCP is in use\&.
.PP
\fBParameters:\fP
.RS 4
\fIcfg\fP the event configuration object
.br
\fIcpus\fP the number of cpus
.RE
.PP
\fBReturns:\fP
.RS 4
0 on success, -1 on failure\&.
.RE
.PP
.SS "void event_debug_unassign (struct \fBevent\fP *)"
.PP
When debugging mode is enabled, informs Libevent that an event should no longer be considered as assigned\&. When debugging mode is not enabled, does nothing\&.
.PP
This function must only be called on a non-added event\&.
.PP
\fBSee also:\fP
.RS 4
\fBevent_enable_debug_mode()\fP
.RE
.PP
.SS "int event_del (struct \fBevent\fP *)"
.PP
Remove an event from the set of monitored events\&. The function \fBevent_del()\fP will cancel the event in the argument ev\&. If the event has already executed or has never been added the call will have no effect\&.
.PP
\fBParameters:\fP
.RS 4
\fIev\fP an event struct to be removed from the working set
.RE
.PP
\fBReturns:\fP
.RS 4
0 if successful, or -1 if an error occurred
.RE
.PP
\fBSee also:\fP
.RS 4
\fBevent_add()\fP
.RE
.PP
.SS "void event_enable_debug_mode (void)"
.PP
Enable some relatively expensive debugging checks in Libevent that would normally be turned off\&. Generally, these checks cause code that would otherwise crash mysteriously to fail earlier with an assertion failure\&. Note that this method MUST be called before any events or event_bases have been created\&.
.PP
Debug mode can currently catch the following errors: An event is re-assigned while it is added Any function is called on a non-assigned event
.PP
Note that debugging mode uses memory to track every event that has been initialized (via event_assign, event_set, or event_new) but not yet released (via event_free or event_debug_unassign)\&. If you want to use debug mode, and you find yourself running out of memory, you will need to use event_debug_unassign to explicitly stop tracking events that are no longer considered set-up\&.
.PP
\fBSee also:\fP
.RS 4
\fBevent_debug_unassign()\fP
.RE
.PP
.SS "void event_free (struct \fBevent\fP *)"
.PP
Deallocate a struct event * returned by \fBevent_new()\fP\&. If the event is pending or active, first make it non-pending and non-active\&.
.SS "void event_get_assignment (const struct \fBevent\fP *event, struct \fBevent_base\fP **base_out, \fBevutil_socket_t\fP *fd_out, short *events_out, \fBevent_callback_fn\fP *callback_out, void **arg_out)"
.PP
Extract \fIall\fP of arguments given to construct a given event\&. The \fBevent_base\fP is copied into *base_out, the fd is copied into *fd_out, and so on\&.
.PP
If any of the '_out' arguments is NULL, it will be ignored\&.
.SS "size_t event_get_struct_event_size (void)"
.PP
Return the size of struct event that the Libevent library was compiled with\&. This will be NO GREATER than sizeof(struct event) if you're running with the same version of Libevent that your application was built with, but otherwise might not\&.
.PP
Note that it might be SMALLER than sizeof(struct event) if some future version of Libevent adds extra padding to the end of struct event\&. We might do this to help ensure ABI-compatibility between different versions of Libevent\&.
.SS "const char** event_get_supported_methods (void)"
.PP
Gets all event notification mechanisms supported by Libevent\&. This functions returns the event mechanism in order preferred by Libevent\&. Note that this list will include all backends that Libevent has compiled-in support for, and will not necessarily check your OS to see whether it has the required resources\&.
.PP
\fBReturns:\fP
.RS 4
an array with pointers to the names of support methods\&. The end of the array is indicated by a NULL pointer\&. If an error is encountered NULL is returned\&.
.RE
.PP
.SS "const char* event_get_version (void)"
.PP
Get the Libevent version\&. Note that this will give you the version of the library that you're currently linked against, not the version of the headers that you've compiled against\&.
.PP
\fBReturns:\fP
.RS 4
a string containing the version number of Libevent
.RE
.PP
.SS "ev_uint32_t event_get_version_number (void)"
.PP
Return a numeric representation of Libevent's version\&. Note that this will give you the version of the library that you're currently linked against, not the version of the headers you've used to compile\&.
.PP
The format uses one byte each for the major, minor, and patchlevel parts of the version number\&. The low-order byte is unused\&. For example, version 2\&.0\&.1-alpha has a numeric representation of 0x02000100
.SS "int event_initialized (const struct \fBevent\fP *ev)"
.PP
Test if an event structure might be initialized\&. The \fBevent_initialized()\fP function can be used to check if an event has been initialized\&.
.PP
Warning: This function is only useful for distinguishing a a zeroed-out piece of memory from an initialized event, it can easily be confused by uninitialized memory\&. Thus, it should ONLY be used to distinguish an initialized event from zero\&.
.PP
\fBParameters:\fP
.RS 4
\fIev\fP an event structure to be tested
.RE
.PP
\fBReturns:\fP
.RS 4
1 if the structure might be initialized, or 0 if it has not been initialized
.RE
.PP
.SS "struct \fBevent\fP* event_new (struct \fBevent_base\fP *, \fBevutil_socket_t\fP, short, \fBevent_callback_fn\fP, void *)"
.PP
Allocate and asssign a new event structure, ready to be added\&. The function \fBevent_new()\fP returns a new event that can be used in future calls to \fBevent_add()\fP and \fBevent_del()\fP\&. The fd and events arguments determine which conditions will trigger the event; the callback and callback_arg arguments tell Libevent what to do when the event becomes active\&.
.PP
If events contains one of EV_READ, EV_WRITE, or EV_READ|EV_WRITE, then fd is a file descriptor or socket that should get monitored for readiness to read, readiness to write, or readiness for either operation (respectively)\&. If events contains EV_SIGNAL, then fd is a signal number to wait for\&. If events contains none of those flags, then the event can be triggered only by a timeout or by manual activation with \fBevent_active()\fP: In this case, fd must be -1\&.
.PP
The EV_PERSIST flag can also be passed in the events argument: it makes \fBevent_add()\fP persistent until \fBevent_del()\fP is called\&.
.PP
The EV_ET flag is compatible with EV_READ and EV_WRITE, and supported only by certain backends\&. It tells Libevent to use edge-triggered events\&.
.PP
The EV_TIMEOUT flag has no effect here\&.
.PP
It is okay to have multiple events all listening on the same fds; but they must either all be edge-triggered, or all not be edge triggerd\&.
.PP
When the event becomes active, the event loop will run the provided callbuck function, with three arguments\&. The first will be the provided fd value\&. The second will be a bitfield of the events that triggered: EV_READ, EV_WRITE, or EV_SIGNAL\&. Here the EV_TIMEOUT flag indicates that a timeout occurred, and EV_ET indicates that an edge-triggered event occurred\&. The third event will be the callback_arg pointer that you provide\&.
.PP
\fBParameters:\fP
.RS 4
\fIbase\fP the event base to which the event should be attached\&.
.br
\fIfd\fP the file descriptor or signal to be monitored, or -1\&.
.br
\fIevents\fP desired events to monitor: bitfield of EV_READ, EV_WRITE, EV_SIGNAL, EV_PERSIST, EV_ET\&.
.br
\fIcallback\fP callback function to be invoked when the event occurs
.br
\fIcallback_arg\fP an argument to be passed to the callback function
.RE
.PP
\fBReturns:\fP
.RS 4
a newly allocated struct event that must later be freed with \fBevent_free()\fP\&.
.RE
.PP
\fBSee also:\fP
.RS 4
\fBevent_free()\fP, \fBevent_add()\fP, \fBevent_del()\fP, \fBevent_assign()\fP
.RE
.PP
.SS "int event_pending (const struct \fBevent\fP *ev, shortevents, struct timeval *tv)"
.PP
Checks if a specific event is pending or scheduled\&.
.PP
\fBParameters:\fP
.RS 4
\fIev\fP an event struct previously passed to \fBevent_add()\fP
.br
\fIevents\fP the requested event type; any of EV_TIMEOUT|EV_READ| EV_WRITE|EV_SIGNAL
.br
\fItv\fP if this field is not NULL, and the event has a timeout, this field is set to hold the time at which the timeout will expire\&.
.RE
.PP
\fBReturns:\fP
.RS 4
true if the event is pending on any of the events in 'what', (that is to say, it has been added), or 0 if the event is not added\&.
.RE
.PP
.SS "int event_priority_set (struct \fBevent\fP *, int)"
.PP
Assign a priority to an event\&.
.PP
\fBParameters:\fP
.RS 4
\fIev\fP an event struct
.br
\fIpriority\fP the new priority to be assigned
.RE
.PP
\fBReturns:\fP
.RS 4
0 if successful, or -1 if an error occurred
.RE
.PP
\fBSee also:\fP
.RS 4
\fBevent_priority_init()\fP
.RE
.PP
.SS "int event_reinit (struct \fBevent_base\fP *base)"
.PP
Reinitialize the event base after a fork\&. Some event mechanisms do not survive across fork\&. The event base needs to be reinitialized with the \fBevent_reinit()\fP function\&.
.PP
\fBParameters:\fP
.RS 4
\fIbase\fP the event base that needs to be re-initialized
.RE
.PP
\fBReturns:\fP
.RS 4
0 if successful, or -1 if some events could not be re-added\&.
.RE
.PP
\fBSee also:\fP
.RS 4
\fBevent_base_new()\fP
.RE
.PP
.SS "void event_set_fatal_callback (\fBevent_fatal_cb\fPcb)"
.PP
Override Libevent's behavior in the event of a fatal internal error\&. By default, Libevent will call exit(1) if a programming error makes it impossible to continue correct operation\&. This function allows you to supply another callback instead\&. Note that if the function is ever invoked, something is wrong with your program, or with Libevent: any subsequent calls to Libevent may result in undefined behavior\&.
.PP
Libevent will (almost) always log an _EVENT_LOG_ERR message before calling this function; look at the last log message to see why Libevent has died\&.
.SS "void event_set_log_callback (\fBevent_log_cb\fPcb)"
.PP
Redirect Libevent's log messages\&.
.PP
\fBParameters:\fP
.RS 4
\fIcb\fP a function taking two arguments: an integer severity between _EVENT_LOG_DEBUG and _EVENT_LOG_ERR, and a string\&. If cb is NULL, then the default log is used\&.
.RE
.PP
NOTE: The function you provide \fImust not\fP call any other libevent functionality\&. Doing so can produce undefined behavior\&.
.SS "void event_set_mem_functions (void *(*)(size_t sz)malloc_fn, void *(*)(void *ptr, size_t sz)realloc_fn, void(*)(void *ptr)free_fn)"
.PP
Override the functions that Libevent uses for memory management\&. Usually, Libevent uses the standard libc functions malloc, realloc, and free to allocate memory\&. Passing replacements for those functions to \fBevent_set_mem_functions()\fP overrides this behavior\&.
.PP
Note that all memory returned from Libevent will be allocated by the replacement functions rather than by malloc() and realloc()\&. Thus, if you have replaced those functions, it will not be appropriate to free() memory that you get from Libevent\&. Instead, you must use the free_fn replacement that you provided\&.
.PP
Note also that if you are going to call this function, you should do so before any call to any Libevent function that does allocation\&. Otherwise, those funtions will allocate their memory using malloc(), but then later free it using your provided free_fn\&.
.PP
\fBParameters:\fP
.RS 4
\fImalloc_fn\fP A replacement for malloc\&.
.br
\fIrealloc_fn\fP A replacement for realloc
.br
\fIfree_fn\fP A replacement for free\&.
.RE
.PP
.SH "Author"
.PP
Generated automatically by Doxygen for libevent from the source code\&.
|