Skip to content

Commit 6fc2699

Browse files
committed
Adding ability to disconnect "cleanly" by sending terminating </stream:stream> element.
1 parent 2308ff0 commit 6fc2699

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

Core/XMPPStream.h

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -331,18 +331,23 @@ typedef enum XMPPStreamErrorCode XMPPStreamErrorCode;
331331

332332
/**
333333
* Disconnects from the remote host by closing the underlying TCP socket connection.
334+
* The terminating </stream:stream> element is not sent to the server.
334335
*
335-
* The disconnect method is synchronous.
336+
* This method is synchronous.
336337
* Meaning that the disconnect will happen immediately, even if there are pending elements yet to be sent.
337-
* The xmppStreamDidDisconnect:withError: method will be invoked before the disconnect method returns.
338338
*
339-
* The disconnectAfterSending method is asynchronous.
340-
* The disconnect will happen after all pending elements have been sent.
341-
* Attempting to send elements after this method is called will not result in the elements getting sent.
342-
* The disconnectAfterSending method will return immediately,
343-
* and the xmppStreamDidDisconnect:withError: delegate method will be invoked at a later time.
339+
* The xmppStreamDidDisconnect:withError: delegate method will immediately be dispatched onto the delegate queue.
344340
**/
345341
- (void)disconnect;
342+
343+
/**
344+
* Disconnects from the remote host by sending the terminating </stream:stream> element,
345+
* and then closing the underlying TCP socket connection.
346+
*
347+
* This method is asynchronous.
348+
* The disconnect will happen after all pending elements have been sent.
349+
* Attempting to send elements after this method has been called will not work (the elements won't get sent).
350+
**/
346351
- (void)disconnectAfterSending;
347352

348353
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Core/XMPPStream.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,13 @@ - (void)disconnectAfterSending
11371137
}
11381138
else
11391139
{
1140+
NSString *termStr = @"</stream:stream>";
1141+
NSData *termData = [termStr dataUsingEncoding:NSUTF8StringEncoding];
1142+
1143+
XMPPLogSend(@"SEND: %@", termStr);
1144+
numberOfBytesSent += [termData length];
1145+
1146+
[asyncSocket writeData:termData withTimeout:TIMEOUT_XMPP_WRITE tag:TAG_XMPP_WRITE_STREAM];
11401147
[asyncSocket disconnectAfterWriting];
11411148

11421149
// Everthing will be handled in socketDidDisconnect:withError:

0 commit comments

Comments
 (0)