Skip to content

Commit

Permalink
Add a bit of debug info in Connection pinging
Browse files Browse the repository at this point in the history
  • Loading branch information
dmoagx committed Mar 9, 2017
1 parent dd2e34f commit 6c3ab14
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Expand Up @@ -34,6 +34,7 @@ typedef struct {
MYSQL *mySQLConnection;
volatile BOOL *keepAlivePingThreadActivePointer;
volatile BOOL *keepAliveLastPingSuccessPointer;
void *parentId;
} SPMySQLConnectionPingDetails;

@interface SPMySQLConnection (Ping_and_KeepAlive)
Expand Down
Expand Up @@ -33,6 +33,7 @@
#import "SPMySQL Private APIs.h"
#import "Locking.h"
#import <pthread.h>
#include <stdio.h>

@implementation SPMySQLConnection (Ping_and_KeepAlive)

Expand Down Expand Up @@ -85,7 +86,7 @@ - (void)_threadedKeepAlive
}

keepAliveThread = [NSThread currentThread];
[keepAliveThread setName:@"SPMySQL connection keepalive monitor thread"];
[keepAliveThread setName:[NSString stringWithFormat:@"SPMySQL connection keepalive monitor thread (id=%p)", self]];

// If the maximum number of ping failures has been reached, determine whether to reconnect.
if (keepAliveLastPingBlocked || keepAlivePingFailures >= 3) {
Expand Down Expand Up @@ -158,6 +159,7 @@ - (BOOL)_pingConnectionUsingLoopDelay:(NSUInteger)loopDelay
pingDetails->mySQLConnection = mySQLConnection;
pingDetails->keepAliveLastPingSuccessPointer = &keepAliveLastPingSuccess;
pingDetails->keepAlivePingThreadActivePointer = &keepAlivePingThreadActive;
pingDetails->parentId = self;

// Create a pthread for the ping
pthread_t keepAlivePingThread_t;
Expand Down Expand Up @@ -216,9 +218,11 @@ - (BOOL)_pingConnectionUsingLoopDelay:(NSUInteger)loopDelay
*/
void _backgroundPingTask(void *ptr)
{
pthread_setname_np("SPMySQL _backgroundPingTask() worker thread");

SPMySQLConnectionPingDetails *pingDetails = (SPMySQLConnectionPingDetails *)ptr;

char threadNameBuf[80];
snprintf(threadNameBuf, sizeof(threadNameBuf), "SPMySQL _backgroundPingTask() worker thread (id=%p)", pingDetails->parentId);
pthread_setname_np(threadNameBuf);

// Set up a cleanup routine
pthread_cleanup_push(_pingThreadCleanup, pingDetails);
Expand Down

0 comments on commit 6c3ab14

Please sign in to comment.