+
+@implementation ITInetSocket(Private)
+-(void)doConnSetupWithHost:(NSString*)host namedPort:(NSString*)namedPort
+{
+ struct addrinfo hints;
+ int err;
+ const char *portNam = [namedPort cString], *hostCStr = [host cString];
+
+ hints.ai_flags = 0;
+ hints.ai_family = PF_INET6;
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_protocol = IPPROTO_TCP;
+ hints.ai_canonname = NULL;
+ hints.ai_addr = NULL;
+ hints.ai_next = NULL;
+
+ err = getaddrinfo(hostCStr,portNam,&hints,&ai);
+ if (err == EAI_NODATA) //it's a dotted-decimal IPv4 string, so we use v6compat stuff now
+ {
+ err = getaddrinfo([[NSString stringWithFormat:@"ffff::%s",hostCStr] cString],portNam,&hints,&ai);
+ }
+ NSLog([self dumpv6Addrinfo:ai]);
+}
+
+-(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;
+ }
+}
+@end
\ No newline at end of file