Skip to content

Commit

Permalink
Testing simple mutex protection on ssl
Browse files Browse the repository at this point in the history
  • Loading branch information
lukes3315 committed Dec 14, 2023
1 parent aa73292 commit 234bd2b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
20 changes: 13 additions & 7 deletions c/src/point_one/polaris/polaris.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,10 @@ void Polaris_Disconnect(PolarisContext_t* context) {
P1_DebugPrint("Closing Polaris connection.\n");
context->disconnected = 1;
#ifdef POLARIS_USE_TLS
SSL_shutdown(context->ssl);
if (pthread_mutex_init(&context->ssl_mutex, NULL) != NULL){
SSL_shutdown(context->ssl);
pthread_mutex_destroy(&context->ssl_mutex);
}
#endif
shutdown(context->socket, SHUT_RDWR);
// Note: We intentionally close the socket here but do _not_ destroy the SSL
Expand Down Expand Up @@ -882,13 +885,16 @@ static int OpenSocket(PolarisContext_t* context, const char* endpoint_url,
void CloseSocket(PolarisContext_t* context, int destroy_context) {
#ifdef POLARIS_USE_TLS
if (destroy_context && context->ssl != NULL) {
if (SSL_get_shutdown(context->ssl) == 0) {
SSL_shutdown(context->ssl);
if (pthread_mutex_init(&context->ssl_mutex, NULL) != NULL){
if (SSL_get_shutdown(context->ssl) == 0) {
SSL_shutdown(context->ssl);
}
SSL_free(context->ssl);
}
context->ssl = NULL;
pthread_mutex_destroy(&context->ssl_mutex);
}
}

SSL_free(context->ssl);
context->ssl = NULL;
}
#endif

if (context->socket != P1_INVALID_SOCKET) {
Expand Down
1 change: 1 addition & 0 deletions c/src/point_one/polaris/polaris.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ struct PolarisContext_s {
// header file.
void* ssl_ctx;
void* ssl;
pthread_mutex_t context_lock;
};

#ifdef __cplusplus
Expand Down

0 comments on commit 234bd2b

Please sign in to comment.