00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015   
00016 #ifndef _IOBUF_H
00017 #define _IOBUF_H
00018 
00023 #define BUFLEN 1024 
00024 
00025 
00029 struct iobuf {
00030   unsigned short head; 
00031   unsigned short tail; 
00032   unsigned short cnt;  
00033   unsigned short buflen; 
00034   char data[BUFLEN];    
00035 };
00036 
00043 static inline void iobuf_init(struct iobuf *x,short bl)
00044 {
00045 
00046 if ((bl<=0)||(bl>BUFLEN)) 
00047         {
00048                 x->buflen=BUFLEN;
00049         }
00050 else {
00051         x->buflen=bl;
00052 }
00053 
00054 x->head=0;
00055 x->tail=0;
00056 x->cnt=0;
00057 
00058 }
00059 
00068 static inline int put(struct iobuf *x,char c) 
00069 {
00070 if (x->cnt < x->buflen) {
00071         x->data[x->head]=c;
00072         x->head=(x->head+1) % x->buflen;
00073         x->cnt++;
00074         return(0);
00075 } else {
00076         return(-1);
00077         }
00078 }
00079 
00089 static inline char get(struct iobuf *x)
00090 {
00091 char c;
00092 while (x->cnt<=0); 
00093 c=x->data[x->tail];
00094 x->tail=(x->tail +1) % x->buflen;
00095 x->cnt--;
00096 return (c);
00097 
00098 }
00099 
00100 #endif