bd0c621e84509db171dd3325591e56f78fe6038f
[framework/uifw/xorg/lib/libxfont.git] / src / fc / fsio.h
1 /*
2  * Copyright 1990 Network Computing Devices
3  *
4  * Permission to use, copy, modify, distribute, and sell this software and its
5  * documentation for any purpose is hereby granted without fee, provided that
6  * the above copyright notice appear in all copies and that both that
7  * copyright notice and this permission notice appear in supporting
8  * documentation, and that the name of Network Computing Devices not be
9  * used in advertising or publicity pertaining to distribution of the
10  * software without specific, written prior permission.  Network Computing
11  * Devices makes no representations about the suitability of this software
12  * for any purpose.  It is provided "as is" without express or implied
13  * warranty.
14  *
15  * NETWORK COMPUTING DEVICES DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
16  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
17  * IN NO EVENT SHALL NETWORK COMPUTING DEVICES BE LIABLE FOR ANY SPECIAL,
18  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
19  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
20  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
21  * OR PERFORMANCE OF THIS SOFTWARE.
22  *
23  * Author:      Dave Lemke, Network Computing Devices, Inc
24  */
25
26 #ifndef _FSIO_H_
27 #define _FSIO_H_
28
29 #undef DEBUG
30 #define REQUEST_LOG_SIZE        100
31
32 typedef struct _fs_fpe_alternate {
33     char       *name;
34     Bool        subset;
35 }           FSFpeAltRec, *FSFpeAltPtr;
36
37
38 /* Per client access contexts */
39 typedef struct _fs_client_data {
40     pointer                 client;
41     struct _fs_client_data  *next;
42     XID                     acid;
43     int                     auth_generation;
44 } FSClientRec, *FSClientPtr;
45
46 #define FS_RECONNECT_POLL       1000
47 #define FS_RECONNECT_WAIT       5000
48 #define FS_GIVEUP_WAIT          20000
49 #define FS_REQUEST_TIMEOUT      20000
50 #define FS_OPEN_TIMEOUT         30000
51 #define FS_REOPEN_TIMEOUT       10000
52 #define FS_FLUSH_POLL           1000
53
54 typedef struct _fs_buf {
55     char    *buf;               /* data */
56     long    size;               /* sizeof data */
57     long    insert;             /* where to insert new data */
58     long    remove;             /* where to remove old data */
59 } FSBufRec, *FSBufPtr;
60
61 #define FS_BUF_INC  1024
62 #define FS_BUF_MAX  32768
63
64 #define FS_PENDING_WRITE        0x01        /* some write data is queued */
65 #define FS_BROKEN_WRITE         0x02        /* writes are broken */
66 #define FS_BROKEN_CONNECTION    0x04        /* connection is broken */
67 #define FS_PENDING_REPLY        0x08        /* waiting for a reply */
68 #define FS_GIVE_UP              0x10        /* font server declared useless */
69 #define FS_COMPLETE_REPLY       0x20        /* complete reply ready */
70 #define FS_RECONNECTING         0x40
71
72 #define FS_CONN_UNCONNECTED     0
73 #define FS_CONN_CONNECTING      1
74 #define FS_CONN_CONNECTED       2
75 #define FS_CONN_SENT_PREFIX     3
76 #define FS_CONN_RECV_INIT       4
77 #define FS_CONN_SENT_CAT        5
78 #define FS_CONN_RUNNING         6
79
80 /* FS specific font FontPathElement data */
81 typedef struct _fs_fpe_data {
82     FSFpePtr    next;           /* list of all active fs fpes */
83     int         fs_fd;          /* < 0 when not running */
84     int         fs_conn_state;  /* connection state */
85     int         current_seq;
86     char       *servername;
87     Bool        has_catalogues;
88
89     int         generation;
90     int         numAlts;
91     int         alternate;      /* which alternate is in use +1 */
92     int         fsMajorVersion; /* font server major version number */
93     FSFpeAltPtr alts;
94
95     FSClientPtr clients;
96     XID         curacid;
97 #ifdef DEBUG
98     int         reqindex;
99     struct {
100         int     opcode;
101         int     sequence;
102     } reqbuffer[REQUEST_LOG_SIZE];
103 #endif
104     FSBufRec    outBuf;         /* request queue */
105     FSBufRec    inBuf;          /* reply queue */
106     long        inNeed;         /* amount needed for reply */
107
108     CARD32      blockState;
109     CARD32      blockedReplyTime;       /* time to abort blocked read */
110     CARD32      brokenWriteTime;        /* time to retry broken write */
111     CARD32      blockedConnectTime;     /* time to abort blocked connect */
112     CARD32      brokenConnectionTime;   /* time to retry broken connection */
113     
114     FSBlockDataPtr  blockedRequests;
115     
116     struct _XtransConnInfo *trans_conn; /* transport connection object */
117 }           FSFpeRec;
118
119 #define fs_outspace(conn)   ((conn)->outBuf.size - (conn)->outBuf.insert)
120 #define fs_outqueued(conn)  ((conn)->outBuf.insert - (conn)->outBuf.remove)
121 #define fs_inqueued(conn)   ((conn)->inBuf.insert - (conn)->inBuf.remove)
122 #define fs_needsflush(conn) (fs_outqueued(conn) != 0)
123 #define fs_needsfill(conn)  (fs_inqueued(conn) < (conn)->inNeed)
124 #define fs_needsconnect(conn)   ((conn)->fs_fd < 0)
125 #define fs_data_read(conn)   ((conn)->inBuf.insert - (conn)->inBuf.remove)
126
127 #define FSIO_READY  1
128 #define FSIO_BLOCK  0
129 #define FSIO_ERROR  -1
130
131 extern Bool _fs_reopen_server ( FSFpePtr conn );
132 extern int _fs_write ( FSFpePtr conn, char *data, long size );
133 extern int _fs_write_pad ( FSFpePtr conn, char *data, long len );
134 extern int _fs_wait_for_readable ( FSFpePtr conn, int ms );
135 extern long _fs_pad_length (long len);
136
137 extern void _fs_connection_died ( FSFpePtr conn );
138
139 extern int  _fs_flush (FSFpePtr conn);
140 extern void _fs_mark_block (FSFpePtr conn, CARD32 mask);
141 extern void _fs_unmark_block (FSFpePtr conn, CARD32 mask);
142 extern void _fs_done_read (FSFpePtr conn, long size);
143 extern void _fs_io_reinit (FSFpePtr conn);
144 extern int  _fs_start_read (FSFpePtr conn, long size, char **buf);
145 extern Bool _fs_io_init (FSFpePtr conn);
146 extern void _fs_io_fini (FSFpePtr conn);
147 extern int  _fs_poll_connect (XtransConnInfo trans_conn, int timeout);
148 extern XtransConnInfo   _fs_connect(char *servername, int *ret);
149
150 /* check for both EAGAIN and EWOULDBLOCK, because some supposedly POSIX
151  * systems are broken and return EWOULDBLOCK when they should return EAGAIN
152  */
153 #ifdef WIN32
154 #define ETEST() (WSAGetLastError() == WSAEWOULDBLOCK)
155 #else
156 #if defined(EAGAIN) && defined(EWOULDBLOCK)
157 #define ETEST() (errno == EAGAIN || errno == EWOULDBLOCK)
158 #else
159 #ifdef EAGAIN
160 #define ETEST() (errno == EAGAIN)
161 #else
162 #define ETEST() (errno == EWOULDBLOCK)
163 #endif
164 #endif
165 #endif
166 #ifdef WIN32
167 #define ECHECK(err) (WSAGetLastError() == err)
168 #define ESET(val) WSASetLastError(val)
169 #else
170 #ifdef ISC
171 #define ECHECK(err) ((errno == err) || ETEST())
172 #else
173 #define ECHECK(err) (errno == err)
174 #endif
175 #define ESET(val) errno = val
176 #endif
177
178 #endif                          /* _FSIO_H_ */