Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Bug fix for XMPPStream's keepAlive functionality. Fixes issue #97

  • Loading branch information...
commit 0a3b7f45c1a1a1b2fd4c3feb2a4223d890258e1b 1 parent 9dcc510
@robbiehanson authored
Showing with 10 additions and 10 deletions.
  1. +1 −1  Core/XMPPStream.h
  2. +9 −9 Core/XMPPStream.m
View
2  Core/XMPPStream.h
@@ -71,7 +71,7 @@ typedef enum XMPPStreamErrorCode XMPPStreamErrorCode;
NSTimeInterval keepAliveInterval;
dispatch_source_t keepAliveTimer;
- dispatch_time_t lastSendReceiveTime;
+ NSTimeInterval lastSendReceiveTime;
DDList *registeredModules;
NSMutableDictionary *autoDelegateDict;
View
18 Core/XMPPStream.m
@@ -3194,7 +3194,7 @@ - (void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)t
XMPPLogTrace();
- lastSendReceiveTime = dispatch_time(DISPATCH_TIME_NOW, 0);
+ lastSendReceiveTime = [NSDate timeIntervalSinceReferenceDate];
if (XMPP_LOG_RECV_PRE)
{
@@ -3250,7 +3250,7 @@ - (void)socket:(GCDAsyncSocket *)sock didWriteDataWithTag:(long)tag
XMPPLogTrace();
- lastSendReceiveTime = dispatch_time(DISPATCH_TIME_NOW, 0);
+ lastSendReceiveTime = [NSDate timeIntervalSinceReferenceDate];
if (tag == TAG_XMPP_WRITE_RECEIPT)
{
@@ -3717,11 +3717,11 @@ - (void)setupKeepAliveTimer
// This allows us to maintain a single timer,
// and an acceptable timer resolution (assuming larger keepAliveIntervals).
- NSTimeInterval interval = keepAliveInterval / 4.0;
+ uint64_t interval = ((keepAliveInterval / 4.0) * NSEC_PER_SEC);
- dispatch_time_t tt = dispatch_time(DISPATCH_TIME_NOW, (interval * NSEC_PER_SEC));
+ dispatch_time_t tt = dispatch_time(DISPATCH_TIME_NOW, interval);
- dispatch_source_set_timer(keepAliveTimer, tt, DISPATCH_TIME_FOREVER, 1.0);
+ dispatch_source_set_timer(keepAliveTimer, tt, interval, 1.0);
dispatch_resume(keepAliveTimer);
}
}
@@ -3733,10 +3733,10 @@ - (void)keepAlive
if (state == STATE_XMPP_CONNECTED)
{
- dispatch_time_t now = dispatch_time(DISPATCH_TIME_NOW, 0);
- NSTimeInterval elapsed = ((now - lastSendReceiveTime) / NSEC_PER_SEC);
+ NSTimeInterval now = [NSDate timeIntervalSinceReferenceDate];
+ NSTimeInterval elapsed = (now - lastSendReceiveTime);
- if (elapsed >= keepAliveInterval)
+ if (elapsed < 0 || elapsed >= keepAliveInterval)
{
NSData *outgoingData = [@" " dataUsingEncoding:NSUTF8StringEncoding];
@@ -3751,7 +3751,7 @@ - (void)keepAlive
// In case the TCP socket comes to a crawl with a giant element in the queue,
// which would prevent the socket:didWriteDataWithTag: method from being called for some time.
- lastSendReceiveTime = now;
+ lastSendReceiveTime = [NSDate timeIntervalSinceReferenceDate];
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.