@@ -115,6 +115,7 @@ - (void)commonInit
115
115
116
116
hostPort = 5222 ;
117
117
keepAliveInterval = DEFAULT_KEEPALIVE_INTERVAL;
118
+ keepAliveData = [@" " dataUsingEncoding: NSUTF8StringEncoding];
118
119
119
120
registeredModules = [[DDList alloc ] init ];
120
121
autoDelegateDict = [[NSMutableDictionary alloc ] init ];
@@ -403,20 +404,18 @@ - (XMPPPresence *)myPresence
403
404
404
405
- (NSTimeInterval )keepAliveInterval
405
406
{
407
+ __block NSTimeInterval result = 0.0 ;
408
+
409
+ dispatch_block_t block = ^{
410
+ result = keepAliveInterval;
411
+ };
412
+
406
413
if (dispatch_get_current_queue () == xmppQueue)
407
- {
408
- return keepAliveInterval;
409
- }
414
+ block ();
410
415
else
411
- {
412
- __block NSTimeInterval result;
413
-
414
- dispatch_sync (xmppQueue, ^{
415
- result = keepAliveInterval;
416
- });
417
-
418
- return result;
419
- }
416
+ dispatch_sync (xmppQueue, block);
417
+
418
+ return result;
420
419
}
421
420
422
421
- (void )setKeepAliveInterval : (NSTimeInterval )interval
@@ -440,6 +439,43 @@ - (void)setKeepAliveInterval:(NSTimeInterval)interval
440
439
dispatch_async (xmppQueue, block);
441
440
}
442
441
442
+ - (char )keepAliveWhitespaceCharacter
443
+ {
444
+ __block char keepAliveChar = ' ' ;
445
+
446
+ dispatch_block_t block = ^{
447
+
448
+ NSString *keepAliveString = [[NSString alloc ] initWithData: keepAliveData encoding: NSUTF8StringEncoding];
449
+ if ([keepAliveString length ] > 0 )
450
+ {
451
+ keepAliveChar = (char )[keepAliveString characterAtIndex: 0 ];
452
+ }
453
+ };
454
+
455
+ if (dispatch_get_current_queue () == xmppQueue)
456
+ block ();
457
+ else
458
+ dispatch_sync (xmppQueue, block);
459
+
460
+ return keepAliveChar;
461
+ }
462
+
463
+ - (void )setKeepAliveWhitespaceCharacter : (char )keepAliveChar
464
+ {
465
+ dispatch_block_t block = ^{
466
+
467
+ if (keepAliveChar == ' ' || keepAliveChar == ' \n ' || keepAliveChar == ' \t ' )
468
+ {
469
+ keepAliveData = [[NSString stringWithFormat: @" %c " , keepAliveChar] dataUsingEncoding: NSUTF8StringEncoding];
470
+ }
471
+ };
472
+
473
+ if (dispatch_get_current_queue () == xmppQueue)
474
+ block ();
475
+ else
476
+ dispatch_async (xmppQueue, block);
477
+ }
478
+
443
479
- (UInt64)numberOfBytesSent
444
480
{
445
481
if (dispatch_get_current_queue () == xmppQueue)
@@ -3349,11 +3385,9 @@ - (void)keepAlive
3349
3385
3350
3386
if (elapsed < 0 || elapsed >= keepAliveInterval)
3351
3387
{
3352
- NSData *outgoingData = [@" " dataUsingEncoding: NSUTF8StringEncoding ];
3388
+ numberOfBytesSent + = [keepAliveData length ];
3353
3389
3354
- numberOfBytesSent += [outgoingData length ];
3355
-
3356
- [asyncSocket writeData: outgoingData
3390
+ [asyncSocket writeData: keepAliveData
3357
3391
withTimeout: TIMEOUT_XMPP_WRITE
3358
3392
tag: TAG_XMPP_WRITE_STREAM];
3359
3393
0 commit comments