PageRenderTime 45ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

servers/pfs/uds.h

http://www.minix3.org/
C Header | 251 lines | 74 code | 62 blank | 115 comment | 2 complexity | 2b77d1c2078b0ce61cf54ea877af4190 MD5 | raw file
Possible License(s): MIT, WTFPL, AGPL-1.0, BSD-3-Clause, GPL-3.0, LGPL-2.0, JSON, 0BSD
  1. #ifndef __PFS_UDS_H__
  2. #define __PFS_UDS_H__
  3. /*
  4. * Unix Domain Sockets Implementation (PF_UNIX, PF_LOCAL)
  5. *
  6. * Also See...
  7. *
  8. * dev_uds.c, table.c, uds.c
  9. */
  10. #include <limits.h>
  11. #include <sys/types.h>
  12. #include <sys/ucred.h>
  13. #include <sys/un.h>
  14. #include <minix/endpoint.h>
  15. /* max connection backlog for incoming connections */
  16. #define UDS_SOMAXCONN 64
  17. typedef void* filp_id_t;
  18. /* ancillary data to be sent */
  19. struct ancillary {
  20. filp_id_t filps[OPEN_MAX];
  21. int fds[OPEN_MAX];
  22. int nfiledes;
  23. struct ucred cred;
  24. };
  25. /*
  26. * Internal State Information for a socket descriptor.
  27. */
  28. struct uds_fd {
  29. /* Flags */
  30. enum UDS_STATE {
  31. /* This file descriptor is UDS_FREE and can be allocated. */
  32. UDS_FREE = 0,
  33. /* OR it is UDS_INUSE and can't be allocated. */
  34. UDS_INUSE = 1
  35. /* state is set to UDS_INUSE in uds_open(). state is Set to
  36. * UDS_FREE in uds_init() and uds_close(). state should be
  37. * checked prior to all operations.
  38. */
  39. } state;
  40. /* Owner Info */
  41. /* Socket Owner */
  42. endpoint_t owner;
  43. /* endpoint for suspend/resume */
  44. endpoint_t endpoint;
  45. /* Pipe Housekeeping */
  46. /* inode number on PFS -- each descriptor is backed by 1
  47. * PIPE which is allocated in uds_open() and freed in
  48. * uds_close(). Data is sent/written to a peer's PIPE.
  49. * Data is recv/read from this PIPE.
  50. */
  51. ino_t inode_nr;
  52. /* position in the PIPE where the data starts */
  53. off_t pos;
  54. /* size of data in the PIPE */
  55. size_t size;
  56. /* control read/write, set by uds_open() and shutdown(2).
  57. * Can be set to S_IRUSR|S_IWUSR, S_IRUSR, S_IWUSR, or 0
  58. * for read and write, read only, write only, or neither.
  59. * default is S_IRUSR|S_IWUSR.
  60. */
  61. mode_t mode;
  62. /* Socket Info */
  63. /* socket type - SOCK_STREAM, SOCK_DGRAM, or SOCK_SEQPACKET
  64. * Set by uds_ioctl(NWIOSUDSTYPE). It defaults to -1 in
  65. * uds_open(). Any action on a socket with type -1 besides
  66. * uds_ioctl(NWIOSUDSTYPE) and uds_close() will result in
  67. * an error.
  68. */
  69. int type;
  70. /* queue of pending connections for server sockets.
  71. * connect(2) inserts and accept(2) removes from the queue
  72. */
  73. int backlog[UDS_SOMAXCONN];
  74. /* requested connection backlog size. Set by listen(2)
  75. * Bounds (0 <= backlog_size <= UDS_SOMAXCONN)
  76. * Defaults to UDS_SOMAXCONN which is defined above.
  77. */
  78. unsigned char backlog_size;
  79. /* index of peer in uds_fd_table for connected sockets.
  80. * -1 is used to mean no peer. Assumptions: peer != -1 means
  81. * connected.
  82. */
  83. int peer;
  84. /* index of child (client sd returned by accept(2))
  85. * -1 is used to mean no child.
  86. */
  87. int child;
  88. /* address -- the address the socket is bound to.
  89. * Assumptions: addr.sun_family == AF_UNIX means its bound.
  90. */
  91. struct sockaddr_un addr;
  92. /* target -- where DGRAMs are sent to on the next uds_write(). */
  93. struct sockaddr_un target;
  94. /* source -- address where DGRAMs are from. used to fill in the
  95. * from address in recvfrom(2) and recvmsg(2).
  96. */
  97. struct sockaddr_un source;
  98. /* Flag (1 or 0) - listening for incoming connections.
  99. * Default to 0. Set to 1 by do_listen()
  100. */
  101. int listening;
  102. /* stores file pointers and credentials being sent between
  103. * processes with sendmsg(2) and recvmsg(2).
  104. */
  105. struct ancillary ancillary_data;
  106. /* Holds an errno. This is set when a connected socket is
  107. * closed and we need to pass ECONNRESET on to a suspended
  108. * peer.
  109. */
  110. int err;
  111. /* Suspend/Revive Housekeeping */
  112. /* SUSPEND State Flags */
  113. enum UDS_SUSPENDED {
  114. /* Socket isn't blocked. */
  115. UDS_NOT_SUSPENDED = 0,
  116. /* Socket is blocked on read(2) waiting for data to read. */
  117. UDS_SUSPENDED_READ = 1,
  118. /* Socket is blocked on write(2) for space to write data. */
  119. UDS_SUSPENDED_WRITE = 2,
  120. /* Socket is blocked on connect(2) waiting for the server. */
  121. UDS_SUSPENDED_CONNECT = 4,
  122. /* Socket is blocked on accept(2) waiting for clients. */
  123. UDS_SUSPENDED_ACCEPT = 8
  124. } suspended;
  125. /* Flag (1 or 0) - thing socket was waiting for is ready.
  126. * If 1, then uds_status() will attempt the operation that
  127. * the socket was blocked on.
  128. */
  129. int ready_to_revive;
  130. /* i/o grant, saved for later use by suspended procs */
  131. cp_grant_id_t io_gr;
  132. /* is of i/o grant, saved for later use by suspended procs */
  133. size_t io_gr_size;
  134. /* Save the call number so that uds_cancel() can unwind the
  135. * call properly.
  136. */
  137. int call_nr;
  138. /* Save the IOCTL so uds_cancel() knows what got cancelled. */
  139. int ioctl;
  140. /* Flag (1 or 0) - the system call completed.
  141. * A doc I read said DEV_CANCEL might be called even though
  142. * the operation is finished. We use this variable to
  143. * determine if we should rollback the changes or not.
  144. */
  145. int syscall_done;
  146. /* select() */
  147. /* Flag (1 or 0) - the process blocked on select(2). When
  148. * selecting is 1 and I/O happens on this socket, then
  149. * select_proc should be notified.
  150. */
  151. int selecting;
  152. /* when a select is in progress, we notify() this endpoint
  153. * of new data.
  154. */
  155. endpoint_t select_proc;
  156. /* Options (SEL_RD, SEL_WR, SEL_ERR) that are requested. */
  157. int sel_ops_in;
  158. /* Options that are available for this socket. */
  159. int sel_ops_out;
  160. /* Flag (1 or 0) to be set to one before calling notify().
  161. * uds_status() will use the flag to locate this descriptor.
  162. */
  163. int status_updated;
  164. };
  165. typedef struct uds_fd uds_fd_t;
  166. /* File Descriptor Table -- Defined in uds.c */
  167. EXTERN uds_fd_t uds_fd_table[NR_FDS];
  168. /*
  169. * Take message m and get the index in uds_fd_table.
  170. */
  171. #define uds_minor(m) (minor((dev_t) m->DEVICE))
  172. #define uds_minor_old(m) (minor((short) m->DEVICE))
  173. /*
  174. * Fill in a reply message.
  175. */
  176. #define uds_set_reply(msg,type,endpoint,io_gr,status) \
  177. do { \
  178. (msg)->m_type = type; \
  179. (msg)->REP_ENDPT = endpoint; \
  180. (msg)->REP_IO_GRANT = io_gr; \
  181. (msg)->REP_STATUS = status; \
  182. } while (0)
  183. #define uds_sel_reply(msg,type,minor,ops) \
  184. do { \
  185. (msg)->m_type = type; \
  186. (msg)->DEV_MINOR = minor; \
  187. (msg)->DEV_SEL_OPS = ops; \
  188. } while (0)
  189. #endif