Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Commit

Permalink
Expose underlying socket errors from openssl calls
Browse files Browse the repository at this point in the history
  • Loading branch information
ali-ince committed Oct 4, 2018
1 parent 5c96066 commit 0957aa0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
30 changes: 23 additions & 7 deletions seabolt/src/bolt/connections.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ enum BoltConnectionError _transform_error(int error_code)
case WSAENETRESET:
case WSAENETDOWN:
return BOLT_NETWORK_UNREACHABLE;
case WSAEWOULDBLOCK:
case WSAETIMEDOUT:
return BOLT_TIMED_OUT;
default:
Expand All @@ -118,8 +119,6 @@ enum BoltConnectionError _transform_error(int error_code)
case ENOBUFS:
case ENOMEM:
return BOLT_OUT_OF_MEMORY;
case EAGAIN:
return BOLT_OUT_OF_PORTS;
case ECONNREFUSED:
return BOLT_CONNECTION_REFUSED;
case ECONNRESET:
Expand All @@ -128,6 +127,7 @@ enum BoltConnectionError _transform_error(int error_code)
return BOLT_INTERRUPTED;
case ENETUNREACH:
return BOLT_NETWORK_UNREACHABLE;
case EAGAIN:
case ETIMEDOUT:
return BOLT_TIMED_OUT;
default:
Expand All @@ -152,6 +152,22 @@ enum BoltConnectionError _last_error(struct BoltConnection* connection)
return _transform_error(error_code);
}

enum BoltConnectionError _last_error_ssl(struct BoltConnection* connection, int ret)
{
int ssl_error_code = SSL_get_error(connection->ssl, ret);
BoltLog_error(connection->log, "ssl error code: %d", ssl_error_code);
switch (ssl_error_code) {
case SSL_ERROR_NONE:
return BOLT_SUCCESS;
case SSL_ERROR_SYSCALL:
case SSL_ERROR_WANT_READ:
case SSL_ERROR_WANT_WRITE:
return _last_error(connection);
default:
return BOLT_TLS_ERROR;
}
}

void _set_status(struct BoltConnection* connection, enum BoltConnectionStatus status, enum BoltConnectionError error)
{
enum BoltConnectionStatus old_status = connection->status;
Expand Down Expand Up @@ -291,9 +307,9 @@ int _open(struct BoltConnection* connection, enum BoltTransport transport, const
int error_code = _last_error_code(connection);
switch (error_code) {
#if USE_WINSOCK
case WSAEWOULDBLOCK: {
break;
}
case WSAEWOULDBLOCK: {
break;
}
#else
case EINPROGRESS: {
break;
Expand Down Expand Up @@ -481,7 +497,7 @@ int _send(struct BoltConnection* connection, const char* data, int size)
BoltLog_error(connection->log, "Socket error %d on transmit", connection->error);
break;
case BOLT_SECURE_SOCKET:
_set_status(connection, BOLT_DEFUNCT, SSL_get_error(connection->ssl, sent));
_set_status(connection, BOLT_DEFUNCT, _last_error_ssl(connection, sent));
BoltLog_error(connection->log, "SSL error %d on transmit", connection->error);
break;
}
Expand Down Expand Up @@ -535,7 +551,7 @@ int _receive(struct BoltConnection* connection, char* buffer, int min_size, int
BoltLog_error(connection->log, "Socket error %d on receive", connection->error);
break;
case BOLT_SECURE_SOCKET:
_set_status(connection, BOLT_DEFUNCT, SSL_get_error(connection->ssl, single_received));
_set_status(connection, BOLT_DEFUNCT, _last_error_ssl(connection, single_received));
BoltLog_error(connection->log, "SSL error %d on receive", connection->error);
break;
}
Expand Down
10 changes: 5 additions & 5 deletions seabolt/src/bolt/pool/direct-pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ int find_unused_connection(struct BoltDirectPool* pool)

int find_connection(struct BoltDirectPool* pool, struct BoltConnection* connection)
{
for (size_t i = 0; i<pool->size; i++) {
for (int i = 0; i<pool->size; i++) {
struct BoltConnection* candidate = &pool->connections[i];
if (candidate==connection) {
return (int) i;
return i;
}
}
return -1;
Expand Down Expand Up @@ -189,8 +189,8 @@ struct BoltDirectPool* BoltDirectPool_create(const struct BoltAddress* address,
void BoltDirectPool_destroy(struct BoltDirectPool* pool)
{
BoltLog_info(pool->config->log, "destroying pool");
for (size_t index = 0; index<pool->size; index++) {
close_pool_entry(pool, (int) index);
for (int index = 0; index<pool->size; index++) {
close_pool_entry(pool, index);
}
BoltMem_deallocate(pool->connections, pool->size*sizeof(struct BoltConnection));
if (pool->ssl_context!=NULL) {
Expand Down Expand Up @@ -320,7 +320,7 @@ int BoltDirectPool_release(struct BoltDirectPool* pool, struct BoltConnection* c
int BoltDirectPool_connections_in_use(struct BoltDirectPool* pool)
{
int count = 0;
for (uint32_t i = 0; i<pool->size; i++) {
for (int i = 0; i<pool->size; i++) {
if (pool->connections[i].agent!=NULL) {
count++;
}
Expand Down

0 comments on commit 0957aa0

Please sign in to comment.