MALOC
0.1
|
00001 /* 00002 * *************************************************************************** 00003 * MALOC = < Minimal Abstraction Layer for Object-oriented C > 00004 * Copyright (C) 1994--2000 Michael Holst 00005 * 00006 * This program is free software; you can redistribute it and/or modify it 00007 * under the terms of the GNU General Public License as published by the 00008 * Free Software Foundation; either version 2 of the License, or (at your 00009 * option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00014 * See the GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License along 00017 * with this program; if not, write to the Free Software Foundation, Inc., 00018 * 675 Mass Ave, Cambridge, MA 02139, USA. 00019 * 00020 * rcsid="$Id: vio.h,v 1.18 2004/02/18 01:10:56 mholst Exp $" 00021 * *************************************************************************** 00022 */ 00023 00024 /* 00025 * *************************************************************************** 00026 * File: vio.h < vio.c > 00027 * 00028 * Purpose: Class Vio: virtual <SDIO/FILE/BUFF/UNIX/INET> I/O layer. 00029 * 00030 * Author: Michael Holst 00031 * *************************************************************************** 00032 */ 00033 00034 #ifndef _VIO_H_ 00035 #define _VIO_H_ 00036 00037 #include <maloc/maloc_base.h> 00038 00039 #include <maloc/vnm.h> 00040 00041 /* 00042 * *************************************************************************** 00043 * Class Vio: Parameters and datatypes 00044 * *************************************************************************** 00045 */ 00046 00047 #define VPORTNUMBER 14916 /* our portbase; 5000 < VPORTNUMBER < 49152 */ 00048 #define VIO_MAXBUF 10 /* number of internal buffers (BUFF datatype) */ 00049 00050 typedef enum VIOtype { 00051 VIO_NO_TYPE, 00052 VIO_SDIO, 00053 VIO_BUFF, 00054 VIO_FILE, 00055 VIO_UNIX, 00056 VIO_INET 00057 } VIOtype; 00058 00059 typedef enum VIOfrmt { 00060 VIO_NO_FRMT, 00061 VIO_XDR, 00062 VIO_ASC 00063 } VIOfrmt; 00064 00065 typedef enum VIOrwkey { 00066 VIO_NO_RW, 00067 VIO_R, 00068 VIO_W 00069 } VIOrwkey; 00070 00071 /* 00072 * *************************************************************************** 00073 * Class Vio: Definition 00074 * *************************************************************************** 00075 */ 00076 00077 typedef struct Vio { 00078 00079 VIOtype type; /* file (or device) type */ 00080 /* VIO_NO_TYPE = not initialized */ 00081 /* VIO_SDIO = standard I/O */ 00082 /* VIO_FILE = file I/O */ 00083 /* VIO_BUFF = buffer I/O */ 00084 /* VIO_UNIX = UNIX (domain) socket I/O */ 00085 /* VIO_INET = INET (network) socket I/O */ 00086 00087 VIOfrmt frmt; /* data format */ 00088 /* VIO_NO_FRMT = not initialized */ 00089 /* VIO_ASC = ASCII (FILE,BUFF,UNIX,INET) */ 00090 /* VIO_XDR = BINARY (FILE,BUFF,UNIX,INET) */ 00091 00092 VIOrwkey rwkey; /* r/w key */ 00093 /* VIO_NO_R = not initialized */ 00094 /* VIO_R = read (FILE,BUFF,UNIX,INET) */ 00095 /* VIO_W = write (FILE,BUFF,UNIX,INET) */ 00096 00097 char file[80]; /* file or device name (FILE,BUFF,UNIX,INET) */ 00098 char lhost[80]; /* local hostname (me) (UNIX,INET) */ 00099 char rhost[80]; /* remote hostname (the other guy) (UNIX,INET) */ 00100 00101 int error; /* note if any error has occurred on this vio device*/ 00102 int dirty; /* dirty read bit -- have we read file yet (FILE) */ 00103 00104 FILE *fp; /* file pointer (SDIO,FILE) */ 00105 int so; /* primary unix domain or inet socket (UNIX,INET) */ 00106 int soc; /* subsocket created for socket reading (UNIX,INET) */ 00107 void *name; /* &sockaddr_un or &sockaddr_in (UNIX,INET) */ 00108 void *axdr; /* ASC/XDR structure pointer (ASC,XDR) */ 00109 00110 char whiteChars[VMAX_ARGNUM]; /* white space character set (ASC) */ 00111 char commChars[VMAX_ARGNUM]; /* comment character set (ASC,XDR) */ 00112 00113 char ioBuffer[VMAX_BUFSIZE]; /* I/O buffer (ASC,XDR) */ 00114 int ioBufferLen; /* I/O buffer length (ASC,XDR) */ 00115 00116 char putBuffer[VMAX_BUFSIZE]; /* final write buffer (ASC,XDR) */ 00117 int putBufferLen; /* final write buffer length (ASC,XDR) */ 00118 00119 char *VIObuffer; /* (BUFF) */ 00120 int VIObufferLen; /* (BUFF) */ 00121 int VIObufferPtr; /* (BUFF) */ 00122 00123 } Vio; 00124 00125 /* 00126 * *************************************************************************** 00127 * Class Vio: Inlineable methods (vio.c) 00128 * *************************************************************************** 00129 */ 00130 00131 #if !defined(VINLINE_MALOC) 00132 #else /* if defined(VINLINE_MALOC) */ 00133 #endif /* if !defined(VINLINE_MALOC) */ 00134 00135 /* 00136 * *************************************************************************** 00137 * Class Vio: Non-Inlineable methods (vio.c) 00138 * *************************************************************************** 00139 */ 00140 00141 void Vio_start(void); 00142 void Vio_stop(void); 00143 00144 Vio* Vio_ctor(const char *socktype, const char *datafrmt, 00145 const char *hostname, const char *filename, const char *rwkey); 00146 int Vio_ctor2(Vio *thee, const char *socktype, const char *datafrmt, 00147 const char *hostname, const char *filename, const char *rwkey); 00148 00149 void Vio_dtor(Vio **thee); 00150 void Vio_dtor2(Vio *thee); 00151 00152 Vio *Vio_socketOpen(char *key, 00153 const char *iodev, const char *iofmt, 00154 const char *iohost, const char *iofile); 00155 void Vio_socketClose(Vio **sock); 00156 00157 void Vio_setWhiteChars(Vio *thee, char *whiteChars); 00158 void Vio_setCommChars(Vio *thee, char *commChars); 00159 00160 int Vio_accept(Vio *thee, int nonblock); 00161 void Vio_acceptFree(Vio *thee); 00162 00163 int Vio_connect(Vio *thee, int nonblock); 00164 void Vio_connectFree(Vio *thee); 00165 00166 int Vio_scanf(Vio *thee, char *parms, ...); 00167 int Vio_printf(Vio *thee, char *parms, ...); 00168 00169 int Vio_read(Vio *thee, char *buf, int bufsize); 00170 int Vio_write(Vio *thee, char *buf, int bufsize); 00171 00172 int Vio_bufSize(Vio *thee); 00173 char* Vio_bufGive(Vio *thee); 00174 void Vio_bufTake(Vio *thee, char *buf, int bufsize); 00175 00176 #endif /* _VIO_H_ */ 00177 00178