Skip to content

Commit a12f9c1

Browse files
committed
Adding delegate method to XMPPStream to detect a "clean" disconnect (stream sent closing </stream:stream> stanza)
1 parent 1da7288 commit a12f9c1

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

Core/XMPPStream.h

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -994,11 +994,31 @@ extern const NSTimeInterval XMPPStreamTimeoutNone;
994994
/**
995995
* This method is called if the disconnect method is called.
996996
* It may be used to determine if a disconnection was purposeful, or due to an error.
997+
*
998+
* Note: A disconnect may be either "clean" or "dirty".
999+
* A "clean" disconnect is when the stream sends the closing </stream:stream> stanza before disconnecting.
1000+
* A "dirty" disconnect is when the stream simply closes its TCP socket.
1001+
* In most cases it makes no difference how the disconnect occurs,
1002+
* but there are a few contexts in which the difference has various protocol implications.
1003+
*
1004+
* @see xmppStreamDidSendClosingStreamStanza
9971005
**/
9981006
- (void)xmppStreamWasToldToDisconnect:(XMPPStream *)sender;
9991007

10001008
/**
1001-
* This methods is called if the XMPP Stream's connect times out
1009+
* This method is called after the stream has sent the closing </stream:stream> stanza.
1010+
* This signifies a "clean" disconnect.
1011+
*
1012+
* Note: A disconnect may be either "clean" or "dirty".
1013+
* A "clean" disconnect is when the stream sends the closing </stream:stream> stanza before disconnecting.
1014+
* A "dirty" disconnect is when the stream simply closes its TCP socket.
1015+
* In most cases it makes no difference how the disconnect occurs,
1016+
* but there are a few contexts in which the difference has various protocol implications.
1017+
**/
1018+
- (void)xmppStreamDidSendClosingStreamStanza:(XMPPStream *)sender;
1019+
1020+
/**
1021+
* This methods is called if the XMPP stream's connect times out.
10021022
**/
10031023
- (void)xmppStreamConnectDidTimeout:(XMPPStream *)sender;
10041024

@@ -1009,7 +1029,9 @@ extern const NSTimeInterval XMPPStreamTimeoutNone;
10091029
* Some examples:
10101030
* - The TCP socket was unexpectedly disconnected.
10111031
* - The SRV resolution of the domain failed.
1012-
* - Error parsing xml sent from server.
1032+
* - Error parsing xml sent from server.
1033+
*
1034+
* @see xmppStreamConnectDidTimeout:
10131035
**/
10141036
- (void)xmppStreamDidDisconnect:(XMPPStream *)sender withError:(NSError *)error;
10151037

Core/XMPPStream.m

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@
4141
#define TAG_XMPP_READ_START 100
4242
#define TAG_XMPP_READ_STREAM 101
4343
#define TAG_XMPP_WRITE_START 200
44-
#define TAG_XMPP_WRITE_STREAM 201
45-
#define TAG_XMPP_WRITE_RECEIPT 202
44+
#define TAG_XMPP_WRITE_STOP 201
45+
#define TAG_XMPP_WRITE_STREAM 202
46+
#define TAG_XMPP_WRITE_RECEIPT 203
4647

4748
// Define the timeouts (in seconds) for SRV
4849
#define TIMEOUT_SRV_RESOLUTION 30.0
@@ -1421,7 +1422,7 @@ - (void)disconnectAfterSending
14211422
XMPPLogSend(@"SEND: %@", termStr);
14221423
numberOfBytesSent += [termData length];
14231424

1424-
[asyncSocket writeData:termData withTimeout:TIMEOUT_XMPP_WRITE tag:TAG_XMPP_WRITE_STREAM];
1425+
[asyncSocket writeData:termData withTimeout:TIMEOUT_XMPP_WRITE tag:TAG_XMPP_WRITE_STOP];
14251426
[asyncSocket disconnectAfterWriting];
14261427

14271428
// Everthing will be handled in socketDidDisconnect:withError:
@@ -3970,6 +3971,10 @@ - (void)socket:(GCDAsyncSocket *)sock didWriteDataWithTag:(long)tag
39703971
[receipt signalSuccess];
39713972
[receipts removeObjectAtIndex:0];
39723973
}
3974+
else if (tag == TAG_XMPP_WRITE_STOP)
3975+
{
3976+
[multicastDelegate xmppStreamDidSendClosingStreamStanza:self];
3977+
}
39733978
}
39743979

39753980
/**

0 commit comments

Comments
 (0)