2
* ***************************************************************************
3
* MALOC = < Minimal Abstraction Layer for Object-oriented C >
4
* Copyright (C) 1994--2000 Michael Holst
6
* This program is free software; you can redistribute it and/or modify it
7
* under the terms of the GNU General Public License as published by the
8
* Free Software Foundation; either version 2 of the License, or (at your
9
* option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
* See the GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License along
17
* with this program; if not, write to the Free Software Foundation, Inc.,
18
* 675 Mass Ave, Cambridge, MA 02139, USA.
20
* rcsid="$Id: vio.h,v 1.18 2004/02/18 01:10:56 mholst Exp $"
21
* ***************************************************************************
25
* ***************************************************************************
26
* File: vio.h < vio.c >
28
* Purpose: Class Vio: virtual <SDIO/FILE/BUFF/UNIX/INET> I/O layer.
30
* Author: Michael Holst
31
* ***************************************************************************
37
#include <maloc/maloc_base.h>
39
#include <maloc/vnm.h>
42
* ***************************************************************************
43
* Class Vio: Parameters and datatypes
44
* ***************************************************************************
47
#define VPORTNUMBER 14916 /* our portbase; 5000 < VPORTNUMBER < 49152 */
48
#define VIO_MAXBUF 10 /* number of internal buffers (BUFF datatype) */
50
typedef enum VIOtype {
59
typedef enum VIOfrmt {
65
typedef enum VIOrwkey {
72
* ***************************************************************************
73
* Class Vio: Definition
74
* ***************************************************************************
79
VIOtype type; /* file (or device) type */
80
/* VIO_NO_TYPE = not initialized */
81
/* VIO_SDIO = standard I/O */
82
/* VIO_FILE = file I/O */
83
/* VIO_BUFF = buffer I/O */
84
/* VIO_UNIX = UNIX (domain) socket I/O */
85
/* VIO_INET = INET (network) socket I/O */
87
VIOfrmt frmt; /* data format */
88
/* VIO_NO_FRMT = not initialized */
89
/* VIO_ASC = ASCII (FILE,BUFF,UNIX,INET) */
90
/* VIO_XDR = BINARY (FILE,BUFF,UNIX,INET) */
92
VIOrwkey rwkey; /* r/w key */
93
/* VIO_NO_R = not initialized */
94
/* VIO_R = read (FILE,BUFF,UNIX,INET) */
95
/* VIO_W = write (FILE,BUFF,UNIX,INET) */
97
char file[80]; /* file or device name (FILE,BUFF,UNIX,INET) */
98
char lhost[80]; /* local hostname (me) (UNIX,INET) */
99
char rhost[80]; /* remote hostname (the other guy) (UNIX,INET) */
101
int error; /* note if any error has occurred on this vio device*/
102
int dirty; /* dirty read bit -- have we read file yet (FILE) */
104
FILE *fp; /* file pointer (SDIO,FILE) */
105
int so; /* primary unix domain or inet socket (UNIX,INET) */
106
int soc; /* subsocket created for socket reading (UNIX,INET) */
107
void *name; /* &sockaddr_un or &sockaddr_in (UNIX,INET) */
108
void *axdr; /* ASC/XDR structure pointer (ASC,XDR) */
110
char whiteChars[VMAX_ARGNUM]; /* white space character set (ASC) */
111
char commChars[VMAX_ARGNUM]; /* comment character set (ASC,XDR) */
113
char ioBuffer[VMAX_BUFSIZE]; /* I/O buffer (ASC,XDR) */
114
int ioBufferLen; /* I/O buffer length (ASC,XDR) */
116
char putBuffer[VMAX_BUFSIZE]; /* final write buffer (ASC,XDR) */
117
int putBufferLen; /* final write buffer length (ASC,XDR) */
119
char *VIObuffer; /* (BUFF) */
120
int VIObufferLen; /* (BUFF) */
121
int VIObufferPtr; /* (BUFF) */
126
* ***************************************************************************
127
* Class Vio: Inlineable methods (vio.c)
128
* ***************************************************************************
131
#if !defined(VINLINE_MALOC)
132
#else /* if defined(VINLINE_MALOC) */
133
#endif /* if !defined(VINLINE_MALOC) */
136
* ***************************************************************************
137
* Class Vio: Non-Inlineable methods (vio.c)
138
* ***************************************************************************
141
VEXTERNC void Vio_start(void);
142
VEXTERNC void Vio_stop(void);
144
VEXTERNC Vio* Vio_ctor(const char *socktype, const char *datafrmt,
145
const char *hostname, const char *filename, const char *rwkey);
146
VEXTERNC int Vio_ctor2(Vio *thee, const char *socktype, const char *datafrmt,
147
const char *hostname, const char *filename, const char *rwkey);
149
VEXTERNC void Vio_dtor(Vio **thee);
150
VEXTERNC void Vio_dtor2(Vio *thee);
152
VEXTERNC Vio *Vio_socketOpen(char *key,
153
const char *iodev, const char *iofmt,
154
const char *iohost, const char *iofile);
155
VEXTERNC void Vio_socketClose(Vio **sock);
157
VEXTERNC void Vio_setWhiteChars(Vio *thee, char *whiteChars);
158
VEXTERNC void Vio_setCommChars(Vio *thee, char *commChars);
160
VEXTERNC int Vio_accept(Vio *thee, int nonblock);
161
VEXTERNC void Vio_acceptFree(Vio *thee);
163
VEXTERNC int Vio_connect(Vio *thee, int nonblock);
164
VEXTERNC void Vio_connectFree(Vio *thee);
166
VEXTERNC int Vio_scanf(Vio *thee, char *parms, ...);
167
VEXTERNC int Vio_printf(Vio *thee, char *parms, ...);
169
VEXTERNC int Vio_read(Vio *thee, char *buf, int bufsize);
170
VEXTERNC int Vio_write(Vio *thee, char *buf, int bufsize);
172
VEXTERNC int Vio_bufSize(Vio *thee);
173
VEXTERNC char* Vio_bufGive(Vio *thee);
174
VEXTERNC void Vio_bufTake(Vio *thee, char *buf, int bufsize);