- struct sockaddr_in csa;
- int csalen;
- signed int cfd;
- (void) timer;
- cfd = accept(sockfd,(struct sockaddr*)&csa,&csalen);
- if (cfd == -1) {
- if (errno == EWOULDBLOCK) return;
- else {perror("Too bad I haven't implemented error checking yet");}
- }
- else {
- ITInetSocket *csocket = [[[ITInetSocket alloc] initWithFD:cfd delegate:self] autorelease];
- [clients addObject:csocket];
- [delegate newClientJoined:csocket];
-
+ NSLog(@"stopping server thread");
+ dieflag = 1;
+ do {} while (dieflag == 1);
+}
+
+- (void)newClient:(int)cfd
+{
+ ITInetSocket *csocket = [[ITInetSocket alloc] initWithFD:cfd delegate:delegate];
+ NSLog(@"new client for this server");
+ [clients addObject:csocket];
+}
+
+- (void)socketAcceptLoop:(id)data
+{
+ NSAutoreleasePool *ap = [[NSAutoreleasePool alloc] init];
+ NSArray *par = data;
+ NSConnection *dcon = [[NSConnection alloc] initWithReceivePort:[par objectAtIndex:0] sendPort:[par objectAtIndex:1]];
+ NSProxy *dp = [dcon rootProxy];
+ while ((sockfd >= 0) && !dieflag)
+ {
+ signed int cfd;
+ cfd = accept(sockfd,NULL,NULL);
+ NSLog(@"Someone connected!");
+ [(id)dp newClient:cfd];
+ [ap release];
+ ap = [[NSAutoreleasePool alloc] init];