NetBurner 3.5.6
PDF Version
iointernal.h
1/*NB_REVISION*/
2
3/*NB_COPYRIGHT*/
4
24#ifndef _NB_IOINTERNALS_H
25#define _NB_IOINTERNALS_H
26
27class FDInfo; //Forward declration
28
29
30extern int null_read(int fd, char *buf, int nbytes);
31extern int null_write(int fd, const char *buf, int nbytes);
32extern int null_close(int fd);
33extern FDInfo unknowninfo;
34
35/*
36 * I/O Expansion Structure
37 * read - read function
38 * write - write function
39 * close - close function
40 * peek - peek function peeks at next char
41 * pInfoStruct -A class with functions to get info about this thing.
42 * extra - void * to stash things in
43 *
44 * Notes:
45 * Expanded routines for library read, write and close
46 */
47struct IoExpandStruct
48{
49 int (*read)(int fd, char *buf, int nbytes);
50 int (*write)(int fd, const char *buf, int nbytes);
51 int (*close)(int fd);
52 int (*peek)(int fd, char *buf);
53 FDInfo *pInfoStruct;
54 void *extra;
55
56 //Since pInfoStruct is a new memeber and its really important this gets set or left as null
57 //We are adding a constructor to make sure its zero by default.
58inline IoExpandStruct( int (*io_read)(int fd, char *buf, int nbytes)=null_read,
59 int (*io_write)(int fd, const char *buf, int nbytes)=null_write,
60 int (*io_close)(int fd)=null_close,
61 int (*io_peek)(int fd, char *buf)=0,
62 FDInfo *io_pInfo=&unknowninfo,
63 void *io_extra=0)
64 {
65 read=io_read;
66 write=io_write;
67 close=io_close;
68 peek=io_peek;
69 pInfoStruct=io_pInfo;
70 extra=io_extra;
71 }
72
73
74} __attribute__((packed));
75
76/****************************************************************************
77
78 Acquire/Release/Access expansion file descriptor
79
80 Parameters:
81 extra_data - Control data structure beginning with
82 IoFrameworkStruct
83 pFuncs - Expanded I/O routines
84
85 fd - Expanded file descriptor
86
87 Return:
88 Acquired fd > EXTRA_IO_OFFSET OK, else -1 for none
89
90 ****************************************************************************/
91
102int GetExtraFD(void *extra_data, struct IoExpandStruct *pFuncs);
103
111IoExpandStruct *GetIoExpandStruct(int fd);
112
120void *GetExtraData(int fd);
121
128void FreeExtraFd(int fd);
129
137
145
146/*
147 ***************************************************************************
148
149 I/O subsystem notification support for use by expanded I/O routines
150
151 Parameters:
152 fd - Expanded file descriptor
153
154 Return:
155 None
156
157 ***************************************************************************
158 */
159void SetDataAvail(int fd);
160void ClrDataAvail(int fd);
161
162void SetWriteAvail(int fd);
163void ClrWriteAvail(int fd);
164
165void SetHaveError(int fd);
166void ClrHaveError(int fd);
167
168void Closing(int fd);
169
170
171//Class designed to get info about individual FD's
172class FDInfo
173{
174 const char * pName;
175public:
176 FDInfo (const char * name=0)
177 : pName(name)
178 {}
179
180 virtual bool IsMyFd(int fd)
181 {
182 IoExpandStruct * pio=GetIoExpandStruct(fd);
183 if(pio && (pio->pInfoStruct==this))
184 return true;
185 return false;
186 }
187
188 virtual const char * GetFdTypeName(int fd);
189
190 virtual int GetFdBelow(int fd);
191 FDInfo * GetInfoBelow(int fd);
192
193 virtual int RxBuffer_SpaceUsed(int fd);
194 virtual int RxBuffer_SpaceAvail(int fd);
195 virtual int TxBuffer_SpaceUsed(int fd);
196 virtual int TxBuffer_SpaceAvail(int fd);
197
198 virtual bool AllTxSent(int fd);
199
200 virtual int RxBuffer_GetMaxSize(int fd);
201 virtual int RxBuffer_SetMaxSize(int fd, int space);
202 virtual int TxBuffer_GetMaxSize(int fd);
203 virtual int TxBuffer_SetMaxSize(int fd, int space);
204
205 //Should this socket flush the whole content stack on each write.
206 virtual void SetFlush(int fd,bool bDoFlush){};
207
208 //Run IOCTL on this fd
209 virtual int doIoctl(int fd, int cmd) {return -1;};
210};
211#endif
212
int GetFreeExtraFDCount()
Returns the number of free file descriptors.
int GetExtraFD(void *extra_data, struct IoExpandStruct *pFuncs)
Returns a file descriptor for the structure passed as the IoExpandStruct. FreeExtraFd( ) will release...
void FreeExtraFd(int fd)
Free a file descriptor and associated resources.
IoExpandStruct * GetIoExpandStruct(int fd)
Returns the pointer to the IoExpandStruct associated with the file descriptor.
void * GetExtraData(int fd)
Returns the extra structure value from IoExpandStruct associated with the file descriptor.
int GetFreeSocketCount(void)
Returns the number of free sockets.