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