Make non-blocking processing possible.
FossilOrigin-Name: 8b4878957125416dad0f0a91a2b64ae63c8284e39286e70eb7ae15086ef90307
This commit is contained in:
parent
a8b7db8d28
commit
8057b5df61
2 changed files with 275 additions and 275 deletions
|
@ -107,5 +107,6 @@
|
||||||
fromChannel: (IRCChannel*)channel
|
fromChannel: (IRCChannel*)channel
|
||||||
withReason: (OFString*)reason;
|
withReason: (OFString*)reason;
|
||||||
- (void)changeNicknameTo: (OFString*)nickname;
|
- (void)changeNicknameTo: (OFString*)nickname;
|
||||||
|
- (void)process;
|
||||||
- (void)handleConnection;
|
- (void)handleConnection;
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -163,25 +163,23 @@
|
||||||
[self sendLineWithFormat: @"NICK %@", nickname_];
|
[self sendLineWithFormat: @"NICK %@", nickname_];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)handleConnection
|
- (void)process
|
||||||
{
|
{
|
||||||
OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
|
OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
|
||||||
OFString *line;
|
OFString *line;
|
||||||
OFArray *split;
|
OFArray *split;
|
||||||
|
|
||||||
for (;;) {
|
|
||||||
OFString *action = nil;
|
OFString *action = nil;
|
||||||
|
|
||||||
@try {
|
@try {
|
||||||
line = [sock readLine];
|
line = [sock tryReadLine];
|
||||||
} @catch (OFInvalidEncodingException *e) {
|
} @catch (OFInvalidEncodingException *e) {
|
||||||
[e dealloc];
|
[e dealloc];
|
||||||
line = [sock readLineWithEncoding:
|
line = [sock tryReadLineWithEncoding:
|
||||||
OF_STRING_ENCODING_WINDOWS_1252];
|
OF_STRING_ENCODING_WINDOWS_1252];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line == nil)
|
if (line == nil)
|
||||||
break;
|
return;
|
||||||
|
|
||||||
if ([delegate respondsToSelector:
|
if ([delegate respondsToSelector:
|
||||||
@selector(connection:didReceiveLine:)])
|
@selector(connection:didReceiveLine:)])
|
||||||
|
@ -197,7 +195,7 @@
|
||||||
withString: @"PONG"];
|
withString: @"PONG"];
|
||||||
[self sendLine: s];
|
[self sendLine: s];
|
||||||
|
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
action = [[split objectAtIndex: 1] uppercaseString];
|
action = [[split objectAtIndex: 1] uppercaseString];
|
||||||
|
@ -208,7 +206,8 @@
|
||||||
@selector(connectionWasEstablished:)])
|
@selector(connectionWasEstablished:)])
|
||||||
[delegate connectionWasEstablished: self];
|
[delegate connectionWasEstablished: self];
|
||||||
|
|
||||||
continue;
|
[pool release];
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* JOIN */
|
/* JOIN */
|
||||||
|
@ -218,14 +217,12 @@
|
||||||
IRCUser *user;
|
IRCUser *user;
|
||||||
IRCChannel *channel;
|
IRCChannel *channel;
|
||||||
|
|
||||||
who = [who substringWithRange:
|
who = [who substringWithRange: of_range(1, who.length - 1)];
|
||||||
of_range(1, who.length - 1)];
|
|
||||||
where = [where substringWithRange:
|
where = [where substringWithRange:
|
||||||
of_range(1, where.length - 1)];
|
of_range(1, where.length - 1)];
|
||||||
user = [IRCUser IRCUserWithString: who];
|
user = [IRCUser IRCUserWithString: who];
|
||||||
|
|
||||||
if ([who hasPrefix:
|
if ([who hasPrefix: [nickname stringByAppendingString: @"!"]]) {
|
||||||
[nickname stringByAppendingString: @"!"]]) {
|
|
||||||
channel = [IRCChannel channelWithName: where];
|
channel = [IRCChannel channelWithName: where];
|
||||||
[channels setObject: channel
|
[channels setObject: channel
|
||||||
forKey: where];
|
forKey: where];
|
||||||
|
@ -238,7 +235,8 @@
|
||||||
didSeeUser: user
|
didSeeUser: user
|
||||||
joinChannel: channel];
|
joinChannel: channel];
|
||||||
|
|
||||||
continue;
|
[pool release];
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* PART */
|
/* PART */
|
||||||
|
@ -249,11 +247,9 @@
|
||||||
IRCChannel *channel;
|
IRCChannel *channel;
|
||||||
OFString *reason = nil;
|
OFString *reason = nil;
|
||||||
size_t pos = who.length + 1 +
|
size_t pos = who.length + 1 +
|
||||||
[[split objectAtIndex: 1] length] + 1 +
|
[[split objectAtIndex: 1] length] + 1 + where.length;
|
||||||
where.length;
|
|
||||||
|
|
||||||
who = [who substringWithRange:
|
who = [who substringWithRange: of_range(1, who.length - 1)];
|
||||||
of_range(1, who.length - 1)];
|
|
||||||
user = [IRCUser IRCUserWithString: who];
|
user = [IRCUser IRCUserWithString: who];
|
||||||
channel = [channels objectForKey: where];
|
channel = [channels objectForKey: where];
|
||||||
|
|
||||||
|
@ -269,7 +265,8 @@
|
||||||
leaveChannel: channel
|
leaveChannel: channel
|
||||||
withReason: reason];
|
withReason: reason];
|
||||||
|
|
||||||
continue;
|
[pool release];
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* KICK */
|
/* KICK */
|
||||||
|
@ -281,11 +278,10 @@
|
||||||
IRCChannel *channel;
|
IRCChannel *channel;
|
||||||
OFString *reason = nil;
|
OFString *reason = nil;
|
||||||
size_t pos = who.length + 1 +
|
size_t pos = who.length + 1 +
|
||||||
[[split objectAtIndex: 1] length] + 1 +
|
[[split objectAtIndex: 1] length] + 1 + where.length + 1 +
|
||||||
where.length + 1 + whom.length;
|
whom.length;
|
||||||
|
|
||||||
who = [who substringWithRange:
|
who = [who substringWithRange: of_range(1, who.length - 1)];
|
||||||
of_range(1, who.length - 1)];
|
|
||||||
user = [IRCUser IRCUserWithString: who];
|
user = [IRCUser IRCUserWithString: who];
|
||||||
channel = [channels objectForKey: where];
|
channel = [channels objectForKey: where];
|
||||||
|
|
||||||
|
@ -302,7 +298,8 @@
|
||||||
fromChannel: channel
|
fromChannel: channel
|
||||||
withReason: reason];
|
withReason: reason];
|
||||||
|
|
||||||
continue;
|
[pool release];
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* QUIT */
|
/* QUIT */
|
||||||
|
@ -310,11 +307,9 @@
|
||||||
OFString *who = [split objectAtIndex: 0];
|
OFString *who = [split objectAtIndex: 0];
|
||||||
IRCUser *user;
|
IRCUser *user;
|
||||||
OFString *reason = nil;
|
OFString *reason = nil;
|
||||||
size_t pos = who.length + 1 +
|
size_t pos = who.length + 1 + [[split objectAtIndex: 1] length];
|
||||||
[[split objectAtIndex: 1] length];
|
|
||||||
|
|
||||||
who = [who substringWithRange:
|
who = [who substringWithRange: of_range(1, who.length - 1)];
|
||||||
of_range(1, who.length - 1)];
|
|
||||||
user = [IRCUser IRCUserWithString: who];
|
user = [IRCUser IRCUserWithString: who];
|
||||||
|
|
||||||
if (split.count > 2)
|
if (split.count > 2)
|
||||||
|
@ -327,7 +322,8 @@
|
||||||
didSeeUserQuit: user
|
didSeeUserQuit: user
|
||||||
withReason: reason];
|
withReason: reason];
|
||||||
|
|
||||||
continue;
|
[pool release];
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* NICK */
|
/* NICK */
|
||||||
|
@ -336,8 +332,7 @@
|
||||||
OFString *newNickname = [split objectAtIndex: 2];
|
OFString *newNickname = [split objectAtIndex: 2];
|
||||||
IRCUser *user;
|
IRCUser *user;
|
||||||
|
|
||||||
who = [who substringWithRange:
|
who = [who substringWithRange: of_range(1, who.length - 1)];
|
||||||
of_range(1, who.length - 1)];
|
|
||||||
newNickname = [newNickname substringWithRange:
|
newNickname = [newNickname substringWithRange:
|
||||||
of_range(1, newNickname.length - 1)];
|
of_range(1, newNickname.length - 1)];
|
||||||
|
|
||||||
|
@ -353,6 +348,9 @@
|
||||||
[delegate connection: self
|
[delegate connection: self
|
||||||
didSeeUser: user
|
didSeeUser: user
|
||||||
changeNicknameTo: newNickname];
|
changeNicknameTo: newNickname];
|
||||||
|
|
||||||
|
[pool release];
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* PRIVMSG */
|
/* PRIVMSG */
|
||||||
|
@ -362,11 +360,9 @@
|
||||||
IRCUser *user;
|
IRCUser *user;
|
||||||
OFString *msg;
|
OFString *msg;
|
||||||
size_t pos = from.length + 1 +
|
size_t pos = from.length + 1 +
|
||||||
[[split objectAtIndex: 1] length] + 1 +
|
[[split objectAtIndex: 1] length] + 1 + to.length;
|
||||||
to.length;
|
|
||||||
|
|
||||||
from = [from substringWithRange:
|
from = [from substringWithRange: of_range(1, from.length - 1)];
|
||||||
of_range(1, from.length - 1)];
|
|
||||||
msg = [line substringWithRange:
|
msg = [line substringWithRange:
|
||||||
of_range(pos + 2, line.length - pos - 2)];
|
of_range(pos + 2, line.length - pos - 2)];
|
||||||
user = [IRCUser IRCUserWithString: from];
|
user = [IRCUser IRCUserWithString: from];
|
||||||
|
@ -393,7 +389,8 @@
|
||||||
fromUser: user];
|
fromUser: user];
|
||||||
}
|
}
|
||||||
|
|
||||||
continue;
|
[pool release];
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* NOTICE */
|
/* NOTICE */
|
||||||
|
@ -403,17 +400,17 @@
|
||||||
IRCUser *user = nil;
|
IRCUser *user = nil;
|
||||||
OFString *notice;
|
OFString *notice;
|
||||||
size_t pos = from.length + 1 +
|
size_t pos = from.length + 1 +
|
||||||
[[split objectAtIndex: 1] length] + 1 +
|
[[split objectAtIndex: 1] length] + 1 + to.length;
|
||||||
to.length;
|
|
||||||
|
|
||||||
from = [from substringWithRange:
|
from = [from substringWithRange: of_range(1, from.length - 1)];
|
||||||
of_range(1, from.length - 1)];
|
|
||||||
notice = [line substringWithRange:
|
notice = [line substringWithRange:
|
||||||
of_range(pos + 2, line.length - pos - 2)];
|
of_range(pos + 2, line.length - pos - 2)];
|
||||||
|
|
||||||
if (![from containsString: @"!"] || [to isEqual: @"*"])
|
if (![from containsString: @"!"] || [to isEqual: @"*"]) {
|
||||||
/* System message - ignore for now */
|
/* System message - ignore for now */
|
||||||
continue;
|
[pool release];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
user = [IRCUser IRCUserWithString: from];
|
user = [IRCUser IRCUserWithString: from];
|
||||||
|
|
||||||
|
@ -438,13 +435,15 @@
|
||||||
fromUser: user];
|
fromUser: user];
|
||||||
}
|
}
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
[pool releaseObjects];
|
|
||||||
}
|
|
||||||
|
|
||||||
[pool release];
|
[pool release];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)handleConnection
|
||||||
|
{
|
||||||
|
while (![sock isAtEndOfStream])
|
||||||
|
[self process];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)dealloc
|
- (void)dealloc
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue