From 6a89ab76d006fcc115bc69a5af6f2afc62963da4 Mon Sep 17 00:00:00 2001 From: Jonathan Schleifer Date: Sat, 24 Nov 2012 01:36:29 +0100 Subject: [PATCH] Make it possible to get exceptions in async mode. --- src/XMPPConnection.h | 12 ++++++++++++ src/XMPPConnection.m | 17 +++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/XMPPConnection.h b/src/XMPPConnection.h index 35a5be5..7fc11df 100644 --- a/src/XMPPConnection.h +++ b/src/XMPPConnection.h @@ -116,6 +116,18 @@ */ - (void)connectionWasClosed: (XMPPConnection*)connection; +/** + * \brief This callback is called when the connection threw an exception. + * + * This is only called for connections on which \ref handleConnection: has been + * called. + * + * \param connection The connection which threw an exception + * \param exception The exception the connection threw + */ +- (void)connection: (XMPPConnection*)connection + didThrowException: (OFException*)exception; + /** * \brief This callback is called when the connection is about to upgrade to * TLS. diff --git a/src/XMPPConnection.m b/src/XMPPConnection.m index 09b9ab6..6367464 100644 --- a/src/XMPPConnection.m +++ b/src/XMPPConnection.m @@ -344,13 +344,26 @@ exception: (OFException*)exception { if (exception != nil) { + [delegates broadcastSelector: @selector(connection: + didThrowException::) + withObject: self + withObject: exception]; [self close]; return NO; } - if (![self XMPP_parseBuffer: buffer - length: length]) + @try { + if (![self XMPP_parseBuffer: buffer + length: length]) + return NO; + } @catch (id e) { + [delegates broadcastSelector: @selector(connection: + didThrowException::) + withObject: self + withObject: e]; + [self close]; return NO; + } if (oldParser != nil || oldElementBuilder != nil) { [oldParser release];