Home | History | Annotate | Line # | Download | only in fc
      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 #ifdef DEBUG
     30 #define	REQUEST_LOG_SIZE	100
     31 #endif
     32 
     33 typedef struct _fs_fpe_alternate {
     34     char       *name;
     35     Bool        subset;
     36 }           FSFpeAltRec, *FSFpeAltPtr;
     37 
     38 
     39 /* Per client access contexts */
     40 typedef struct _fs_client_data {
     41     pointer		    client;
     42     struct _fs_client_data  *next;
     43     XID			    acid;
     44     int			    auth_generation;
     45 } FSClientRec, *FSClientPtr;
     46 
     47 #define FS_RECONNECT_POLL	1000
     48 #define FS_RECONNECT_WAIT	5000
     49 #define FS_GIVEUP_WAIT		20000
     50 #define FS_REQUEST_TIMEOUT	20000
     51 #define FS_OPEN_TIMEOUT		30000
     52 #define FS_REOPEN_TIMEOUT	10000
     53 #define FS_FLUSH_POLL		1000
     54 
     55 typedef struct _fs_buf {
     56     char    *buf;		/* data */
     57     long    size;		/* sizeof data */
     58     long    insert;		/* where to insert new data */
     59     long    remove;		/* where to remove old data */
     60 } FSBufRec, *FSBufPtr;
     61 
     62 #define FS_BUF_INC  1024
     63 #define FS_BUF_MAX  32768
     64 
     65 #define FS_PENDING_WRITE	0x01	    /* some write data is queued */
     66 #define FS_BROKEN_WRITE		0x02	    /* writes are broken */
     67 #define FS_BROKEN_CONNECTION	0x04	    /* connection is broken */
     68 #define FS_PENDING_REPLY	0x08	    /* waiting for a reply */
     69 #define FS_GIVE_UP		0x10	    /* font server declared useless */
     70 #define FS_COMPLETE_REPLY	0x20	    /* complete reply ready */
     71 #define FS_RECONNECTING		0x40
     72 
     73 #define FS_CONN_UNCONNECTED	0
     74 #define FS_CONN_CONNECTING	1
     75 #define FS_CONN_CONNECTED	2
     76 #define FS_CONN_SENT_PREFIX	3
     77 #define FS_CONN_RECV_INIT	4
     78 #define FS_CONN_SENT_CAT    	5
     79 #define FS_CONN_RUNNING		6
     80 
     81 /* FS specific font FontPathElement data */
     82 typedef struct _fs_fpe_data {
     83     FSFpePtr	next;		/* list of all active fs fpes */
     84     FontPathElementPtr fpe;	/* Back pointer to FPE */
     85     int         fs_fd;		/* < 0 when not running */
     86     Bool	fs_listening;	/* Listening for input */
     87     int		fs_conn_state;	/* connection state */
     88     int         current_seq;
     89     char       *servername;
     90     Bool	has_catalogues;
     91 
     92     int         generation;
     93     int         numAlts;
     94     int		alternate;	/* which alternate is in use +1 */
     95     int		fsMajorVersion; /* font server major version number */
     96     FSFpeAltPtr alts;
     97 
     98     FSClientPtr	clients;
     99     XID		curacid;
    100 #ifdef DEBUG
    101     int         reqindex;
    102     struct {
    103 	int	opcode;
    104 	int	sequence;
    105     } reqbuffer[REQUEST_LOG_SIZE];
    106 #endif
    107     FSBufRec	outBuf;		/* request queue */
    108     FSBufRec	inBuf;		/* reply queue */
    109     long	inNeed;		/* amount needed for reply */
    110 
    111     CARD32	blockState;
    112     CARD32	blockedReplyTime;	/* time to abort blocked read */
    113     CARD32	brokenWriteTime;	/* time to retry broken write */
    114     CARD32	blockedConnectTime;	/* time to abort blocked connect */
    115     CARD32	brokenConnectionTime;	/* time to retry broken connection */
    116 
    117     FSBlockDataPtr  blockedRequests;
    118 
    119     struct _XtransConnInfo *trans_conn; /* transport connection object */
    120 }           FSFpeRec;
    121 
    122 #define fs_outspace(conn)   ((conn)->outBuf.size - (conn)->outBuf.insert)
    123 #define fs_outqueued(conn)  ((conn)->outBuf.insert - (conn)->outBuf.remove)
    124 #define fs_inqueued(conn)   ((conn)->inBuf.insert - (conn)->inBuf.remove)
    125 #define fs_needsflush(conn) (fs_outqueued(conn) != 0)
    126 #define fs_needsfill(conn)  (fs_inqueued(conn) < (conn)->inNeed)
    127 #define fs_needsconnect(conn)	((conn)->fs_fd < 0)
    128 #define fs_data_read(conn)   ((conn)->inBuf.insert - (conn)->inBuf.remove)
    129 
    130 #define FSIO_READY  1
    131 #define FSIO_BLOCK  0
    132 #define FSIO_ERROR  -1
    133 
    134 extern Bool _fs_reopen_server ( FSFpePtr conn );
    135 extern int _fs_write ( FSFpePtr conn, const char *data, long size );
    136 extern int _fs_write_pad ( FSFpePtr conn, const char *data, long len );
    137 extern int _fs_wait_for_readable ( FSFpePtr conn, int ms );
    138 extern long _fs_pad_length (long len);
    139 
    140 extern void _fs_connection_died ( FSFpePtr conn );
    141 
    142 extern int  _fs_flush (FSFpePtr conn);
    143 extern void _fs_mark_block (FSFpePtr conn, CARD32 mask);
    144 extern void _fs_unmark_block (FSFpePtr conn, CARD32 mask);
    145 extern void _fs_done_read (FSFpePtr conn, long size);
    146 extern void _fs_io_reinit (FSFpePtr conn);
    147 extern int  _fs_start_read (FSFpePtr conn, long size, char **buf);
    148 extern Bool _fs_io_init (FSFpePtr conn);
    149 extern void _fs_io_fini (FSFpePtr conn);
    150 extern int  _fs_poll_connect (XtransConnInfo trans_conn, int timeout);
    151 extern XtransConnInfo	_fs_connect(char *servername, int *ret);
    152 
    153 /* check for both EAGAIN and EWOULDBLOCK, because some supposedly POSIX
    154  * systems are broken and return EWOULDBLOCK when they should return EAGAIN
    155  */
    156 #ifdef WIN32
    157 #define ETEST() (WSAGetLastError() == WSAEWOULDBLOCK)
    158 #else
    159 #if defined(EAGAIN) && defined(EWOULDBLOCK)
    160 #define ETEST() (errno == EAGAIN || errno == EWOULDBLOCK)
    161 #else
    162 #ifdef EAGAIN
    163 #define ETEST() (errno == EAGAIN)
    164 #else
    165 #define ETEST() (errno == EWOULDBLOCK)
    166 #endif
    167 #endif
    168 #endif
    169 #ifdef WIN32
    170 #define ECHECK(err) (WSAGetLastError() == err)
    171 #define ESET(val) WSASetLastError(val)
    172 #else
    173 #define ECHECK(err) (errno == err)
    174 #define ESET(val) errno = val
    175 #endif
    176 
    177 #endif				/* _FSIO_H_ */
    178