su.docs 35.2 KB
Newer Older
Pekka Pessi's avatar
Pekka Pessi committed
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
/* -*- C -*- */

/**@mainpage Sofia OS Services and Utility Library
 *
 * @section su_meta Module Information
 *
 * The @b su module contains a simple, portable socket/timing/synchronizing
 * library developed for Sofia communications software.
 * 
 * @CONTACT Pekka Pessi <Pekka.Pessi@nokia.com>
 * 
 * @STATUS Core library
 * 
 * @LICENSE LGPL
 *
 * @section su_overview Overview
 *
 * The @b su module provides following interfaces for application programs:
 *
 * - su_types.h - integral types
 * - su.h - @ref su_socket 
 * - su_wait.h - @ref su_wait 
 * - su_time.h - @ref su_time
 * - su_alloc.h - @ref su_alloc
 * - su_log.h - @ref su_log
 * - su_tag.h - @ref su_tag
 * - su_md5.h - @ref su_md5
 * - su_uniqueid.h - @ref su_uniqueid 
 *
 * The @b su library also contains some collection datatypes:
 * - htable.h - @ref su_htable
 * - rbtree.h - balanced red-black trees
 * - su_strlst.h - @ref su_strlst
 * - su_vector.h - @ref su_vector
 *
 * There are also some convenience macros for unit test programs:
 * - tstdef.h - macros for unit tests
 *
 * @author Pekka Pessi <Pekka.Pessi@nokia.com>
 * @author Jari Selin <Jari.Selin@nokia.com>
 *
 * @par SU Debug Log
 *
Pekka Pessi's avatar
Pekka Pessi committed
44
 * The debugging output from @b su module is controlled by #su_log_global
Pekka Pessi's avatar
Pekka Pessi committed
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
 * log object. The environment variable #SU_DEBUG sets the default log
 * level.
 */

/**@maindefgroup su OS Utilities
 *
 * The "su" module contains OS utilies for Sofia.
 *
 * The @b su is a simple, portable socket/timing/synchronizing library
 * developed for Sofia communications software. Currently, interface to
 * it consists of following parts:
 *
 * - <a href=su_types_h.html>su_types</a> - basic integer types
 * - <a href=group_su_socket.html>su_socket</a> - socket functions
 * - <a href=group_su_wait.html>su_wait</a> - synchronization functions
 * - <a href=group_su_time.html>su_time</a> - time functions
 * - <a href=group_su_alloc.html>su_alloc</a> - memory management functions
 * - <a href=group_su_log.html>su_log</a> - generic logging functions
 * - <a href=group_su_tag.html>su_tag</a> - tag list function
 * - <a href=group_su_md5.html>su_md5</a> - MD5 hashing 
 */

/**@defgroup su_programs Shell Programs
 * 
 * The @b su module provides few shell utilities:
 * - @ref localinfo (localinfo.c)
 * - @ref addrinfo (addrinfo.c) 
 */

/**@defgroup su_socket Socket Functions
 *
 *  @brief The <su.h> contains the portable socket functions. 
 *
 *  The <su.h> contains following functions, macros, and types:
 *    - su_init(): initializes sockets
 *    - su_deinit(): deinitializes sockets
 *    - su_socket(): creates a socket
 *    - su_close(): closes a socket
 *    - su_ioctl(): ioctl to a socket
 *    - su_setreuseaddr(): set/reset reusing the addresses/ports for a socket
 *    - su_setblocking(): enables/disables blocking
 *    - su_isblocking(): checks if the previous call failed because it 
 *  	would have blocked
 *    - su_errno(): the latest socket error
 *    - su_perror(): prints the latest socket error message to stderr
 *    - su_strerror(): returns the given socket error message
 *    - su_perror2(): prints the  given socket error message to stderr
 *    - su_soerror(): returns the error code associated with the socket
 *    - su_getmsgsize(): return the number of bytes that can be recv()ed from
 *  	a socket
 *    - su_getlocalip(): return an IP address belonging to the local host
 *    - su_vsend(): scatter-gather send
 *    - su_vrecv(): scatter-gather receive
 *    - #su_iovec_t: structure holding scatter-gather IO vector
 */

/**@defgroup su_log Logging Interface
 *
 * Generic logging interface.
 *
 * The @b su_log submodule contains a generic logging interface. The
 * interface provides means for redirecting the log and filtering log
 * messages based on message priority.
 */

/**@defgroup su_htable Hash tables
 *
 * Hash tables.
 *
 * The hash table interface and implementation is defined in htable.h.
 * Example code and tests for the implementation is in htable_test.c.
 */


