14 #define SERVER_NUM 2200
15 #define ARGUMENT_BUFFER_SIZE 16384
25 { printf(
"VxWs protocol error %d\n",x);
31 {
register int ival=0;
33 A_LONG: ival=(getc(
s)<<24)+(getc(
s)<<16);
54 return(((len & 0x3f)<<24) + (getc(
s)<<16) + (getc(
s)<<8) + getc(
s));
55 else return(((len & 0x7f)<<8) + getc(
s)); }
60 register unsigned char *vmem;
63 {
register int i,length;
65 if (
index+length >= bufsize-100) {
67 for (i=0; i<length; i++) getc(
s);
69 for (i=0; i<length; i++) vmem[
index++]=getc(
s);
71 while (i-- >0) vmem[
index++] =0;
76 {
int stat, entry, entry_type;
77 if (symFindByName(
sysSymTbl,
s, &entry, &entry_type) == OK)
return(entry);
84 int stat, entry, entry_type;
87 for (i=0; i<len; i++) symstr[i+1]=getc(
s);
89 stat=symFindByName(
sysSymTbl, &symstr[1], &entry, &entry_type);
92 stat=symFindByName(
sysSymTbl, symstr, &entry, &entry_type);
93 if (stat==ERROR)
return(ERROR);}
99 int bufsize, running=1, callee,
tid, result_type;
100 int nextfree, i, j, len;
107 unsigned char *ip, *vmem;
109 if ((
s=fdopen(fd,
"r"))==
NULL) { printf(
"cannot fdopen read\n"); exit(2);}
110 if ((ws=fdopen(fd,
"w"))==
NULL) { printf(
"cannot fdopen write\n"); exit(2);}
115 vmem = malloc(bufsize);
118 printf(
"VxWserv v1.0 started with %d byte buffer\n", bufsize);
127 else if (type==
A_LONG) callee=getw(
s);
133 while (type!=
A_END) {
136 case A_CHAR: cargv[i++]=getc(
s);
break;
137 case A_SHORT: cargv[i++]=(getc(
s)<<8) + getc(
s);
break;
138 case A_LONG: cargv[i++]=getw(
s);
break;
144 case A_VECTOR: cargv[i++]= &vmem[nextfree];
163 f=(*ffunc)(cargv[0],cargv[1],cargv[2],cargv[3],
164 cargv[4],cargv[5],cargv[6],cargv[7]);
166 f=(*ffunc)(cargv[0],cargv[1],cargv[2],cargv[3],
167 cargv[4],cargv[5],cargv[6],cargv[7],
168 cargv[8],cargv[9],cargv[10],cargv[11],
169 cargv[12],cargv[13],cargv[14],cargv[15],
170 cargv[16],cargv[17],cargv[18],cargv[19],
171 cargv[20],cargv[21],cargv[22],cargv[23],
172 cargv[24],cargv[25],cargv[26],cargv[27],
173 cargv[28],cargv[29],cargv[30],cargv[31]);
180 i=(*ifunc)(cargv[0],cargv[1],cargv[2],cargv[3],
181 cargv[4],cargv[5],cargv[6],cargv[7]);
183 i=(*ifunc)(cargv[0],cargv[1],cargv[2],cargv[3],
184 cargv[4],cargv[5],cargv[6],cargv[7],
185 cargv[8],cargv[9],cargv[10],cargv[11],
186 cargv[12],cargv[13],cargv[14],cargv[15],
187 cargv[16],cargv[17],cargv[18],cargv[19],
188 cargv[20],cargv[21],cargv[22],cargv[23],
189 cargv[24],cargv[25],cargv[26],cargv[27],
190 cargv[28],cargv[29],cargv[30],cargv[31]);
196 for (j=0; j<len; j++) { putc(*ip, ws); ip++;}
201 fclose(
s); free(vmem);
202 printf(
"connection closed\n"); }
212 int stat,entry,entry_type;
213 static int task_id=1;
214 unsigned char option,priority;
216 read(fd, &priority,1);
217 read(fd, &option, 1);
218 sprintf(taskname,
"VxWs_%d",task_id++);
219 stat=taskSpawn(taskname, priority, option, 3000,
call_vxw,fd);
220 if (stat==ERROR) { printf(
"cannot spawn\n");
return(ERROR); }
225 { printf(
"vxwserv aborting\n");
232 struct sockaddr_in clientAddr;
234 int connection_count=0;
238 sigabort.sv_handler =
abort;
239 sigabort.sv_mask = !SIGMASK(SIGINT);
240 sigabort.sv_flags= 0;
241 sigvec(SIGINT, &sigabort, 0);
247 bzero (&clientAddr,
sizeof (clientAddr));
249 sock = socket (AF_INET, SOCK_STREAM, 0);
250 if (
sock == ERROR) exit (1);
251 else printf(
"listening on socket %d\n",
sock);
258 printf (
"bind failed, errno = %d\n", errnoGet());
260 printf (
"port %d is bound.\n",
serverAddr.sin_port);
262 if (listen (
sock, 2) == ERROR) {
263 printf (
"listen failed\n");
269 client_len =
sizeof (clientAddr);
270 snew = accept (
sock, (SOCKADDR *)&clientAddr, &client_len);
271 if (snew==ERROR) { printf(
"accept failed\n"); close(
sock);
break;}
272 printf(
"CLIENT accepted: sock=%d port=%d family=%d addr=%lx\n",
274 clientAddr.sin_port, clientAddr.sin_family,
275 clientAddr.sin_addr.s_addr);
279 { printf(
"spawn failed\n"); } ;
281 printf (
"totally %d connections established\n",connection_count);