Use async I/O.
FossilOrigin-Name: e7f34ce8d03e83a75b0da0471aafe0e84e139f0b2e4f5dde571bd6b5bdd07cbd
This commit is contained in:
parent
89e58c938f
commit
2d705754fd
3 changed files with 43 additions and 23 deletions
|
@ -20,6 +20,8 @@
|
|||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#import <ObjFW/OFString.h>
|
||||
|
||||
#import "IRCChannel.h"
|
||||
|
||||
@implementation IRCChannel
|
||||
|
|
|
@ -110,6 +110,6 @@
|
|||
fromChannel: (IRCChannel*)channel
|
||||
withReason: (OFString*)reason;
|
||||
- (void)changeNicknameTo: (OFString*)nickname;
|
||||
- (void)process;
|
||||
- (void)processLine: (OFString*)line;
|
||||
- (void)handleConnection;
|
||||
@end
|
||||
|
|
|
@ -30,6 +30,8 @@
|
|||
|
||||
#import <ObjFW/OFInvalidEncodingException.h>
|
||||
|
||||
#import <ObjFW/macros.h>
|
||||
|
||||
#import "IRCConnection.h"
|
||||
#import "IRCUser.h"
|
||||
#import "IRCChannel.h"
|
||||
|
@ -163,31 +165,12 @@
|
|||
[self sendLineWithFormat: @"NICK %@", nickname_];
|
||||
}
|
||||
|
||||
- (void)process
|
||||
- (void)processLine: (OFString*)line
|
||||
{
|
||||
OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
|
||||
OFString *line;
|
||||
OFArray *split;
|
||||
OFString *action = nil;
|
||||
|
||||
if (sock.atEndOfStream) {
|
||||
if ([delegate respondsToSelector:
|
||||
@selector(connectionWasClosed:)])
|
||||
[delegate connectionWasClosed: self];
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@try {
|
||||
line = [sock tryReadLine];
|
||||
} @catch (OFInvalidEncodingException *e) {
|
||||
line = [sock tryReadLineWithEncoding:
|
||||
OF_STRING_ENCODING_WINDOWS_1252];
|
||||
}
|
||||
|
||||
if (line == nil)
|
||||
return;
|
||||
|
||||
if ([delegate respondsToSelector:
|
||||
@selector(connection:didReceiveLine:)])
|
||||
[delegate connection: self
|
||||
|
@ -502,10 +485,45 @@
|
|||
}
|
||||
}
|
||||
|
||||
- (BOOL)connection: (OFTCPSocket*)connection
|
||||
didReceiveISO88591Line: (OFString*)line
|
||||
exception: (OFException*)exception
|
||||
{
|
||||
if (line != nil) {
|
||||
[self processLine: line];
|
||||
[sock asyncReadLineWithTarget: self
|
||||
selector: @selector(connection:
|
||||
didReceiveLine:
|
||||
exception:)];
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL)connection: (OFTCPSocket*)connection
|
||||
didReceiveLine: (OFString*)line
|
||||
exception: (OFException*)exception
|
||||
{
|
||||
if (line != nil) {
|
||||
[self processLine: line];
|
||||
return YES;
|
||||
}
|
||||
|
||||
if ([exception isKindOfClass: [OFInvalidEncodingException class]])
|
||||
[sock asyncReadLineWithEncoding: OF_STRING_ENCODING_ISO_8859_1
|
||||
target: self
|
||||
selector: @selector(connection:
|
||||
didReceiveISO88591Line:
|
||||
exception:)];
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void)handleConnection
|
||||
{
|
||||
while (![sock isAtEndOfStream])
|
||||
[self process];
|
||||
[sock asyncReadLineWithTarget: self
|
||||
selector: @selector(connection:didReceiveLine:
|
||||
exception:)];
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue