Moved .h files to include directory
[yaz-moved-to-github.git] / include / comstack.h
1 /*
2  * Copyright (C) 1994, Index Data I/S 
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: comstack.h,v $
7  * Revision 1.1  1995-03-30 09:39:40  quinn
8  * Moved .h files to include directory
9  *
10  * Revision 1.11  1995/03/27  08:36:05  quinn
11  * Some work on nonblocking operation in xmosi.c and rfct.c.
12  * Added protocol parameter to cs_create()
13  *
14  * Revision 1.10  1995/03/20  09:47:12  quinn
15  * Added server-side support to xmosi.c
16  * Fixed possible problems in rfct
17  * Other little mods
18  *
19  * Revision 1.9  1995/03/15  15:36:27  quinn
20  * Mods to support nonblocking I/O
21  *
22  * Revision 1.8  1995/03/14  17:00:07  quinn
23  * Bug-fixes - added tracing info to tcpip.c
24  *
25  * Revision 1.7  1995/03/14  10:28:35  quinn
26  * Adding server-side support to tcpip.c and fixing bugs in nonblocking I/O
27  *
28  * Revision 1.6  1995/03/07  16:29:45  quinn
29  * Various fixes.
30  *
31  * Revision 1.5  1995/03/07  10:39:31  quinn
32  * Added cs_fileno
33  *
34  * Revision 1.4  1995/03/06  16:49:29  adam
35  * COMSTACK type inspection possible with cs_type.
36  *
37  * Revision 1.3  1995/02/14  11:54:48  quinn
38  * Beginning to add full CCL.
39  *
40  * Revision 1.2  1995/02/10  18:58:10  quinn
41  * Fixed tcpip_get (formerly tcpip_read).
42  * Turned tst (cli) into a proper, event-driven thing.
43  *
44  * Revision 1.1  1995/02/09  15:51:51  quinn
45  * Works better now.
46  *
47  */
48
49 #ifndef COMSTACK_H
50 #define COMSTACK_H
51
52 #include <dmalloc.h>
53
54 #define COMSTACK_DEFAULT_TIMEOUT -1
55
56 struct comstack;
57 typedef struct comstack *COMSTACK;
58
59 typedef COMSTACK (*CS_TYPE)(int blocking, int protocol);
60
61 struct comstack
62 {
63     CS_TYPE type;
64     int errno;     /* current error code of this stack */
65     char *stackerr;/* current lower-layer error string, or null if none */
66     int iofile;    /* UNIX file descriptor for iochannel */
67     int timeout;   /* how long to wait for trailing blocks */          
68     void *private; /* state info for lower stack */
69     int more;      /* connection has extra data in buffer */
70     int state;     /* current state */
71 #define CS_UNBND      0
72 #define CS_IDLE       1
73 #define CS_INCON      2
74 #define CS_OUTCON     3
75 #define CS_DATAXFER   4
76     int newfd;     /* storing new descriptor between listen and accept */
77     int blocking;  /* is this link (supposed to be) blocking? */
78     int event;     /* current event */
79 #define CS_NONE       0
80 #define CS_CONNECT    1
81 #define CS_DISCON     2
82 #define CS_LISTEN     3
83 #define CS_DATA       4
84     int protocol;  /* what application protocol are we talking? */
85 #define CS_Z3950      0
86 #define CS_SR         1
87     int (*f_look)(COMSTACK handle);
88     int (*f_put)(COMSTACK handle, char *buf, int size);
89     int (*f_get)(COMSTACK handle, char **buf, int *bufsize);
90     int (*f_more)(COMSTACK handle);
91     int (*f_connect)(COMSTACK handle, void *address);
92     int (*f_rcvconnect)(COMSTACK handle);
93     int (*f_bind)(COMSTACK handle, void *address, int mode);
94 #define CS_CLIENT 0
95 #define CS_SERVER 1
96     int (*f_listen)(COMSTACK handle, char *addrp, int *addrlen);
97     COMSTACK (*f_accept)(COMSTACK handle);
98     int (*f_close)(COMSTACK handle);
99     /* to add: commands for the server side (bind, listen, accept) */
100 };
101
102 #define cs_put(handle, buf, size) ((*(handle)->f_put)(handle, buf, size))
103 #define cs_get(handle, buf, size) ((*(handle)->f_get)(handle, buf, size))
104 #define cs_more(handle) ((*(handle)->f_more)(handle))
105 #define cs_connect(handle, address) ((*(handle)->f_connect)(handle, address))
106 #define cs_rcvconnect(handle) ((*(handle)->f_rcvconnect)(handle))
107 #define cs_bind(handle, ad, mo) ((*(handle)->f_bind)(handle, ad, mo))
108 #define cs_listen(handle, ap, al) ((*(handle)->f_listen)(handle, ap, al))
109 #define cs_accept(handle) ((*(handle)->f_accept)(handle))
110 #define cs_close(handle) ((*(handle)->f_close)(handle))
111 #define cs_create(type, blocking, proto) ((*type)(blocking, proto))
112 #define cs_type(handle) ((handle)->type)
113 #define cs_fileno(handle) ((handle)->iofile)
114 #define cs_stackerr(handle) ((handle)->stackerr)
115 #define cs_getstate(handle) ((handle)->getstate)
116 #define cs_errno(handle) ((handle)->errno)
117 #define cs_getproto(handle) ((handle)->protocol)
118
119 const char *cs_strerror(COMSTACK h);
120
121 /*
122  * error management.
123  */
124
125 #define CSNONE     0
126 #define CSYSERR    1
127 #define CSOUTSTATE 2
128 #define CSNODATA   3
129 #define CSWRONGBUF 4
130
131 extern char *cs_errlist[];
132
133 #endif