15 #define SERVER_NUM 2200 16 #define ARGUMENT_BUFFER_SIZE 16384 26 { printf(
"VxWs protocol error %d\n",x);
32 {
register int ival=0;
34 A_LONG: ival=(getc(s)<<24)+(getc(s)<<16);
36 A_CHAR:
return(ival+getc(s));}
55 return(((len & 0x3f)<<24) + (getc(s)<<16) + (getc(s)<<8) + getc(s));
56 else return(((len & 0x7f)<<8) + getc(s)); }
61 register
unsigned char *vmem;
64 {
register int i,length;
66 if (index+length >= bufsize-100) {
68 for (i=0; i<length; i++) getc(s);
70 for (i=0; i<length; i++) vmem[index++]=getc(s);
72 while (i-- >0) vmem[index++] =0;
77 {
int stat, entry, entry_type;
78 if (symFindByName(
sysSymTbl, s, &entry, &entry_type) == OK)
return(entry);
85 int stat, entry, entry_type;
88 for (i=0; i<len; i++) symstr[i+1]=getc(s);
90 stat=symFindByName(
sysSymTbl, &symstr[1], &entry, &entry_type);
93 stat=symFindByName(
sysSymTbl, symstr, &entry, &entry_type);
94 if (stat==ERROR)
return(ERROR);}
100 int bufsize, running=1, callee,
tid, result_type;
101 int nextfree, i, j, len;
108 unsigned char *ip, *vmem;
110 if ((s=fdopen(fd,
"r"))==
NULL) { printf(
"cannot fdopen read\n"); exit(2);}
111 if ((ws=fdopen(fd,
"w"))==
NULL) { printf(
"cannot fdopen write\n"); exit(2);}
116 vmem = malloc(bufsize);
119 printf(
"VxWserv v1.0 started with %d byte buffer\n", bufsize);
128 else if (type==
A_LONG) callee=getw(s);
134 while (type!=
A_END) {
137 case A_CHAR: cargv[i++]=getc(s);
break;
138 case A_SHORT: cargv[i++]=(getc(s)<<8) + getc(s);
break;
139 case A_LONG: cargv[i++]=getw(s);
break;
145 case A_VECTOR: cargv[i++]= &vmem[nextfree];
146 nextfree=
getvector(s,vmem,nextfree,bufsize);
164 f=(*ffunc)(cargv[0],cargv[1],cargv[2],cargv[3],
165 cargv[4],cargv[5],cargv[6],cargv[7]);
167 f=(*ffunc)(cargv[0],cargv[1],cargv[2],cargv[3],
168 cargv[4],cargv[5],cargv[6],cargv[7],
169 cargv[8],cargv[9],cargv[10],cargv[11],
170 cargv[12],cargv[13],cargv[14],cargv[15],
171 cargv[16],cargv[17],cargv[18],cargv[19],
172 cargv[20],cargv[21],cargv[22],cargv[23],
173 cargv[24],cargv[25],cargv[26],cargv[27],
174 cargv[28],cargv[29],cargv[30],cargv[31]);
181 i=(*ifunc)(cargv[0],cargv[1],cargv[2],cargv[3],
182 cargv[4],cargv[5],cargv[6],cargv[7]);
184 i=(*ifunc)(cargv[0],cargv[1],cargv[2],cargv[3],
185 cargv[4],cargv[5],cargv[6],cargv[7],
186 cargv[8],cargv[9],cargv[10],cargv[11],
187 cargv[12],cargv[13],cargv[14],cargv[15],
188 cargv[16],cargv[17],cargv[18],cargv[19],
189 cargv[20],cargv[21],cargv[22],cargv[23],
190 cargv[24],cargv[25],cargv[26],cargv[27],
191 cargv[28],cargv[29],cargv[30],cargv[31]);
196 len=
getlength(s); ip=(
unsigned char *) i;
197 for (j=0; j<len; j++) { putc(*ip, ws); ip++;}
202 fclose(s); free(vmem);
203 printf(
"connection closed\n"); }
213 int stat,entry,entry_type;
214 static int task_id=1;
215 unsigned char option,priority;
217 read(fd, &priority,1);
218 read(fd, &option, 1);
219 sprintf(taskname,
"VxWs_%d",task_id++);
220 stat=taskSpawn(taskname, priority, option, 3000,
call_vxw,fd);
221 if (stat==ERROR) { printf(
"cannot spawn\n");
return(ERROR); }
226 { printf(
"vxwserv aborting\n");
232 struct sockaddr_in serverAddr;
233 struct sockaddr_in clientAddr;
235 int connection_count=0;
239 sigabort.sv_handler =
abort;
240 sigabort.sv_mask = !SIGMASK(SIGINT);
241 sigabort.sv_flags= 0;
242 sigvec(SIGINT, &sigabort, 0);
247 bzero (&serverAddr,
sizeof (serverAddr));
248 bzero (&clientAddr,
sizeof (clientAddr));
250 sock = socket (AF_INET, SOCK_STREAM, 0);
251 if (
sock == ERROR) exit (1);
252 else printf(
"listening on socket %d\n",
sock);
255 serverAddr.sin_family = AF_INET;
258 while (bind (
sock, (SOCKADDR *)&serverAddr,
sizeof(serverAddr))==ERROR) {
259 printf (
"bind failed, errno = %d\n", errnoGet());
260 serverAddr.sin_port++; }
261 printf (
"port %d is bound.\n", serverAddr.sin_port);
263 if (listen (
sock, 2) == ERROR) {
264 printf (
"listen failed\n");
270 client_len =
sizeof (clientAddr);
271 snew = accept (
sock, (SOCKADDR *)&clientAddr, &client_len);
272 if (snew==ERROR) { printf(
"accept failed\n"); close(
sock);
break;}
273 printf(
"CLIENT accepted: sock=%d port=%d family=%d addr=%lx\n",
275 clientAddr.sin_port, clientAddr.sin_family,
276 clientAddr.sin_addr.s_addr);
278 read(snew, &special, 1);
280 { printf(
"spawn failed\n"); } ;
282 printf (
"totally %d connections established\n",connection_count);
static int getvector(FILE *s, unsigned char *vmem, int index, int bufsize)
static void abort(int sig)
void protocol_error(int x)
static void special(int k, int x, int y)
static getint(enum argument_type type, FILE *s)
struct number_union::@4 f
struct number_union::@5 i
static int getsymbol(FILE *s)
static getlength(FILE *s)
static double getfloat(enum argument_type type, FILE *s)