summaryrefslogtreecommitdiff
path: root/src/fc/fsio.h
blob: 0d3590a86c52bcd319a01bcd47cf1b0fb4328e42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/* $Xorg: fsio.h,v 1.3 2000/08/17 19:46:36 cpqbld Exp $ */
/*
 * Copyright 1990 Network Computing Devices
 *
 * Permission to use, copy, modify, distribute, and sell this software and its
 * documentation for any purpose is hereby granted without fee, provided that
 * the above copyright notice appear in all copies and that both that
 * copyright notice and this permission notice appear in supporting
 * documentation, and that the name of Network Computing Devices not be
 * used in advertising or publicity pertaining to distribution of the
 * software without specific, written prior permission.  Network Computing
 * Devices makes no representations about the suitability of this software
 * for any purpose.  It is provided "as is" without express or implied
 * warranty.
 *
 * NETWORK COMPUTING DEVICES DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
 * IN NO EVENT SHALL NETWORK COMPUTING DEVICES BE LIABLE FOR ANY SPECIAL,
 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
 * OR PERFORMANCE OF THIS SOFTWARE.
 *
 * Author:  	Dave Lemke, Network Computing Devices, Inc
 */
/* $XFree86$ */

#ifndef	_FSIO_H_
#define	_FSIO_H_

#undef DEBUG
#define	REQUEST_LOG_SIZE	100

typedef struct _fs_fpe_alternate {
    char       *name;
    Bool        subset;
}           FSFpeAltRec, *FSFpeAltPtr;


/* Per client access contexts */
typedef struct _fs_client_data {
    pointer		    client;
    struct _fs_client_data  *next;
    XID			    acid;
    int			    auth_generation;
} FSClientRec, *FSClientPtr;

#define FS_RECONNECT_POLL	1000
#define FS_RECONNECT_WAIT	5000
#define FS_GIVEUP_WAIT		20000
#define FS_REQUEST_TIMEOUT	20000
#define FS_OPEN_TIMEOUT		30000
#define FS_REOPEN_TIMEOUT	10000
#define FS_FLUSH_POLL		1000

typedef struct _fs_buf {
    char    *buf;		/* data */
    long    size;		/* sizeof data */
    long    insert;		/* where to insert new data */
    long    remove;		/* where to remove old data */
} FSBufRec, *FSBufPtr;

#define FS_BUF_INC  1024
#define FS_BUF_MAX  32768

#define FS_PENDING_WRITE	0x01	    /* some write data is queued */
#define FS_BROKEN_WRITE		0x02	    /* writes are broken */
#define FS_BROKEN_CONNECTION	0x04	    /* connection is broken */
#define FS_PENDING_REPLY	0x08	    /* waiting for a reply */
#define FS_GIVE_UP		0x10	    /* font server declared useless */
#define FS_COMPLETE_REPLY	0x20	    /* complete reply ready */
#define FS_RECONNECTING		0x40

#define FS_CONN_UNCONNECTED	0
#define FS_CONN_CONNECTING	1
#define FS_CONN_CONNECTED	2
#define FS_CONN_SENT_PREFIX	3
#define FS_CONN_RECV_INIT	4
#define FS_CONN_SENT_CAT    	5
#define FS_CONN_RUNNING		6

/* FS specific font FontPathElement data */
typedef struct _fs_fpe_data {
    FSFpePtr	next;		/* list of all active fs fpes */
    int         fs_fd;		/* < 0 when not running */
    int		fs_conn_state;	/* connection state */
    int         current_seq;
    char       *servername;
    Bool	has_catalogues;

    int         generation;
    int         numAlts;
    int		alternate;	/* which alternate is in use +1 */
    int		fsMajorVersion; /* font server major version number */
    FSFpeAltPtr alts;

    FSClientPtr	clients;
    XID		curacid;
#ifdef DEBUG
    int         reqindex;
    struct {
	int	opcode;
	int	sequence;
    } reqbuffer[REQUEST_LOG_SIZE];
#endif
    FSBufRec	outBuf;		/* request queue */
    FSBufRec	inBuf;		/* reply queue */
    long	inNeed;		/* amount needed for reply */

    CARD32	blockState;
    CARD32	blockedReplyTime;	/* time to abort blocked read */
    CARD32	brokenWriteTime;	/* time to retry broken write */
    CARD32	blockedConnectTime;	/* time to abort blocked connect */
    CARD32	brokenConnectionTime;	/* time to retry broken connection */
    
    FSBlockDataPtr  blockedRequests;
    
    struct _XtransConnInfo *trans_conn; /* transport connection object */
}           FSFpeRec;

