git.ithinksw.org
/
ITFoundation.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Sockets don't quite work, but they will almost work.
[ITFoundation.git]
/
ITInetSocket.m
diff --git
a/ITInetSocket.m
b/ITInetSocket.m
index
c51c05a
..
b61e44f
100755
(executable)
--- a/
ITInetSocket.m
+++ b/
ITInetSocket.m
@@
-30,7
+30,7
@@
ITServiceBrowserDelegate *bd = [[ITServiceBrowserDelegate alloc] initWithDelegate:d];
[browse setDelegate:bd];
ITServiceBrowserDelegate *bd = [[ITServiceBrowserDelegate alloc] initWithDelegate:d];
[browse setDelegate:bd];
- [browse searchForServicesOfType:[NSString stringWithFormat:@"
._%@._tcp",type] inDomain:nil
];
+ [browse searchForServicesOfType:[NSString stringWithFormat:@"
_%@._tcp.",type] inDomain:@""
];
}
-(id)initWithFD:(int)fd delegate:(id <ITInetSocketDelegate,NSObject>)d
}
-(id)initWithFD:(int)fd delegate:(id <ITInetSocketDelegate,NSObject>)d
@@
-41,13
+41,15
@@
sockfd = fd;
delegate = [d retain];
port = 0;
sockfd = fd;
delegate = [d retain];
port = 0;
- writePipe = [[ITByteStream alloc] init];
- readPipe = [[ITByteStream alloc] init];
+ writePipe = [[ITByteStream alloc] init
WithDelegate:self
];
+ readPipe = [[ITByteStream alloc] init
WithDelegate:d
];
ai = nil;
sarr = nil;
bufs = 512;
actionflag = dieflag = 0;
ai = nil;
sarr = nil;
bufs = 512;
actionflag = dieflag = 0;
+ nc = 0;
}
}
+ [self spinoffReadLoop];
return self;
}
return self;
}
@@
-59,12
+61,13
@@
sockfd = -1;
delegate = [d retain];
port = 0;
sockfd = -1;
delegate = [d retain];
port = 0;
- writePipe = [[ITByteStream alloc] init];
- readPipe = [[ITByteStream alloc] init];
+ writePipe = [[ITByteStream alloc] init
WithDelegate:self
];
+ readPipe = [[ITByteStream alloc] init
WithDelegate:d
];
ai = nil;
sarr = nil;
bufs = 512;
actionflag = dieflag = 0;
ai = nil;
sarr = nil;
bufs = 512;
actionflag = dieflag = 0;
+ nc = 1;
}
return self;
}
}
return self;
}
@@
-109,18
+112,21
@@
while (d = [e nextObject])
{
struct sockaddr *s = (struct sockaddr*)[d bytes];
while (d = [e nextObject])
{
struct sockaddr *s = (struct sockaddr*)[d bytes];
+ bzero(a,sizeof(struct addrinfo));
a->ai_family = s->sa_family;
a->ai_addr = s;
a->ai_next = malloc(sizeof(struct addrinfo));
a = a->ai_next;
}
a->ai_family = s->sa_family;
a->ai_addr = s;
a->ai_next = malloc(sizeof(struct addrinfo));
a = a->ai_next;
}
+ ai_cur = ai;
+ [self realDoConnection];
}
}
-(void)disconnect
{
}
}
-(void)disconnect
{
+ NSLog(@"Got a disconnect");
dieflag = 1;
dieflag = 1;
- do {} while (dieflag == 1);
}
-(void)retryConnection
}
-(void)retryConnection
@@
-148,6
+154,14
@@
{
bufs = _bufs;
}
{
bufs = _bufs;
}
+
+-(void)newDataAdded:(ITByteStream*)sender
+{
+ NSLog(@"writePipe got something");
+ actionflag = 1;
+ do {} while (actionflag == 1);
+ NSLog(@"thread saw actionFlag");
+}
@end
@implementation ITInetSocket(Debugging)
@end
@implementation ITInetSocket(Debugging)
@@
-185,7
+199,7
@@
struct addrinfo hints;
int err;
const char *portNam = [namedPort cString], *hostCStr = [host cString];
struct addrinfo hints;
int err;
const char *portNam = [namedPort cString], *hostCStr = [host cString];
-
+ state = ITInetSocketConnecting;
hints.ai_flags = 0;
hints.ai_family = PF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = 0;
hints.ai_family = PF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
@@
-205,7
+219,7
@@
-(void)realDoConnection
{
-(void)realDoConnection
{
- sockfd = socket(ai_cur->ai_
addr->sa_
family,SOCK_STREAM,IPPROTO_TCP);
+ sockfd = socket(ai_cur->ai_family,SOCK_STREAM,IPPROTO_TCP);
[self spinoffReadLoop];
}
[self spinoffReadLoop];
}
@@
-222,11
+236,13
@@
{
NSAutoreleasePool *ap = [[NSAutoreleasePool alloc] init];
NSConnection *dcon = [[NSConnection alloc] initWithReceivePort:[data objectAtIndex:0] sendPort:[data objectAtIndex:1]];
{
NSAutoreleasePool *ap = [[NSAutoreleasePool alloc] init];
NSConnection *dcon = [[NSConnection alloc] initWithReceivePort:[data objectAtIndex:0] sendPort:[data objectAtIndex:1]];
- NSProxy *dp = [
dcon rootProxy
];
+ NSProxy *dp = [
[dcon rootProxy] retain
];
char *buf = malloc(bufs);
unsigned long readLen = 0;
signed int err;
char *buf = malloc(bufs);
unsigned long readLen = 0;
signed int err;
- NSLog(@"EYE MAEK CONNECT");
+ [readPipe setDelegate:dp];
+ if (nc){
+ NSLog(@"Connecting");
err = connect(sockfd,ai_cur->ai_addr,ai_cur->ai_addrlen);
if (err == -1)
{
err = connect(sockfd,ai_cur->ai_addr,ai_cur->ai_addrlen);
if (err == -1)
{
@@
-234,39
+250,48
@@
[(id)dp errorOccured:ITInetCouldNotConnect during:ITInetSocketConnecting onSocket:self];
goto dieaction;
}
[(id)dp errorOccured:ITInetCouldNotConnect during:ITInetSocketConnecting onSocket:self];
goto dieaction;
}
+ }
+ NSLog(@"Sending finishedConnecting");
[(id)dp finishedConnecting:self];
lstart:
[(id)dp finishedConnecting:self];
lstart:
-
- while (!actionflag && !
[writePipe availableDataLength] && !
dieflag)
+ state = ITInetSocketListening;
+ while (!actionflag && !dieflag)
{
{
- NSData *d;
readLen = recv(sockfd,buf,bufs,0);
readLen = recv(sockfd,buf,bufs,0);
+ state = ITInetSocketReading;
+ if (readLen == -1) {[(id)dp errorOccured:ITInetConnectionDropped during:ITInetSocketReading onSocket:self];goto dieaction;}
if (readLen) {
if (readLen) {
-
d = [NSData alloc]
;
-
[d initWithBytesNoCopy:buf length:readLen freeWhenDone:NO]
;
- [readPipe write
Data:d
];
- [
d
release];
-
[(id)dp dataReceived:self
];
+
NSLog(@"recv'd")
;
+
NSLog(@"Doing writeData to readPipe")
;
+ [readPipe write
Bytes:buf len:readLen
];
+ [
ap
release];
+
ap = [[NSAutoreleasePool alloc] init
];
}
}
}
}
-
+ state = ITInetSocketListening;
actionflag = 0;
if (dieflag)
{
dieaction:
actionflag = 0;
if (dieflag)
{
dieaction:
+ state = ITInetSocketDisconnected;
perror("Awh");
free(buf);
shutdown(sockfd,2);
[dcon release];
perror("Awh");
free(buf);
shutdown(sockfd,2);
[dcon release];
+ [dp release];
[ap release];
dieflag = 0;
return;
}
{
[ap release];
dieflag = 0;
return;
}
{
+ state = ITInetSocketWriting;
+ NSLog(@"Emptying writePipe");
NSData *d = [writePipe readAllData];
write(sockfd,[d bytes],[d length]);
NSData *d = [writePipe readAllData];
write(sockfd,[d bytes],[d length]);
+ [ap release];
+ ap = [[NSAutoreleasePool alloc] init];
goto lstart;
}
goto dieaction;
goto lstart;
}
goto dieaction;