2 * Copyright 1990 Network Computing Devices
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
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.
23 * Author: Dave Lemke, Network Computing Devices, Inc
30 #define REQUEST_LOG_SIZE 100
32 typedef struct _fs_fpe_alternate {
35 } FSFpeAltRec, *FSFpeAltPtr;
38 /* Per client access contexts */
39 typedef struct _fs_client_data {
41 struct _fs_client_data *next;
44 } FSClientRec, *FSClientPtr;
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
54 typedef struct _fs_buf {
56 long size; /* sizeof data */
57 long insert; /* where to insert new data */
58 long remove; /* where to remove old data */
59 } FSBufRec, *FSBufPtr;
61 #define FS_BUF_INC 1024
62 #define FS_BUF_MAX 32768
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
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
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 */
91 int alternate; /* which alternate is in use +1 */
92 int fsMajorVersion; /* font server major version number */
102 } reqbuffer[REQUEST_LOG_SIZE];
104 FSBufRec outBuf; /* request queue */
105 FSBufRec inBuf; /* reply queue */
106 long inNeed; /* amount needed for reply */
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 */
114 FSBlockDataPtr blockedRequests;
116 struct _XtransConnInfo *trans_conn; /* transport connection object */
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)
129 #define FSIO_ERROR -1
131 extern Bool _fs_reopen_server ( FSFpePtr conn );
132 extern int _fs_write ( FSFpePtr conn, const char *data, long size );
133 extern int _fs_write_pad ( FSFpePtr conn, const char *data, long len );
134 extern int _fs_wait_for_readable ( FSFpePtr conn, int ms );
135 extern long _fs_pad_length (long len);
137 extern void _fs_connection_died ( FSFpePtr conn );
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);
150 /* check for both EAGAIN and EWOULDBLOCK, because some supposedly POSIX
151 * systems are broken and return EWOULDBLOCK when they should return EAGAIN
154 #define ETEST() (WSAGetLastError() == WSAEWOULDBLOCK)
156 #if defined(EAGAIN) && defined(EWOULDBLOCK)
157 #define ETEST() (errno == EAGAIN || errno == EWOULDBLOCK)
160 #define ETEST() (errno == EAGAIN)
162 #define ETEST() (errno == EWOULDBLOCK)
167 #define ECHECK(err) (WSAGetLastError() == err)
168 #define ESET(val) WSASetLastError(val)
171 #define ECHECK(err) ((errno == err) || ETEST())
173 #define ECHECK(err) (errno == err)
175 #define ESET(val) errno = val
178 #endif /* _FSIO_H_ */