vm, kernel, top: report memory usage of vm, kernel
[minix.git] / servers / pfs / uds.h
blobefcb9c1da9a35b682fd5b50560d20b6fe8168d80
1 #ifndef __PFS_UDS_H__
2 #define __PFS_UDS_H__
4 /*
5 * Unix Domain Sockets Implementation (PF_UNIX, PF_LOCAL)
7 * Also See...
9 * dev_uds.c, table.c, uds.c
12 #include <limits.h>
13 #include <sys/types.h>
14 #include <sys/ucred.h>
15 #include <sys/un.h>
17 #include <minix/endpoint.h>
19 /* max connection backlog for incoming connections */
20 #define UDS_SOMAXCONN 64
22 typedef void* filp_id_t;
24 /* ancillary data to be sent */
25 struct ancillary {
26 filp_id_t filps[OPEN_MAX];
27 int fds[OPEN_MAX];
28 int nfiledes;
29 struct ucred cred;
33 * Internal State Information for a socket descriptor.
35 struct uds_fd {
37 /* Flags */
39 enum UDS_STATE {
40 /* This file descriptor is UDS_FREE and can be allocated. */
41 UDS_FREE = 0,
43 /* OR it is UDS_INUSE and can't be allocated. */
44 UDS_INUSE = 1
46 /* state is set to UDS_INUSE in uds_open(). state is Set to
47 * UDS_FREE in uds_init() and uds_close(). state should be
48 * checked prior to all operations.
50 } state;
52 /* Owner Info */
54 /* Socket Owner */
55 endpoint_t owner;
57 /* endpoint for suspend/resume */
58 endpoint_t endpoint;
60 /* Pipe Housekeeping */
62 /* inode number on PFS -- each descriptor is backed by 1
63 * PIPE which is allocated in uds_open() and freed in
64 * uds_close(). Data is sent/written to a peer's PIPE.
65 * Data is recv/read from this PIPE.
67 ino_t inode_nr;
70 /* position in the PIPE where the data starts */
71 off_t pos;
73 /* size of data in the PIPE */
74 size_t size;
76 /* control read/write, set by uds_open() and shutdown(2).
77 * Can be set to S_IRUSR|S_IWUSR, S_IRUSR, S_IWUSR, or 0
78 * for read and write, read only, write only, or neither.
79 * default is S_IRUSR|S_IWUSR.
81 mode_t mode;
83 /* Socket Info */
86 /* socket type - SOCK_STREAM, SOCK_DGRAM, or SOCK_SEQPACKET
87 * Set by uds_ioctl(NWIOSUDSTYPE). It defaults to -1 in
88 * uds_open(). Any action on a socket with type -1 besides
89 * uds_ioctl(NWIOSUDSTYPE) and uds_close() will result in
90 * an error.
92 int type;
94 /* queue of pending connections for server sockets.
95 * connect(2) inserts and accept(2) removes from the queue
97 int backlog[UDS_SOMAXCONN];
99 /* requested connection backlog size. Set by listen(2)
100 * Bounds (0 <= backlog_size <= UDS_SOMAXCONN)
101 * Defaults to UDS_SOMAXCONN which is defined above.
103 unsigned char backlog_size;
105 /* index of peer in uds_fd_table for connected sockets.
106 * -1 is used to mean no peer. Assumptions: peer != -1 means
107 * connected.
109 int peer;
111 /* index of child (client sd returned by accept(2))
112 * -1 is used to mean no child.
114 int child;
116 /* address -- the address the socket is bound to.
117 * Assumptions: addr.sun_family == AF_UNIX means its bound.
119 struct sockaddr_un addr;
121 /* target -- where DGRAMs are sent to on the next uds_write(). */
122 struct sockaddr_un target;
124 /* source -- address where DGRAMs are from. used to fill in the
125 * from address in recvfrom(2) and recvmsg(2).
127 struct sockaddr_un source;
129 /* Flag (1 or 0) - listening for incoming connections.
130 * Default to 0. Set to 1 by do_listen()
132 int listening;
134 /* stores file pointers and credentials being sent between
135 * processes with sendmsg(2) and recvmsg(2).
137 struct ancillary ancillary_data;
139 /* Holds an errno. This is set when a connected socket is
140 * closed and we need to pass ECONNRESET on to a suspended
141 * peer.
143 int err;
145 /* Suspend/Revive Housekeeping */
148 /* SUSPEND State Flags */
149 enum UDS_SUSPENDED {
151 /* Socket isn't blocked. */
152 UDS_NOT_SUSPENDED = 0,
154 /* Socket is blocked on read(2) waiting for data to read. */
155 UDS_SUSPENDED_READ = 1,
157 /* Socket is blocked on write(2) for space to write data. */
158 UDS_SUSPENDED_WRITE = 2,
160 /* Socket is blocked on connect(2) waiting for the server. */
161 UDS_SUSPENDED_CONNECT = 4,
163 /* Socket is blocked on accept(2) waiting for clients. */
164 UDS_SUSPENDED_ACCEPT = 8
165 } suspended;
167 /* Flag (1 or 0) - thing socket was waiting for is ready.
168 * If 1, then uds_status() will attempt the operation that
169 * the socket was blocked on.
171 int ready_to_revive;
173 /* i/o grant, saved for later use by suspended procs */
174 cp_grant_id_t io_gr;
176 /* is of i/o grant, saved for later use by suspended procs */
177 size_t io_gr_size;
179 /* Save the call number so that uds_cancel() can unwind the
180 * call properly.
182 int call_nr;
184 /* Save the IOCTL so uds_cancel() knows what got cancelled. */
185 int ioctl;
187 /* Flag (1 or 0) - the system call completed.
188 * A doc I read said DEV_CANCEL might be called even though
189 * the operation is finished. We use this variable to
190 * determine if we should rollback the changes or not.
192 int syscall_done;
194 /* select() */
196 /* Flag (1 or 0) - the process blocked on select(2). When
197 * selecting is 1 and I/O happens on this socket, then
198 * select_proc should be notified.
200 int selecting;
202 /* when a select is in progress, we notify() this endpoint
203 * of new data.
205 endpoint_t select_proc;
207 /* Options (SEL_RD, SEL_WR, SEL_ERR) that are requested. */
208 int sel_ops_in;
210 /* Options that are available for this socket. */
211 int sel_ops_out;
213 /* Flag (1 or 0) to be set to one before calling notify().
214 * uds_status() will use the flag to locate this descriptor.
216 int status_updated;
219 typedef struct uds_fd uds_fd_t;
221 /* File Descriptor Table -- Defined in uds.c */
222 EXTERN uds_fd_t uds_fd_table[NR_FDS];
225 * Take message m and get the index in uds_fd_table.
227 #define uds_minor(m) (minor((dev_t) m->DEVICE))
228 #define uds_minor_old(m) (minor((short) m->DEVICE))
231 * Fill in a reply message.
233 #define uds_set_reply(msg,type,endpoint,io_gr,status) \
234 do { \
235 (msg)->m_type = type; \
236 (msg)->REP_ENDPT = endpoint; \
237 (msg)->REP_IO_GRANT = io_gr; \
238 (msg)->REP_STATUS = status; \
239 } while (0)
241 #define uds_sel_reply(msg,type,minor,ops) \
242 do { \
243 (msg)->m_type = type; \
244 (msg)->DEV_MINOR = minor; \
245 (msg)->DEV_SEL_OPS = ops; \
246 } while (0)
251 #endif