Index: src/IRCChannel.m ================================================================== --- src/IRCChannel.m +++ src/IRCChannel.m @@ -17,10 +17,12 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ + +#import #import "IRCChannel.h" @implementation IRCChannel @synthesize name, users; Index: src/IRCConnection.h ================================================================== --- src/IRCConnection.h +++ src/IRCConnection.h @@ -108,8 +108,8 @@ toChannel: (IRCChannel*)channel; - (void)kickUser: (OFString*)user fromChannel: (IRCChannel*)channel withReason: (OFString*)reason; - (void)changeNicknameTo: (OFString*)nickname; -- (void)process; +- (void)processLine: (OFString*)line; - (void)handleConnection; @end Index: src/IRCConnection.m ================================================================== --- src/IRCConnection.m +++ src/IRCConnection.m @@ -27,10 +27,12 @@ #import #import #import #import + +#import #import "IRCConnection.h" #import "IRCUser.h" #import "IRCChannel.h" @@ -161,35 +163,16 @@ - (void)changeNicknameTo: (OFString*)nickname_ { [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 didReceiveLine: line]; @@ -499,15 +482,50 @@ [pool release]; return; } } + +- (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 { [sock release];