+
+-(void)spinoffReadLoop
+{
+ NSPort *p1 = [NSPort port], *p2 = [NSPort port];
+ NSConnection *dcon = [[NSConnection alloc] initWithReceivePort:p1 sendPort:p2];
+ NSArray *par = [NSArray arrayWithObjects:p2,p1,nil];
+ [dcon setRootObject:delegate];
+ [NSThread detachNewThreadSelector:@selector(socketReadLoop:) toTarget:self withObject:par]; //spawn read thread
+}
+
+-(void)socketReadLoop:(id)data
+{
+ NSAutoreleasePool *ap = [[NSAutoreleasePool alloc] init];
+ NSConnection *dcon = [[NSConnection alloc] initWithReceivePort:[data objectAtIndex:0] sendPort:[data objectAtIndex:1]];
+ NSProxy *dp = [dcon rootProxy];
+ char *buf = malloc(bufs);
+ unsigned long readLen = 0;
+
+lstart:
+ do
+ {
+ NSData *d = [NSData alloc];
+ readLen = recv(sockfd,buf,bufs,0);
+ [d initWithBytesNoCopy:buf length:readLen];
+ [readPipe writeData:d];
+ [d release];
+ [dp dataRecieved:self];
+ }
+ while (!actionflag);
+ actionflag = 0;
+ if (dieflag)
+ {
+ free(buf);
+ [dcon release];
+ [ap release];
+ dieflag = 0;
+ return;
+ }
+
+ {
+ NSData *d = [writePipe readAllData];
+ write(sockfd,[d bytes],[d length]);
+ goto lstart;
+ }
+}