util.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. * Copyright (c) 2002-2003 MontaVista Software, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Steven Dake (sdake@mvista.com)
  7. *
  8. * This software licensed under BSD license, the text of which follows:
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions are met:
  12. *
  13. * - Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * - Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  26. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  32. * THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #ifndef AIS_UTIL_H_DEFINED
  35. #define AIS_UTIL_H_DEFINED
  36. #include <pthread.h>
  37. #include <sys/poll.h>
  38. #include <sys/socket.h>
  39. #include "../include/ipc_gen.h"
  40. #ifdef SO_NOSIGPIPE
  41. #ifndef MSG_NOSIGNAL
  42. #define MSG_NOSIGNAL 0
  43. #endif
  44. void socket_nosigpipe(int s);
  45. #else
  46. #define socket_nosigpipe(s)
  47. #endif
  48. struct saHandleDatabase {
  49. unsigned int handleCount;
  50. struct saHandle *handles;
  51. pthread_mutex_t mutex;
  52. void (*handleInstanceDestructor) (void *);
  53. };
  54. struct saVersionDatabase {
  55. int versionCount;
  56. SaVersionT *versionsSupported;
  57. };
  58. struct queue {
  59. int head;
  60. int tail;
  61. int used;
  62. int usedhw;
  63. int size;
  64. void *items;
  65. int bytesPerItem;
  66. };
  67. SaAisErrorT
  68. saServiceConnect (
  69. int *fdOut,
  70. enum service_types service);
  71. SaAisErrorT
  72. saServiceConnectTwo (
  73. int *responseOut,
  74. int *callbackOut,
  75. enum service_types service);
  76. SaAisErrorT
  77. saRecvRetry (
  78. int s,
  79. void *msg,
  80. size_t len);
  81. SaAisErrorT
  82. saSendRetry (
  83. int s,
  84. const void *msg,
  85. size_t len);
  86. SaAisErrorT saSendMsgRetry (
  87. int s,
  88. struct iovec *iov,
  89. int iov_len);
  90. SaAisErrorT saSendMsgReceiveReply (
  91. int s,
  92. struct iovec *iov,
  93. int iov_len,
  94. void *responseMessage,
  95. int responseLen);
  96. SaAisErrorT saSendReceiveReply (
  97. int s,
  98. void *requestMessage,
  99. int requestLen,
  100. void *responseMessage,
  101. int responseLen);
  102. SaAisErrorT
  103. saPollRetry (
  104. struct pollfd *ufds,
  105. unsigned int nfds,
  106. int timeout);
  107. SaAisErrorT
  108. saHandleCreate (
  109. struct saHandleDatabase *handleDatabase,
  110. int instanceSize,
  111. SaUint64T *handleOut);
  112. SaAisErrorT
  113. saHandleDestroy (
  114. struct saHandleDatabase *handleDatabase,
  115. SaUint64T handle);
  116. SaAisErrorT
  117. saHandleInstanceGet (
  118. struct saHandleDatabase *handleDatabase,
  119. SaUint64T handle,
  120. void **instance);
  121. SaAisErrorT
  122. saHandleInstancePut (
  123. struct saHandleDatabase *handleDatabase,
  124. SaUint64T handle);
  125. SaAisErrorT
  126. saVersionVerify (
  127. struct saVersionDatabase *versionDatabase,
  128. SaVersionT *version);
  129. #define offset_of(type,member) (int)(&(((type *)0)->member))
  130. SaTimeT
  131. clustTimeNow(void);
  132. #endif /* AIS_UTIL_H_DEFINED */