/* <a name="su_wallclock"></a>
 * <h3>Function @c su_wallclock() - get current time</h3>
 * 
 * <h4>Synopsis</h4>
 * 
 * <blockquote><pre>
 * #include &lt;su_time.h&gt;
 * 
 * void su_wallclock(su_time_t *tv);
 * </pre></blockquote>
 * 
 * <h4>Description</h4>
 * <blockquote>
 * Fills the @a tv with the current NTP timestamp.
 * </blockquote>
 * 
 * <h4>Parameters</h4>
 * <blockquote>
 * <table cellpadding=3 cellspacing=0 border=1>
 *   <tr><td>@c tv      <td>pointer to the timeval object
 * </table>
 * </blockquote>
 * 
 * <a name="su_now"></a>
 * <h3>Function @c su_now() - get current time</h3>
 * 
 * <h4>Synopsis</h4>
 * 
 * <blockquote><pre>
 * #include &lt;su_time.h&gt;
 * 
 * su_time_t su_now(void);
 * </pre></blockquote>
 * 
 * <h4>Description</h4>
 * <blockquote>
 * Return the current NTP timestamp.
 * </blockquote>
 * 
 * 
 * <h4>Return Value</h4>
 * <blockquote>
 * The structure containing the current NTP timestamp.
 * </blockquote>
 * 
 * <a name="su_time_print"></a>
 * <h3>Function @c su_time_print() - print an NTP timestamp</h3>
 * 
 * <h4>Synopsis</h4>
 * 
 * <blockquote><pre>
 * #include &lt;su_time.h&gt;
 * 
 * int su_time_print(char *s, int n, su_time_t const *tv);
 * </pre></blockquote>
 * 
 * <h4>Description</h4>
 * <blockquote>
 *  This function prints an NTP timestamp as a decimal number to the
 *  given buffer.
 * </blockquote>
 * 
 * <h4>Parameters</h4>
 * <blockquote>
 * <table cellpadding=3 cellspacing=0 border=1>
 *   <tr><td>@c char *s            <td>pointer to buffer
 *   <tr><td>@c int n              <td>buffer size
 *   <tr><td>@c su_time_t const tv <td>pointer to the timeval object
 * </table>
 * </blockquote>
 * 
 * <h4>Return Value</h4>
 * <blockquote>
 * The number of characters printed, excluding the final NUL.
 * </blockquote>
 * 
 * <a name="su_duration"></a>
 * <h3>Function @c su_duration() - return time difference in milliseconds</h3>
 * 
 * <h4>Synopsis</h4>
 * 
 * <blockquote><pre>
 * #include &lt;su_time.h&gt;
 * 
 * su_duration_t su_duration(su_time_t t1, su_time_t t2);
 * </pre></blockquote>
 * 
 * <h4>Description</h4>
 * <blockquote>
 * Calculates the duration in milliseconds from @a t2 to @a t1 in milliseconds. If the difference is bigger
 * than @c SU_MAX_DURATION, return @c SU_MAX_DURATION instead.
 * </blockquote>
 * 
 * <h4>Parameters</h4>
 * <blockquote>
 * <table cellpadding=3 cellspacing=0 border=1>
 *   <tr><td>@c t1      <td>after time
 *   <tr><td>@c t2      <td>before time
 * </table>
 * </blockquote>
 * 
 * <h4>Return Value</h4>
 * <blockquote>
 * The duration in milliseconds between the two times.
 * </blockquote>
 * 
 * <a name="su_alloc.h"></a>
 * <h1>&lt;su_alloc.h&gt;</h1>
 * 
 * This section describes memory management functions.
 * 
 * 
 * The
 * @c su_alloc library provides convenience functions for
 * memory management. The library defines an object @c su_home_t for
 * collecting multiple memory allocations under one handle.
 * 
 * <ul>
 *   - Function @c su_home_create()
 *       - create an su_home_t object
 * 
 *   - Function @c su_home_destroy()
 *       - free a home object
 * 
 *   - Function @c su_alloc()
 *       - allocate a memory block
 * 
 *   - Function @c su_zalloc()
 *       - allocate and zero a memory block
 * 
 *   - Function @c su_salloc()
 *       - allocate a structure
 * 
 *   - Function @c su_free()
 *       - free a memory block
 * 
 * </ul>
 * 
 * 
 * The functions for implementing objects derived from @c su_home_t
 * are as follows:
 * <ul>
 *   - Function @c su_home_init()
 *       - initialize an @c su_home_t object
 * 
 *   - Function @c su_home_deinit()
 *        - free memory blocks from home
 * 
 * </ul>
 * 
 * <a name="su_home_create"></a>
 * <h3>Function @c su_home_create() - create an su_home_t object</h3>
 * 
 * <h4>Synopsis</h4>
 * 
 * <blockquote><pre>
 * #include &lt;su_alloc.h&gt;
 * 
 * su_home_t *su_home_create(void);
 * </pre></blockquote>
 * 
 * <h4>Description</h4>
 * <blockquote>
 * The function @c su_home_create() creates a home object used to
 * collect multiple memory allocations under one handle, so that they can be
 * freed by calling <dfn>su_home_destroy()</dfn>.
 * </blockquote>
 * 
 * <h4>Return Value</h4>
 * <blockquote>
 * This function returns a pointer to an @c su_home_t object, or
 * @c NULL upon an error.
 * </blockquote>
 * 
 * <a name="su_home_destroy"></a>
 * <h3>Function @c su_home_destroy() - free a home object</h3>
 * 
 * <h4>Synopsis</h4>
 * 
 * <blockquote><pre>
 * #include &lt;su_alloc.h&gt;
 * 
 * void su_home_destroy(su_home_t *h);
 * </pre></blockquote>
 * 
 * <h4>Description</h4>
 * <blockquote>
 * The function @c su_home_destroy() frees a home object, and all
 * memory blocks associated with it.
 * </blockquote>
 * 
 * <h4>Parameters</h4>
 * <blockquote>
 * <table cellpadding=3 cellspacing=0 border=1>
 *   <tr><td>@c su_home_t *h <td>pointer to a home object
 * </table>
 * </blockquote>
 * 
 * <a name="su_alloc"></a>
 * <h3>Function @c su_alloc() - allocate a memory block</h3>
 * 
 * <h4>Synopsis</h4>
 * 
 * <blockquote><pre>
 * #include &lt;su_alloc.h&gt;
 * 
 * void *su_alloc(su_home_t *h, int  n);
 * </pre></blockquote>
 * 
 * <h4>Description</h4>
 * <blockquote>
 * The function @c su_alloc() allocates a memory block of a given size.
 * 
 * 
 * If @a h is @c NULL, this function behaves exactly like
 * @c malloc().
 * </blockquote>
 * 
 * <h4>Parameters</h4>
 * <blockquote>
 * <table cellpadding=3 cellspacing=0 border=1>
 *   <tr><td>@c su_home_t *h <td>pointer to a home object
 *   <tr><td>@c int n      <td>size of the memory block to be allocated
 * </table>
 * </blockquote>
 * 
 * <h4>Return Value</h4>
 * <blockquote>
 * This function returns a pointer to the allocated memory block, or
 * @c NULL, if an error occurred.
 * </blockquote>
 * 
 * <a name="su_zalloc"></a>
 * <h3>Function @c su_zalloc() - allocate and zero a memory block</h3>
 * 
 * <h4>Synopsis</h4>
 * 
 * <blockquote><pre>
 * #include &lt;su_alloc.h&gt;
 * 
 * void *su_zalloc(su_home_t *h, int  n)
 * </pre></blockquote>
 * 
 * <h4>Description</h4>
 * <blockquote>
 * The function @c su_zalloc() allocates a memory block with a given
 * size and zeroes the allocated block.
 * </blockquote>
 * 
 * <h4>Parameters</h4>
 * <blockquote>
 * <table cellpadding=3 cellspacing=0 border=1>
 *   <tr><td>@c su_home_t *h <td>pointer to a home object
 *   <tr><td>@c int n      <td>size of the memory block to be allocated
 * </table>
 * </blockquote>
 * 
 * <h4>Return Value</h4>
 * <blockquote>
 * This function returns a pointer to the allocated memory block, or
 * @c NULL, if an error occurred.
 * </blockquote>
 * 
 * <a name="su_salloc"></a>
 * <h3>Function @c su_salloc() - allocate a structure</h3>
 * 
 * <h4>Synopsis</h4>
 * 
 * <blockquote><pre>
 * #include &lt;su_alloc.h&gt;
 * 
 * void *su_salloc(su_home_t *h, int  s);
 * </pre></blockquote>
 * 
 * <h4>Description</h4>
 * <blockquote>
 * The function su_salloc() allocates a structure with a given size,
 * zeros it, and initializes the size field to the given size.
 * </blockquote>
 * 
 * <h4>Parameters</h4>
 * <blockquote>
 * <table cellpadding=3 cellspacing=0 border=1>
 *   <tr><td>@c su_home_t *h <td>pointer to a home object
 *   <tr><td>@c int n      <td>size of the structure to be allocated
 * </table>
 * </blockquote>
 * 
 * <h4>Return Value</h4>
 * <blockquote>
 * This function returns a pointer to the allocated memory block, or
 * @c NULL, if an error occurred.
 * </blockquote>
 * 
 * <a name="su_free"></a>
 * <h3>Function @c su_free() - free a memory block</h3>
 * 
 * <h4>Synopsis</h4>
 * 
 * <blockquote><pre>
 * #include &lt;su_alloc.h&gt;
 * 
 * void su_free(su_home_t *h, void *vb);
 * </pre></blockquote>
 * 
 * <h4>Description</h4>
 * <blockquote>
 * The function @c su_free() frees a single memory block.
 * </blockquote>
 * 
 * <h4>Parameters</h4>
 * <blockquote>
 * <table cellpadding=3 cellspacing=0 border=1>
 *   <tr><td>@c su_home_t *h  <td>pointer to a home object
 *   <tr><td>@c void      *vb <td>pointer to the memory block to be freed
 * </table>
 * </blockquote>
 * 
 * <h4>Return Value</h4>
 * <blockquote>
 * </blockquote>
 * 
 * <a name="su_home_init"></a>
 * <h3>Function @c su_home_init() - initialize an @c su_home_t object</h3>
 * 
 * <h4>Synopsis</h4>
 * 
 * <blockquote><pre>
 * #include &lt;su_alloc.h&gt;
 * 
 * int su_home_init(su_home_t *h);
 * </pre></blockquote>
 * 
 * <h4>Description</h4>
 * <blockquote>
 * The function @c su_home_init() initializes an object derived from
 * @c su_home_t. It checks that the @a suh_size field is valid.
 * </blockquote>
 * 
 * <h4>Parameters</h4>
 * <blockquote>
 * <table cellpadding=3 cellspacing=0 border=1>
 *   <tr><td>@c su_home_t *h <td>pointer to a home object
 * </table>
 * </blockquote>
 * 
 * <h4>Return Value</h4>
 * <blockquote>
 * The function @c su_home_init() returns @c 0 when
 * successful, or @c -1 upon an error.
 * </blockquote>
 * 
 * <h4>Note</h4>
 * <blockquote><strong>This is an internal function, and it is intended for
 * implementing the objects derived from @c su_home_t.</strong>
 * </blockquote>
 * 
 * <a name="su_home_deinit"></a>
 * <h3>Function @c su_home_deinit() - free memory blocks from home </h3>
 * 
 * <h4>Synopsis</h4>
 * 
 * <blockquote><pre>
 * #include &lt;su_alloc.h&gt;
 * 
 * void su_home_deinit(su_home_t *h);
 * </pre></blockquote>
 * 
 * <h4>Description</h4>
 * <blockquote>
 * The function @c su_home_deinit() frees the memory blocks
 * associated with the home object.
 * </blockquote>
 * 
 * <h4>Parameters</h4>
 * <blockquote>
 * <table cellpadding=3 cellspacing=0 border=1>
 *   <tr><td>@c su_home_t *h <td>pointer to a home object
 * </table>
 * </blockquote>
 * 
 * <h4>Note</h4>
 * <blockquote><strong>This is an internal function, and it is intended for
 * implementing the objects derived from @c su_home_t.</strong>
 * </blockquote>
 * 
 * 
 * <a name="su_wait.h"></a>
 * <h1>&lt;su_wait.h&gt;</h1>
 * 
 * This section describes synchronization functionality.
 * The @c su_wait library provides portable synchronization
 * primitives needed for running communication software.
 * 
 * Synchronization means that the program can stop waiting for events,
 * set callback functions for events, schedule timers, and set callback
 * functions for timers. In other words, it is an OS-independent
 * @c poll()/@c select()/@c WaitForMultipleObjects()
 * interface, spiced up with timer interface.
 * 
 * The library provides three kinds of objects: root
 * objects (@c su_root_t), wait objects
 * (@c su_wait_t), and timer objects
 * (@c su_timer_t).
 * 
 * <a name="wait"></a>
 * <h2>Wait Objects</h2>
 * 
 * 
 *   Wait objects are used to signal I/O events to the process.
 *   The events are as follows:
 * 
 * <dl>
 *   <dt>SU_WAIT_IN
 *   <dd>incoming data is available
 * 
 *   <dt>SU_WAIT_OUT
 *   <dd>data can be output
 * 
 *   <dt>SU_WAIT_ERR
 *   <dd>an error occurred
 * 
 *   <dt>SU_WAIT_HUP
 *   <dd>the socket connection was closed
 * 
 *   <dt>SU_WAIT_ACCEPT
 *   <dd>a listening socket accepted a new connection attempt
 * </dl>
 * 
 * 
 *   It is possible to combine several events with |, binary or operator.
 * 
 * 
 *   Public API contains functions as follows:
 * <ul>
 *   - su_wait_create()
 *   - su_wait_destroy()
 *   - su_wait()
 *   - su_wait_events()
 * </ul>
 * 
 * 
 *   In Unix, the wait object is @c struct poll. The structure contains a file
 *   handle, a mask describing expected events, and a mask containing the
 *   occurred events after calling @c poll(), ie. @c su_wait().
 * 
 * 
 *   In Windows, the wait object is a @c HANDLE (a descriptor of a Windows
 *   kernel entity).
 * 
 * 
 * <a name="su_wait_create"></a>
 * <h3>Function @c su_wait_create()</h3>
 * 
 * <h4>Synopsis</h4>
 * 
 * <blockquote><pre>
 * #include &lt;su_wait.h&gt;
 * 
 * int su_wait_create(su_wait_t *newwait, su_socket_t socket, int events)</pre></blockquote>
 * 
 * <h4>Description</h4>
 * 
 * <blockquote>
 * @c Su_wait_create() creates a new wait object for a
 * @a socket with given @a events.  The new wait object is
 * assigned to the @a newwait parameter.
 * </blockquote>
 * 
 * <h4>Parameters</h4>
 * 
 * <blockquote>
 * <table cellpadding=3 cellspacing=0 border=1>
 *   <tr><td>@c newwait<td>the newly created wait object
 *   <tr><td>@c socket <td>socket descriptor
 *   <tr><td>@c events <td>mask for events that can signal this wait object
 * </table>
 * </blockquote>
 * 
 * <h4>Return Value</h4>
 * 
 * <blockquote>
 * 0 if the call was successful, -1 otherwise.
 * </blockquote>
 * 
 * <a name="su_wait_destroy"></a>
 * <h3>Function @c su_wait_destroy()</h3>
 * 
 * <h4>Synopsis</h4>
 * 
 * <blockquote><pre> #include &lt;su_wait.h&gt;
 * 
 * int su_wait_destroy(su_wait_t *waitobj);
 * </pre></blockquote>
 * 
 * <h4>Description</h4>
 * <blockquote>Destroy a wait object.
 * </blockquote>
 * 
 * 
 * <h4>Parameters</h4>
 * 
 * <blockquote>
 * <table cellpadding=3 cellspacing=0 border=1>
 *   <tr><td>@c waitobj <td>pointer to wait object
 * </table>
 * </blockquote>
 * 
 * <h4>Return Value</h4>
 * 
 * <blockquote>
 * 0 when successful, -1 upon an error.
 * </blockquote>
 * 
 * <a name="su_wait"></a>
 * <h3>Function @c su_wait()</h3>
 * 
 * <h4>Synopsis</h4>
 * 
 * <blockquote><pre>
 * #include &lt;su_wait.h&gt;
 * 
 * int su_wait(su_wait_t waits[], unsigned n, long timeout);
 * </pre></blockquote>
 * 
 * <h4>Description</h4>
 * <blockquote>  Block until a event specified by wait objects or a timeout occurs.
 * 
 * 
 *   In Unix, this is poll.
 * 
 * 
 *   In Windows, this is WSAWaitForMultipleEvents
 * </blockquote>
 * 
 * <h4>Parameters</h4>
 * <blockquote>
 * <table cellpadding=3 cellspacing=0 border=1>
 *   <tr><td>@c waits   <td>array of wait objects
 *   <tr><td>@c n       <td>number of wait objects in array waits
 *   <tr><td>@c timeout <td>timeout in milliseocnds
 * </table>
 * </blockquote>
 * 
 * <h4>Return Value</h4>
 * <blockquote>
 *   Index of the signaled wait object, if any, SU_WAIT_TIMEOUT if timeout
 *   occurred, and -1 upon an error.
 * </blockquote>
 * 
 * <a name="su_wait_events"></a>
 * <h3>Function @c su_wait_events()</h3>
 * 
 * <h4>Synopsis</h4>
 * 
 * <blockquote><pre>
 * #include &lt;su_wait.h&gt;
 * 
 * int su_wait_events(su_wait_t *waitobj, su_socket_t s);
 * </pre></blockquote>
 * 
 * <h4>Description</h4>
 * <blockquote>  Return an mask describing events occurred.
 * </blockquote>
 * 
 * 
 * <h4>Parameters</h4>
 * <blockquote>
 * <table cellpadding=3 cellspacing=0 border=1>
 *   <tr><td>@c waitobj  <td>pointer to wait object
 *   <tr><td>@c s        <td>socket
 * </table>
 * </blockquote>
 * 
 * <h4>Return Value</h4>
 * <blockquote>  Binary mask describing the events.
 * </blockquote>
 * 
 * <a name="su_wait_mask"></a>
 * <h3>Function @c su_wait_mask()</h3>
 * 
 * <h4>Synopsis</h4>
 * 
 * <blockquote><pre>
 * #include &lt;su_wait.h&gt;
 * 
 * int su_wait_mask(su_wait_t *waitobj, su_socket_t s, int events);
 * </pre></blockquote>
 * 
 * <h4>Description</h4>
 * <blockquote>
 *   Sets the mask describing events that can signal the wait object.
 * </blockquote>
 * 
 * <h4>Parameters</h4>
 * <blockquote>
 * <table cellpadding=3 cellspacing=0 border=1>
 *   <tr><td>@c waitobj  <td>pointer to wait object
 *   <tr><td>@c s        <td>socket
 *   <tr><td>@c events   <td>new event mask
 * </table>
 * </blockquote>
 * 
 * <h4>Return Value</h4>
 * <blockquote>
 *   0 when successful, -1 upon an error.
 * </blockquote>
 * 
 * <a name="root"></a>
 * <h2>Root objects</h2>
 * 
 * 
 *    Root object is a structure containing a list of wait objects,
 *    associated callback functions, and arguments to these functions.
 *    It can also contain a list of timers, and a magic cookie (a pointer
 *    defined by root object user.)
 * 
 * 
 *    The public API contains following functions:
 * <ul>
 *   - su_root_create()
 *   - su_root_destroy()
 *   - su_root_magic()
 *   - su_root_register()
 *   - su_root_unregister()
 *   - su_root_run()
 *   - su_root_break()
 *   - su_root_step()
 * </ul>
 * 
 * These functions are intended for implementing su_root API:
 * <ul>
 *   - su_root_init()
 *   - su_root_deinit()
 *   - su_root_query()
 *   - su_root_event()
 * </ul>
 * 
 * <a name="su_root_create"></a>
 * <h3>Function @c su_root_create()</h3>
 * 
 * <h4>Synopsis</h4>
 * 
 * <blockquote><pre>
 * #include &lt;su_wait.h&gt;
 * 
 * su_root_t *su_root_create(su_root_magic_t *magic);
 * </pre></blockquote>
 * 
 * <h4>Description</h4>
 * <blockquote> Allocate and initialize an instance of su_root_t
 * </blockquote>
 * 
 * 
 * <h4>Parameters</h4>
 * <blockquote>
 * <table cellpadding=3 cellspacing=0 border=1>
 *   <tr><td>@c magic    <td>pointer to user data
 * </table>
 * </blockquote>
 * 
 * <h4>Return Value</h4>
 * <blockquote>  A pointer to allocated su_root_t instance, NULL on error.
 * </blockquote>
 * 
 * 
 * <a name="su_root_destroy"></a>
 * <h3>Function @c su_root_destroy()</h3>
 * 
 * <h4>Synopsis</h4>
 * 
 * <blockquote><pre>
 * #include &lt;su_wait.h&gt;
 * 
 * void su_root_destroy(su_root_t *root);
 * </pre></blockquote>
 * 
 * <h4>Description</h4>
 * <blockquote> Deinitialize and free an instance of su_root_t
 * </blockquote>
 * 
 * 
 * <h4>Parameters</h4>
 * <blockquote>
 * <table cellpadding=3 cellspacing=0 border=1>
 *   <tr><td>@c root    <td>pointer to a root structure
 * </table>
 * </blockquote>
 * 
 * 
 * <a name="su_root_magic"></a>
 * <h3>Function @c su_root_magic()</h3>
 * 
 * <h4>Synopsis</h4>
 * 
 * <blockquote><pre>
 * #include &lt;su_wait.h&gt;
 * 
 * su_root_magic_t *su_root_magic(su_root_t *root);
 * </pre></blockquote>
 * 
 * <h4>Description</h4>
 * <blockquote> Return the user data pointer that was given input to su_root_create() or
 * 
 *  su_root_init().
 * </blockquote>
 * 
 * <h4>Parameters</h4>
 * <blockquote>
 * <table cellpadding=3 cellspacing=0 border=1>
 *   <tr><td>@c root     <td>pointer to a root object
 * </table>
 * </blockquote>
 * 
 * <h4>Return Value</h4>
 * <blockquote>  A pointer to user data
 * </blockquote>
 * 
 * 
 * <a name="su_root_register"></a>
 * <h3>Function @c su_root_register()</h3>
 * 
 * <h4>Synopsis</h4>
 * 
 * <blockquote><pre>
 * #include &lt;su_wait.h&gt;
 * 
 * int su_root_register(su_root_t *root,
 * 		     su_wait_t *waits,
 * 		     su_wakeup_f callback,
 * 		     su_wakeup_arg_t arg,
 * 		     int priority);
 * </pre></blockquote>
 * 
 * <h4>Description</h4>
 * <blockquote> Register a su_wait_t object. The wait object, a callback function and
 * 
 *  a argument is stored to the root object. The callback function is called,
 *  when the wait object is signaled.
 * 
 *  Please note if identical wait objects are inserted, only first one is
 *  ever signalled.
 * </blockquote>
 * 
 * <h4>Parameters</h4>
 * <blockquote>
 * <table cellpadding=3 cellspacing=0 border=1>
 *   <tr><td>@c root     <td>pointer to root object
 *   <tr><td>@c waits    <td>pointer to wait object
 *   <tr><td>@c callback <td>callback function pointer
 *   <tr><td>@c arg      <td>argument given to callback function when it is invoked
 *   <tr><td>@c priority <td>relative priority of the wait object
 *              (0 is normal, 1 important, 2 realtime)
 * </table>
 * </blockquote>
 * 
 * <h4>Return Value</h4>
 * <blockquote>  Index of the wait object, or -1 upon an error.
 * </blockquote>
 * 
 * 
 * <a name="su_root_unregister"></a>
 * <h3>Function @c su_root_unregister()</h3>
 * 
 * <h4>Synopsis</h4>
 * 
 * <blockquote><pre>
 * #include &lt;su_wait.h&gt;
 * 
 * int su_root_unregister(su_root_t *root,
 * 		       su_wait_t *wait,
 * 		       su_wakeup_f callback,
 * 		       su_wakeup_arg_t arg);
 * </pre></blockquote>
 * 
 * <h4>Description</h4>
 * <blockquote> UnRegisters a su_wait_t object. The wait object, a callback function and
 * 
 *  a argument are removed from the root object. The callback function is called,
 *  when the wait object is signaled.
 * </blockquote>
 * 
 * <h4>Parameters</h4>
 * <blockquote>
 * <table cellpadding=3 cellspacing=0 border=1>
 *   <tr><td>@c root     <td>pointer to root object
 *   <tr><td>@c waits    <td>pointer to wait object
 *   <tr><td>@c callback <td>callback function pointer (may be NULL)
 *   <tr><td>@c arg      <td>argument given to callback function when it
 *                                 is invoked (may be NULL)
 * </table>
 * </blockquote>
 * 
 * <h4>Return Value</h4>
 * <blockquote>  Index of the wait object, or -1 upon an error.
 * </blockquote>
 * 
 * 
 * <a name="su_root_run"></a>
 * <h3>Function @c su_root_run()</h3>
 * 
 * <h4>Synopsis</h4>
 * 
 * <blockquote><pre>
 * #include &lt;su_wait.h&gt;
 * 
 * void su_root_run(su_root_t *root);
 * </pre></blockquote>
 * 
 * <h4>Description</h4>
 * <blockquote>  This function waits for wait objects and the timers associated with
 *   the root object.  When any wait object is signaled or timer is
 *   expired, it invokes the callbacks, and returns waiting.
 * 
 * 
 *   This function returns when su_root_break() is called from a callback.
 * </blockquote>
 * 
 * <h4>Parameters</h4>
 * <blockquote>
 * <table cellpadding=3 cellspacing=0 border=1>
 *   <tr><td>@c root     <td>pointer to root object
 * </table>
 * </blockquote>
 * 
 * 
 * <a name="su_root_break"></a>
 * <h3>Function @c su_root_break()</h3>
 * 
 * <h4>Synopsis</h4>
 * 
 * <blockquote><pre>
 * #include &lt;su_wait.h&gt;
 * 
 * void su_root_break(su_root_t *root);
 * </pre></blockquote>
 * 
 * <h4>Description</h4>
 * <blockquote>  If this function is used to terminate execution of su_root_run(). It
 * 
 *   can be called from a callback function.
 * </blockquote>
 * 
 * <h4>Parameters</h4>
 * <blockquote>
 * <table cellpadding=3 cellspacing=0 border=1>
 *   <tr><td>@c root     <td>pointer to root object
 * </table>
 * </blockquote>
 * 
 * 
 * <a name="su_root_step"></a>
 * <h3>Function @c su_root_step()</h3>
 * 
 * <h4>Synopsis</h4>
 * 
 * <blockquote><pre>
 * #include &lt;su_wait.h&gt;
 * 
 * su_duration_t su_root_step(su_root_t *root, su_duration_t tout);
 * </pre></blockquote>
 * 
 * <h4>Description</h4>
 * <blockquote>  This function waits for wait objects and the timers associated with
 *   the @a root object.  When any wait object is signaled or timer is
 *   expired, it invokes the callbacks, and returns.
 * 
 * 
 *   This function returns when a callback has been invoked or @a tout
 *   milliseconds is elapsed.
 * </blockquote>
 * 
 * <h4>Parameters</h4>
 * <blockquote>
 * <table cellpadding=3 cellspacing=0 border=1>
 *   <tr><td>@c root     <td>pointer to root object
 *   <tr><td>@c tout     <td>timeout in milliseconds
 * </table>
 * </blockquote>
 * 
 * <h4>Return Value</h4>
 * <blockquote>
 *   Milliseconds to the next invocation of timer, or SU_WAIT_FOREVER if
 *   there are no active timers.
 * </blockquote>
 * 
 * <a name="timer"></a>
 * <h2>Timer objects</h2>
 * 
 * Timers are used to schedule some task to be executed at given time or
 * after a default interval. The default interval is specified when the
 * timer is created. We call timer activation "setting the timer", and
 * deactivation "resetting the timer" (as in SDL). When the given time has
 * arrived or the default interval has elapsed, the timer expires and
 * it is ready for execution.
 * 
 * These functions are available for handling timers:
 * 
 * - su_timer_create()
 *   - su_timer_destroy()
 *   - su_timer_set()
 *   - su_timer_set_at()
 *   - su_timer_reset()
 *   - su_timer_run()
 * 
 * <a name="su_timer_create"></a>
 * <h3>Function @c su_timer_create()</h3>
 * 
 * <h4>Synopsis</h4>
 * 
 * <blockquote><pre>
 * #include &lt;su_wait.h&gt;
 * 
 * su_timer_t *su_timer_create(su_root_t *root, su_duration_t msec);
 * </pre></blockquote>
 * 
 * <h4>Description</h4>
 * 
 * <blockquote>
 * Allocate and initialize an instance of su_timer_t.
 * </blockquote>
 * 
 * <h4>Parameters</h4>
 * <blockquote>
 * <table cellpadding=3 cellspacing=0 border=1>
 *  <tr><td>@c root   <td>the root object with which the timer will be associated
 *  <tr><td>@c msec   <td>the default duration of the timer
 * </table>
 * </blockquote>
 * 
 * <h4>Return Value</h4>
 * <blockquote>  A pointer to allocated timer instance, NULL on error.
 * </blockquote>
 * 
 * 
 * <a name="su_timer_destroy"></a>
 * <h3>Function @c su_timer_destroy()</h3>
 * 
 * <h4>Synopsis</h4>
 * 
 * <blockquote><pre>
 * #include &lt;su_wait.h&gt;
 * 
 * void su_timer_destroy(su_timer_t *t);
 * </pre></blockquote>
 * 
 * <h4>Description</h4>
 * <blockquote> Deinitialize and free an instance of su_timer_t.
 * </blockquote>
 * 
 * 
 * <h4>Parameters</h4>
 * <blockquote>
 * <table cellpadding=3 cellspacing=0 border=1>
 *   <tr><td>@c t      <td>pointer to the timer object
 * </table>
 * </blockquote>
 * 
 * 
 * <a name="su_timer_set"></a>
 * <h3>Function @c su_timer_set()</h3>
 * 
 * <h4>Synopsis</h4>
 * 
 * <blockquote><pre>
 * #include &lt;su_wait.h&gt;
 * 
 * int su_timer_set(su_timer_t *t,
 * 		 su_timer_f wakeup,
 * 		 su_wakeup_arg_t arg);
 * </pre></blockquote>
 * 
 * <h4>Description</h4>
 * <blockquote> Sets the given timer to expire after the default duration.
 * 
 * The timer must have an default duration.
 * </blockquote>
 * 
 * <h4>Parameters</h4>
 * <blockquote>
 * <table cellpadding=3 cellspacing=0 border=1>
 *   <tr><td>@c t      <td>pointer to the timer object
 *   <tr><td>@c wakeup <td>pointer to the wakeup function
 *   <tr><td>@c arg    <td>argument given to the wakeup function
 * </table>
 * </blockquote>
 * 
 * <h4>Return Value</h4>
 * <blockquote>  0 if successful, -1 otherwise.
 * </blockquote>
 * 
 * 
 * <a name="su_timer_set_at"></a>
 * <h3>Function @c su_timer_set_at()</h3>
 * 
 * <h4>Synopsis</h4>
 * 
 * <blockquote><pre>
 * #include &lt;su_wait.h&gt;
 * 
 * int su_timer_set_at(su_timer_t *t,
 * 		    su_timer_f wakeup,
 * 		    su_wakeup_arg_t arg,
 * 		    su_time_t when);
 * </pre></blockquote>
 * 
 * <h4>Description</h4>
 * <blockquote> Sets the timer to expire at given time.
 * </blockquote>
 * 
 * 
 * <h4>Parameters</h4>
 * <blockquote>
 * <table cellpadding=3 cellspacing=0 border=1>
 *   <tr><td>@c t      <td>pointer to the timer object
 *   <tr><td>@c wakeup <td>pointer to the wakeup function
 *   <tr><td>@c arg    <td>argument given to the wakeup function
 *   <tr><td>@c when   <td>time structure defining the wakeup time
 * </table>
 * </blockquote>
 * 
 * <h4>Return Value</h4>
 * <blockquote>  0 if successful, -1 otherwise.
 * </blockquote>
 * 
 * 
 * <a name="su_timer_reset"></a>
 * <h3>Function @c su_timer_reset()</h3>
 * 
 * <h4>Synopsis</h4>
 * 
 * <blockquote><pre>
 * #include &lt;su_wait.h&gt;
 * 
 * int su_timer_reset(su_timer_t *t);
 * </pre></blockquote>
 * 
 * <h4>Description</h4>
 * <blockquote>  Resets the given timer.
 * </blockquote>
 * 
 * 
 * <h4>Parameters</h4>
 * <blockquote>
 * <table cellpadding=3 cellspacing=0 border=1>
 *   <tr><td>@c t      <td>pointer to the timer object
 * </table>
 * </blockquote>
 * 
 * <h4>Return Value</h4>
 * <blockquote>  0 if successful, -1 otherwise.
 * </blockquote>
 * 
 * <a name="su_timer_run"></a>
 * <h3>Function @c su_timer_run()</h3>
 * 
 * <h4>Synopsis</h4>
 * 
 * <blockquote><pre>
 * #include &lt;su_wait.h&gt;
 * 
 * su_duration_t su_timer_run(su_timer_t ** const t0, su_duration_t tout);
 * </pre></blockquote>
 * 
 * <h4>Description</h4>
 * <blockquote>  Expires and executes expired timers in queue.
 * </blockquote>
 * 
 * 
 * <h4>Parameters</h4>
 * <blockquote>
 * <table cellpadding=3 cellspacing=0 border=1>
 *   <tr><td>@c t0     <td>pointer to the timer queue
 *   <tr><td>@c tout   <td>timeout in milliseconds
 * </table>
 * </blockquote>
 * 
 * <h4>Return Value</h4>
 * <blockquote>
 *  The duration in milliseconds before the next timer expires, or timeout (2**31 - 1
 *  ms), whichever is shorter.
 * </blockquote>
 * 
 * <!--
 * Root object is used for synchronizing. There must be one root object per
 * thread. There are two alternative ways for creating a root object. If you
 * are just using su_root_t, and don't want to <a
 * href="#inherit_su_root_t">inherit from it</a>, you can use
 * @c su_create().
 * -->
 * 
 * <a name="su_wait_internal.h"></a>
 * <h1>&lt;su_wait_internal.h&gt;</h1>
 * 
 * 
 * This section contains the internal functions, that is, functions used to
 * implement objects in @c &lt;su_wait.h&gt;.
 * 
 * <a name="su_root_init"></a>
 * <h3>Function @c su_root_init()</h3>
 * 
 * <h4>Synopsis</h4>
 * 
 * <blockquote><pre>
 * #include &lt;su_wait.h&gt;
 * #include &lt;su_wait_internal.h&gt;
 * 
 * int su_root_init(su_root_t *root, su_root_magic_t *magic);
 * </pre></blockquote>
 * 
 * <h4>Description</h4>
 * 
 * <blockquote>
 * 
 * Initialize an instance of @c su_root_t. The caller should allocate
 * the memory required for su_root_t, and set the sur_size to the size of the
 * allocated structure.
 * 
 * </blockquote>
 * 
 * <h4>Parameters</h4>
 * 
 * <blockquote>
 * <table cellpadding=3 cellspacing=0 border=1>
 *   <tr><td>@c root    <td>pointer to a uninitialized root structure
 * </table>
 * </blockquote>
 * 
 * <h4>Return Value</h4>
 * <blockquote>  0 when call was successful, -1 otherwise.
 * </blockquote>
 * 
 * 
 * <h4>Note</h4>
 * <blockquote>
 * <strong>This is an internal function, and it is intended for implementing
 * the objects derived from @c su_root_t.</strong>
 * </blockquote>
 * 
 * 
 * <a name="su_root_deinit"></a>
 * <h3>Function @c su_root_deinit()</h3>
 * 
 * <h4>Synopsis</h4>
 * 
 * <blockquote><pre>
 * #include &lt;su_wait.h&gt;
 * #include &lt;su_wait_internal.h&gt;
 * 
 * void su_root_deinit(su_root_t *root);
 * </pre></blockquote>
 * 
 * <h4>Description</h4>
 * <blockquote> Deinitialize an instance of su_root_t
 * </blockquote>
 * 
 * 
 * <h4>Parameters</h4>
 * <blockquote>
 * <table cellpadding=3 cellspacing=0 border=1>
 *   <tr><td>@c root    <td>pointer to a root structure
 * </table>
 * </blockquote>
 * 
 * <h4>Note</h4>
 * <blockquote>  <strong>This is an internal function, and it is intended for
 * implementing the objects derived from @c su_root_t.</strong>
 * </blockquote>
 * 
 * <a name="su_root_query"></a>
 * <h3>Function @c su_root_query()</h3>
 * 
 * <h4>Synopsis</h4>
 * 
 * <blockquote><pre>
 * #include &lt;su_wait.h&gt;
 * #include &lt;su_wait_internal.h&gt;
 * 
 * unsigned su_root_query(su_root_t *root, su_wait_t *waits, unsigned n_waits);
 * </pre></blockquote>
 * 
 * <h4>Description</h4>
 * <blockquote> Copies the su_wait_t objects from the root. The number of wait objects
 * 
 *  can be found out by calling su_root_query() with n_waits as zero.
 * </blockquote>
 * 
 * <h4>Parameters</h4>
 * <blockquote>
 * <table cellpadding=3 cellspacing=0 border=1>
 *   <tr><td>@c waits    <td>pointer to array to which wait objects are copied
 *   <tr><td>@c root     <td>pointer to root object
 *   <tr><td>@c n_waits  <td>number of wait objects fitting in array waits
 * </table>
 * </blockquote>
 * 
 * <h4>Return Value</h4>
 * <blockquote>  Number of wait objects, or 0 upon an error.
 * </blockquote>
 * 
 * 
 * <h4>Note</h4>
 * <blockquote><strong>This is an internal function, and it is intended for
 * implementing the objects derived from @c su_root_t.</strong>
 * </blockquote>
 * 
 * 
 * <a name="su_root_event"></a>
 * <h3>Function @c su_root_event()</h3>
 * 
 * <h4>Synopsis</h4>
 * 
 * <blockquote><pre>
 * #include &lt;su_wait.h&gt;
 * #include &lt;su_wait_internal.h&gt;
 * 
 * void su_root_event(su_root_t *root, su_wait_t *waitobj);
 * </pre></blockquote>
 * 
 * <h4>Description</h4>
 * <blockquote>  Invokes the callback function associated with the wait object.
 * 
 * 
 *   If waitobj is NULL, check if a wait object associated with root is
 *   signaled, and its callback is invoked.
 * </blockquote>
 * 
 * <h4>Parameters</h4>
 * <blockquote>
 * <table cellpadding=3 cellspacing=0 border=1>
 *   <tr><td>@c root     <td>pointer to root object
 *   <tr><td>@c waitobj    <td>pointer to wait object, or NULL
 * </table>
 * </blockquote>
 * 
 * <h4>Note</h4>
 * <blockquote><strong>This is an internal function, and it is intended for
 * implementing the objects derived from @c su_root_t.</strong>
 * </blockquote>
 * 
 */