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

Commit 0957aa0

Browse files
committed
Expose underlying socket errors from openssl calls
1 parent 5c96066 commit 0957aa0

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

seabolt/src/bolt/connections.c

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ enum BoltConnectionError _transform_error(int error_code)
9898
case WSAENETRESET:
9999
case WSAENETDOWN:
100100
return BOLT_NETWORK_UNREACHABLE;
101+
case WSAEWOULDBLOCK:
101102
case WSAETIMEDOUT:
102103
return BOLT_TIMED_OUT;
103104
default:
@@ -118,8 +119,6 @@ enum BoltConnectionError _transform_error(int error_code)
118119
case ENOBUFS:
119120
case ENOMEM:
120121
return BOLT_OUT_OF_MEMORY;
121-
case EAGAIN:
122-
return BOLT_OUT_OF_PORTS;
123122
case ECONNREFUSED:
124123
return BOLT_CONNECTION_REFUSED;
125124
case ECONNRESET:
@@ -128,6 +127,7 @@ enum BoltConnectionError _transform_error(int error_code)
128127
return BOLT_INTERRUPTED;
129128
case ENETUNREACH:
130129
return BOLT_NETWORK_UNREACHABLE;
130+
case EAGAIN:
131131
case ETIMEDOUT:
132132
return BOLT_TIMED_OUT;
133133
default:
@@ -152,6 +152,22 @@ enum BoltConnectionError _last_error(struct BoltConnection* connection)
152152
return _transform_error(error_code);
153153
}
154154

155+
enum BoltConnectionError _last_error_ssl(struct BoltConnection* connection, int ret)
156+
{
157+
int ssl_error_code = SSL_get_error(connection->ssl, ret);
158+
BoltLog_error(connection->log, "ssl error code: %d", ssl_error_code);
159+
switch (ssl_error_code) {
160+
case SSL_ERROR_NONE:
161+
return BOLT_SUCCESS;
162+
case SSL_ERROR_SYSCALL:
163+
case SSL_ERROR_WANT_READ:
164+
case SSL_ERROR_WANT_WRITE:
165+
return _last_error(connection);
166+
default:
167+
return BOLT_TLS_ERROR;
168+
}
169+
}
170+
155171
void _set_status(struct BoltConnection* connection, enum BoltConnectionStatus status, enum BoltConnectionError error)
156172
{
157173
enum BoltConnectionStatus old_status = connection->status;
@@ -291,9 +307,9 @@ int _open(struct BoltConnection* connection, enum BoltTransport transport, const
291307
int error_code = _last_error_code(connection);
292308
switch (error_code) {
293309
#if USE_WINSOCK
294-
case WSAEWOULDBLOCK: {
295-
break;
296-
}
310+
case WSAEWOULDBLOCK: {
311+
break;
312+
}
297313
#else
298314
case EINPROGRESS: {
299315
break;
@@ -481,7 +497,7 @@ int _send(struct BoltConnection* connection, const char* data, int size)
481497
BoltLog_error(connection->log, "Socket error %d on transmit", connection->error);
482498
break;
483499
case BOLT_SECURE_SOCKET:
484-
_set_status(connection, BOLT_DEFUNCT, SSL_get_error(connection->ssl, sent));
500+
_set_status(connection, BOLT_DEFUNCT, _last_error_ssl(connection, sent));
485501
BoltLog_error(connection->log, "SSL error %d on transmit", connection->error);
486502
break;
487503
}
@@ -535,7 +551,7 @@ int _receive(struct BoltConnection* connection, char* buffer, int min_size, int
535551
BoltLog_error(connection->log, "Socket error %d on receive", connection->error);
536552
break;
537553
case BOLT_SECURE_SOCKET:
538-
_set_status(connection, BOLT_DEFUNCT, SSL_get_error(connection->ssl, single_received));
554+
_set_status(connection, BOLT_DEFUNCT, _last_error_ssl(connection, single_received));
539555
BoltLog_error(connection->log, "SSL error %d on receive", connection->error);
540556
break;
541557
}

seabolt/src/bolt/pool/direct-pool.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ int find_unused_connection(struct BoltDirectPool* pool)
7373

7474
int find_connection(struct BoltDirectPool* pool, struct BoltConnection* connection)
7575
{
76-
for (size_t i = 0; i<pool->size; i++) {
76+
for (int i = 0; i<pool->size; i++) {
7777
struct BoltConnection* candidate = &pool->connections[i];
7878
if (candidate==connection) {
79-
return (int) i;
79+
return i;
8080
}
8181
}
8282
return -1;
@@ -189,8 +189,8 @@ struct BoltDirectPool* BoltDirectPool_create(const struct BoltAddress* address,
189189
void BoltDirectPool_destroy(struct BoltDirectPool* pool)
190190
{
191191
BoltLog_info(pool->config->log, "destroying pool");
192-
for (size_t index = 0; index<pool->size; index++) {
193-
close_pool_entry(pool, (int) index);
192+
for (int index = 0; index<pool->size; index++) {
193+
close_pool_entry(pool, index);
194194
}
195195
BoltMem_deallocate(pool->connections, pool->size*sizeof(struct BoltConnection));
196196
if (pool->ssl_context!=NULL) {
@@ -320,7 +320,7 @@ int BoltDirectPool_release(struct BoltDirectPool* pool, struct BoltConnection* c
320320
int BoltDirectPool_connections_in_use(struct BoltDirectPool* pool)
321321
{
322322
int count = 0;
323-
for (uint32_t i = 0; i<pool->size; i++) {
323+
for (int i = 0; i<pool->size; i++) {
324324
if (pool->connections[i].agent!=NULL) {
325325
count++;
326326
}

0 commit comments

Comments
 (0)