5751242 [rkeene@sledge /home/rkeene/devel/old/distlib]$ cat -n distserv.c
 1 #include "net.h"
 2 #include "distlib.h"
 3 #include "config.h"
 4 #include <fcntl.h>
 5 #include <unistd.h>
 6 #include <sys/types.h>
 7 #include <sys/socket.h>
 8 #include <stdio.h>
 9 #include <stdlib.h>
10 
11 #define BUFSIZE 2048
12 
13 int main(int argc, char **argv) {
14     struct sockaddr *peername=0;
15     int peernamelen=0;
16     int listensock, sockids[MAX_CLIENTS];
17     int i=0,x,bytes;
18     int taskid;
19     char buffer[BUFSIZE];
20     if ((listensock=createlisten(PORT))<0) return(-1);
21     fcntl(listensock, F_SETFL, O_NONBLOCK);
22     while(1) {
23         if ( (sockids[i]=accept(listensock, peername, &peernamelen))>0 ) {
24             printf("Recieved connection\n");
25             fcntl(sockids[i++], F_SETFL, O_NONBLOCK);
26         }
27         usleep(10000);
28         for (x=0;x<i;x++) {
29             if ((bytes=recv(sockids[x],buffer,sizeof(buffer)-1,0))>0) {
30                 printf("Recieved %i bytes.\n",bytes);
31                 taskid=distlib_decode(buffer, bytes);
32                 write(sockids[x], &taskid, sizeof(taskid));
33             }
34         }
35     }
36 }
5751243 [rkeene@sledge /home/rkeene/devel/old/distlib]$

Click here to go back to the directory listing.
Click here to download this file.
last modified: 2000-02-17 04:50:24