PageRenderTime 42ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/ORBit2-2.14.19/linc2/src/linc-private.h

#
C Header | 220 lines | 149 code | 43 blank | 28 comment | 15 complexity | 5284bb3b4aad08350feea2100047f282 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0
  1. /*
  2. * linc-private.h: This file is part of the linc library.
  3. *
  4. * Authors:
  5. * Elliot Lee (sopwith@redhat.com)
  6. * Michael Meeks (michael@ximian.com)
  7. * Mark McLouglin (mark@skynet.ie) & others
  8. *
  9. * Copyright 2001, Red Hat, Inc., Ximian, Inc.,
  10. * Sun Microsystems, Inc.
  11. */
  12. #ifndef _LINK_PRIVATE_H_
  13. #define _LINK_PRIVATE_H_
  14. #include "config.h"
  15. #include <linc/linc.h>
  16. #include "linc-debug.h"
  17. #ifdef LINK_SSL_SUPPORT
  18. #include <openssl/ssl.h>
  19. #include <openssl/bio.h>
  20. extern SSL_METHOD *link_ssl_method;
  21. extern SSL_CTX *link_ssl_ctx;
  22. #endif /* LINK_SSL_SUPPORT */
  23. typedef struct {
  24. enum {
  25. LINK_COMMAND_DISCONNECT,
  26. LINK_COMMAND_SET_CONDITION,
  27. LINK_COMMAND_SET_IO_THREAD,
  28. LINK_COMMAND_CNX_UNREF
  29. } type;
  30. } LinkCommand;
  31. typedef struct {
  32. LinkCommand cmd;
  33. gboolean complete;
  34. } LinkSyncCommand;
  35. typedef struct {
  36. LinkCommand cmd;
  37. LinkConnection *cnx;
  38. GIOCondition condition;
  39. } LinkCommandSetCondition;
  40. typedef struct {
  41. LinkCommand cmd;
  42. LinkConnection *cnx;
  43. } LinkCommandDisconnect;
  44. typedef struct {
  45. LinkSyncCommand cmd;
  46. LinkConnection *cnx;
  47. } LinkCommandCnxUnref;
  48. void link_exec_command (LinkCommand *cmd);
  49. void link_connection_exec_disconnect (LinkCommandDisconnect *cmd, gboolean immediate);
  50. void link_connection_exec_set_condition (LinkCommandSetCondition *cmd, gboolean immediate);
  51. void link_connection_exec_cnx_unref (LinkCommandCnxUnref *cmd, gboolean immediate);
  52. /*
  53. * Really raw internals, exported for the tests
  54. */
  55. struct _LinkServerPrivate {
  56. int fd;
  57. LinkWatch *tag;
  58. GSList *connections;
  59. };
  60. struct _LinkWriteOpts {
  61. gboolean block_on_write;
  62. };
  63. struct _LinkConnectionPrivate {
  64. #ifdef LINK_SSL_SUPPORT
  65. SSL *ssl;
  66. #endif
  67. LinkWatch *tag;
  68. int fd;
  69. gulong max_buffer_bytes;
  70. gulong write_queue_bytes;
  71. GList *write_queue;
  72. /*
  73. * This flag is used after a LincConnection is disconnected when
  74. * an attempt to made to retry the connection. If the attempt returns
  75. * EINPROGRESS and subsequently is reported as disconnected we want
  76. * to avoid emitting another "broken" signal.
  77. */
  78. gboolean was_disconnected;
  79. #ifdef CONNECTION_DEBUG
  80. guint64 total_read_bytes;
  81. guint64 total_written_bytes;
  82. #endif
  83. };
  84. typedef struct {
  85. GSource source;
  86. GIOChannel *channel;
  87. GPollFD pollfd;
  88. #ifdef G_OS_WIN32
  89. LinkWatch *link_watch;
  90. SOCKET socket;
  91. int event_mask;
  92. gboolean write_would_have_blocked;
  93. #endif
  94. GIOCondition condition;
  95. GIOFunc callback;
  96. gpointer user_data;
  97. } LinkUnixWatch;
  98. struct _LinkWatch {
  99. GSource *main_source;
  100. GSource *link_source;
  101. #ifdef G_OS_WIN32
  102. LinkUnixWatch *last_polled_source;
  103. #endif
  104. };
  105. #define LINK_ERR_CONDS (G_IO_ERR|G_IO_HUP|G_IO_NVAL)
  106. #define LINK_IN_CONDS (G_IO_PRI|G_IO_IN)
  107. #ifdef G_OS_WIN32
  108. /* The functions in the Microsoft C library that correspond to
  109. * system calls in Unix don't have any EINTR failure mode.
  110. */
  111. #define LINK_TEMP_FAILURE_RETRY_SYSCALL(expression, val) \
  112. { val = (int) (expression); }
  113. #else
  114. /* taken from glibc */
  115. #define LINK_TEMP_FAILURE_RETRY_SYSCALL(expression, val) \
  116. { long int __result; \
  117. do __result = (long int) (expression); \
  118. while (__result == -1L && errno == EINTR); \
  119. val = __result; }
  120. #endif
  121. #ifdef HAVE_WINSOCK2_H
  122. /* In WinSock2 WSAEINTR can't happen according to the docs, but
  123. * it doesn't hurt to check anyway, does it?
  124. */
  125. #define LINK_TEMP_FAILURE_RETRY_SOCKET(expression, val) \
  126. { int __result; \
  127. do __result = (int) (expression); \
  128. while (__result == SOCKET_ERROR && WSAGetLastError() == WSAEINTR); \
  129. val = __result; }
  130. #define LINK_CLOSE_SOCKET(fd) while (closesocket (fd) == SOCKET_ERROR && WSAGetLastError() == WSAEINTR)
  131. #else
  132. /* On Unix socket API calls are no different from normal system calls */
  133. #define LINK_TEMP_FAILURE_RETRY_SOCKET(expression, val) \
  134. LINK_TEMP_FAILURE_RETRY_SYSCALL(expression, val)
  135. #define LINK_CLOSE_SOCKET(fd) while (close (fd) < 0 && errno == EINTR)
  136. #endif
  137. struct sockaddr *link_protocol_get_sockaddr (const LinkProtocolInfo *proto,
  138. const char *hostname,
  139. const char *service,
  140. LinkSockLen *saddr_len);
  141. gboolean link_protocol_get_sockinfo (const LinkProtocolInfo *proto,
  142. const struct sockaddr *saddr,
  143. gchar **hostname,
  144. gchar **service);
  145. gboolean link_protocol_is_local (const LinkProtocolInfo *proto,
  146. const struct sockaddr *saddr,
  147. LinkSockLen saddr_len);
  148. void link_protocol_destroy_cnx (const LinkProtocolInfo *proto,
  149. int fd,
  150. const char *host,
  151. const char *service);
  152. void link_protocol_destroy_addr (const LinkProtocolInfo *proto,
  153. int fd,
  154. struct sockaddr *saddr);
  155. LinkWatch *link_io_add_watch_fd (int fd,
  156. GIOCondition condition,
  157. GIOFunc func,
  158. gpointer user_data);
  159. void link_io_remove_watch (LinkWatch *w);
  160. void link_watch_set_condition (LinkWatch *w,
  161. GIOCondition condition);
  162. void link_watch_move_io (LinkWatch *w,
  163. gboolean to_io_thread);
  164. GMainContext *link_main_get_context (void);
  165. GMainContext *link_thread_io_context (void);
  166. gboolean link_in_io_thread (void);
  167. gboolean link_mutex_is_locked (GMutex *lock);
  168. void link_lock (void);
  169. void link_unlock (void);
  170. gboolean link_is_locked (void);
  171. void link_servers_move_io_T (gboolean to_io_thread);
  172. void link_connections_move_io_T (gboolean to_io_thread);
  173. #ifdef G_OS_WIN32
  174. void link_win32_watch_set_write_wouldblock (LinkWatch *watch,
  175. gboolean flag);
  176. #endif
  177. #endif /* _LINK_PRIVATE_H */