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);
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];
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]);
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");
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);
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);
259 printf (
"bind failed, errno = %d\n", errnoGet());
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);
280 { printf(
"spawn failed\n"); } ;
282 printf (
"totally %d connections established\n",connection_count);