Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding ability to disconnect "cleanly" by sending terminating </strea…

…m:stream> element.
  • Loading branch information...
commit 6fc26993dd80f47640fde8afc9031605c0cb703a 1 parent 2308ff0
@robbiehanson authored
Showing with 19 additions and 7 deletions.
  1. +12 −7 Core/XMPPStream.h
  2. +7 −0 Core/XMPPStream.m
View
19 Core/XMPPStream.h
@@ -331,18 +331,23 @@ typedef enum XMPPStreamErrorCode XMPPStreamErrorCode;
/**
* Disconnects from the remote host by closing the underlying TCP socket connection.
+ * The terminating </stream:stream> element is not sent to the server.
*
- * The disconnect method is synchronous.
+ * This method is synchronous.
* Meaning that the disconnect will happen immediately, even if there are pending elements yet to be sent.
- * The xmppStreamDidDisconnect:withError: method will be invoked before the disconnect method returns.
*
- * The disconnectAfterSending method is asynchronous.
- * The disconnect will happen after all pending elements have been sent.
- * Attempting to send elements after this method is called will not result in the elements getting sent.
- * The disconnectAfterSending method will return immediately,
- * and the xmppStreamDidDisconnect:withError: delegate method will be invoked at a later time.
+ * The xmppStreamDidDisconnect:withError: delegate method will immediately be dispatched onto the delegate queue.
**/
- (void)disconnect;
+
+/**
+ * Disconnects from the remote host by sending the terminating </stream:stream> element,
+ * and then closing the underlying TCP socket connection.
+ *
+ * This method is asynchronous.
+ * The disconnect will happen after all pending elements have been sent.
+ * Attempting to send elements after this method has been called will not work (the elements won't get sent).
+**/
- (void)disconnectAfterSending;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
View
7 Core/XMPPStream.m
@@ -1137,6 +1137,13 @@ - (void)disconnectAfterSending
}
else
{
+ NSString *termStr = @"</stream:stream>";
+ NSData *termData = [termStr dataUsingEncoding:NSUTF8StringEncoding];
+
+ XMPPLogSend(@"SEND: %@", termStr);
+ numberOfBytesSent += [termData length];
+
+ [asyncSocket writeData:termData withTimeout:TIMEOUT_XMPP_WRITE tag:TAG_XMPP_WRITE_STREAM];
[asyncSocket disconnectAfterWriting];
// Everthing will be handled in socketDidDisconnect:withError:
Please sign in to comment.
Something went wrong with that request. Please try again.