#define fs_outspace(conn)   ((conn)->outBuf.size - (conn)->outBuf.insert)
#define fs_outqueued(conn)  ((conn)->outBuf.insert - (conn)->outBuf.remove)
#define fs_inqueued(conn)   ((conn)->inBuf.insert - (conn)->inBuf.remove)
#define fs_needsflush(conn) (fs_outqueued(conn) != 0)
#define fs_needsfill(conn)  (fs_inqueued(conn) < (conn)->inNeed)
#define fs_needsconnect(conn)	((conn)->fs_fd < 0)
#define fs_data_read(conn)   ((conn)->inBuf.insert - (conn)->inBuf.remove)

#define FSIO_READY  1
#define FSIO_BLOCK  0
#define FSIO_ERROR  -1

extern Bool _fs_reopen_server ( FSFpePtr conn );
extern int _fs_write ( FSFpePtr conn, char *data, long size );
extern int _fs_write_pad ( FSFpePtr conn, char *data, long len );
extern int _fs_data_ready ( FSFpePtr conn );
extern int _fs_wait_for_readable ( FSFpePtr conn, int ms );
extern int _fs_set_bit ( fd_set * mask, int fd );
extern int _fs_is_bit_set ( fd_set * mask, int fd );
extern void _fs_bit_clear ( fd_set * mask, int fd );
extern int  _fs_any_bit_set ( fd_set * mask );
extern void _fs_or_bits ( fd_set * dst, fd_set * m1, fd_set * m2 );
extern long _fs_pad_length (long len);

extern void _fs_connection_died ( FSFpePtr conn );

extern int  _fs_fill (FSFpePtr conn);
extern int  _fs_flush (FSFpePtr conn);
extern void _fs_mark_block (FSFpePtr conn, CARD32 mask);
extern void _fs_unmark_block (FSFpePtr conn, CARD32 mask);
extern void _fs_done_read (FSFpePtr conn, long size);
extern void _fs_io_reinit (FSFpePtr conn);
extern int  _fs_start_read (FSFpePtr conn, long size, char **buf);
extern Bool _fs_io_init (FSFpePtr conn);
extern void _fs_io_fini (FSFpePtr conn);
extern int  _fs_poll_connect (XtransConnInfo trans_conn, int timeout);
extern XtransConnInfo	_fs_connect(char *servername, int *ret);

/* check for both EAGAIN and EWOULDBLOCK, because some supposedly POSIX
 * systems are broken and return EWOULDBLOCK when they should return EAGAIN
 */
#ifdef WIN32
#define ETEST() (WSAGetLastError() == WSAEWOULDBLOCK)
#else
#if defined(EAGAIN) && defined(EWOULDBLOCK)
#define ETEST() (errno == EAGAIN || errno == EWOULDBLOCK)
#else
#ifdef EAGAIN
#define ETEST() (errno == EAGAIN)
#else
#define ETEST() (errno == EWOULDBLOCK)
#endif
#endif
#endif
#ifdef WIN32
#define ECHECK(err) (WSAGetLastError() == err)
#define ESET(val) WSASetLastError(val)
#else
#ifdef ISC
#define ECHECK(err) ((errno == err) || ETEST())
#else
#define ECHECK(err) (errno == err)
#endif
#define ESET(val) errno = val
#endif

#endif				/* _FSIO_H_ */