moved and renamed the CBIO error codes so they are publically available

This commit is contained in:
John Safranek 2013-04-16 12:32:55 -07:00
parent d279695314
commit fe13b4b6c6
4 changed files with 48 additions and 48 deletions

View File

@ -1791,18 +1791,6 @@ enum AlertDescription {
};
/* I/O Callback default errors */
enum IOerrors {
IO_ERR_GENERAL = -1, /* general unexpected err, not in below group */
IO_ERR_WANT_READ = -2, /* need to call read again */
IO_ERR_WANT_WRITE = -2, /* need to call write again */
IO_ERR_CONN_RST = -3, /* connection reset */
IO_ERR_ISR = -4, /* interrupt */
IO_ERR_CONN_CLOSE = -5, /* connection closed or epipe */
IO_ERR_TIMEOUT = -6 /* socket timeout */
};
enum AlertLevel {
alert_warning = 1,
alert_fatal = 2

View File

@ -829,6 +829,18 @@ CYASSL_API void CyaSSL_SetIOOcspRespFree(CYASSL_CTX *ocsp,
CYASSL_API void CyaSSL_SetIOOcspCtx(CYASSL_CTX *ocsp, void *octx);
#endif
/* I/O Callback default errors */
enum IOerrors {
CYASSL_CBIO_ERR_GENERAL = -1, /* general unexpected err */
CYASSL_CBIO_ERR_WANT_READ = -2, /* need to call read again */
CYASSL_CBIO_ERR_WANT_WRITE = -2, /* need to call write again */
CYASSL_CBIO_ERR_CONN_RST = -3, /* connection reset */
CYASSL_CBIO_ERR_ISR = -4, /* interrupt */
CYASSL_CBIO_ERR_CONN_CLOSE = -5, /* connection closed or epipe */
CYASSL_CBIO_ERR_TIMEOUT = -6 /* socket timeout */
};
/* CA cache callbacks */
enum {
CYASSL_SSLV3 = 0,

View File

@ -2245,13 +2245,13 @@ retry:
recvd = ssl->ctx->CBIORecv(ssl, (char *)buf, (int)sz, ssl->IOCB_ReadCtx);
if (recvd < 0)
switch (recvd) {
case IO_ERR_GENERAL: /* general/unknown error */
case CYASSL_CBIO_ERR_GENERAL: /* general/unknown error */
return -1;
case IO_ERR_WANT_READ: /* want read, would block */
case CYASSL_CBIO_ERR_WANT_READ: /* want read, would block */
return WANT_READ;
case IO_ERR_CONN_RST: /* connection reset */
case CYASSL_CBIO_ERR_CONN_RST: /* connection reset */
#ifdef USE_WINDOWS_API
if (ssl->options.dtls) {
goto retry;
@ -2260,7 +2260,7 @@ retry:
ssl->options.connReset = 1;
return -1;
case IO_ERR_ISR: /* interrupt */
case CYASSL_CBIO_ERR_ISR: /* interrupt */
/* see if we got our timeout */
#ifdef CYASSL_CALLBACKS
if (ssl->toInfoOn) {
@ -2277,11 +2277,11 @@ retry:
#endif
goto retry;
case IO_ERR_CONN_CLOSE: /* peer closed connection */
case CYASSL_CBIO_ERR_CONN_CLOSE: /* peer closed connection */
ssl->options.isClosed = 1;
return -1;
case IO_ERR_TIMEOUT:
case CYASSL_CBIO_ERR_TIMEOUT:
#ifdef CYASSL_DTLS
if (DtlsPoolTimeout(ssl) == 0 && DtlsPoolSend(ssl) == 0)
goto retry;
@ -2353,14 +2353,14 @@ int SendBuffered(CYASSL* ssl)
if (sent < 0) {
switch (sent) {
case IO_ERR_WANT_WRITE: /* would block */
case CYASSL_CBIO_ERR_WANT_WRITE: /* would block */
return WANT_WRITE;
case IO_ERR_CONN_RST: /* connection reset */
case CYASSL_CBIO_ERR_CONN_RST: /* connection reset */
ssl->options.connReset = 1;
break;
case IO_ERR_ISR: /* interrupt */
case CYASSL_CBIO_ERR_ISR: /* interrupt */
/* see if we got our timeout */
#ifdef CYASSL_CALLBACKS
if (ssl->toInfoOn) {
@ -2377,8 +2377,8 @@ int SendBuffered(CYASSL* ssl)
#endif
continue;
case IO_ERR_CONN_CLOSE: /* epipe / conn closed, same as reset */
ssl->options.connReset = 1;
case CYASSL_CBIO_ERR_CONN_CLOSE: /* epipe / conn closed */
ssl->options.connReset = 1; /* treat same as reset */
break;
default:

View File

@ -217,37 +217,37 @@ int EmbedReceive(CYASSL *ssl, char *buf, int sz, void *ctx)
if (err == SOCKET_EWOULDBLOCK || err == SOCKET_EAGAIN) {
if (!CyaSSL_dtls(ssl) || CyaSSL_get_using_nonblock(ssl)) {
CYASSL_MSG(" Would block");
return IO_ERR_WANT_READ;
return CYASSL_CBIO_ERR_WANT_READ;
}
else {
CYASSL_MSG(" Socket timeout");
return IO_ERR_TIMEOUT;
return CYASSL_CBIO_ERR_TIMEOUT;
}
}
else if (err == SOCKET_ECONNRESET) {
CYASSL_MSG(" Connection reset");
return IO_ERR_CONN_RST;
return CYASSL_CBIO_ERR_CONN_RST;
}
else if (err == SOCKET_EINTR) {
CYASSL_MSG(" Socket interrupted");
return IO_ERR_ISR;
return CYASSL_CBIO_ERR_ISR;
}
else if (err == SOCKET_ECONNREFUSED) {
CYASSL_MSG(" Connection refused");
return IO_ERR_WANT_READ;
return CYASSL_CBIO_ERR_WANT_READ;
}
else if (err == SOCKET_ECONNABORTED) {
CYASSL_MSG(" Connection aborted");
return IO_ERR_CONN_CLOSE;
return CYASSL_CBIO_ERR_CONN_CLOSE;
}
else {
CYASSL_MSG(" General error");
return IO_ERR_GENERAL;
return CYASSL_CBIO_ERR_GENERAL;
}
}
else if (recvd == 0) {
CYASSL_MSG("Embed receive connection closed");
return IO_ERR_CONN_CLOSE;
return CYASSL_CBIO_ERR_CONN_CLOSE;
}
return recvd;
@ -271,23 +271,23 @@ int EmbedSend(CYASSL* ssl, char *buf, int sz, void *ctx)
if (err == SOCKET_EWOULDBLOCK || err == SOCKET_EAGAIN) {
CYASSL_MSG(" Would Block");
return IO_ERR_WANT_WRITE;
return CYASSL_CBIO_ERR_WANT_WRITE;
}
else if (err == SOCKET_ECONNRESET) {
CYASSL_MSG(" Connection reset");
return IO_ERR_CONN_RST;
return CYASSL_CBIO_ERR_CONN_RST;
}
else if (err == SOCKET_EINTR) {
CYASSL_MSG(" Socket interrupted");
return IO_ERR_ISR;
return CYASSL_CBIO_ERR_ISR;
}
else if (err == SOCKET_EPIPE) {
CYASSL_MSG(" Socket EPIPE");
return IO_ERR_CONN_CLOSE;
return CYASSL_CBIO_ERR_CONN_CLOSE;
}
else {
CYASSL_MSG(" General error");
return IO_ERR_GENERAL;
return CYASSL_CBIO_ERR_GENERAL;
}
}
@ -350,28 +350,28 @@ int EmbedReceiveFrom(CYASSL *ssl, char *buf, int sz, void *ctx)
if (err == SOCKET_EWOULDBLOCK || err == SOCKET_EAGAIN) {
if (CyaSSL_get_using_nonblock(ssl)) {
CYASSL_MSG(" Would block");
return IO_ERR_WANT_READ;
return CYASSL_CBIO_ERR_WANT_READ;
}
else {
CYASSL_MSG(" Socket timeout");
return IO_ERR_TIMEOUT;
return CYASSL_CBIO_ERR_TIMEOUT;
}
}
else if (err == SOCKET_ECONNRESET) {
CYASSL_MSG(" Connection reset");
return IO_ERR_CONN_RST;
return CYASSL_CBIO_ERR_CONN_RST;
}
else if (err == SOCKET_EINTR) {
CYASSL_MSG(" Socket interrupted");
return IO_ERR_ISR;
return CYASSL_CBIO_ERR_ISR;
}
else if (err == SOCKET_ECONNREFUSED) {
CYASSL_MSG(" Connection refused");
return IO_ERR_WANT_READ;
return CYASSL_CBIO_ERR_WANT_READ;
}
else {
CYASSL_MSG(" General error");
return IO_ERR_GENERAL;
return CYASSL_CBIO_ERR_GENERAL;
}
}
else {
@ -379,7 +379,7 @@ int EmbedReceiveFrom(CYASSL *ssl, char *buf, int sz, void *ctx)
&& peerSz != (XSOCKLENT)dtlsCtx->peer.sz
&& memcmp(&peer, dtlsCtx->peer.sa, peerSz) != 0) {
CYASSL_MSG(" Ignored packet from invalid peer");
return IO_ERR_WANT_READ;
return CYASSL_CBIO_ERR_WANT_READ;
}
}
@ -408,23 +408,23 @@ int EmbedSendTo(CYASSL* ssl, char *buf, int sz, void *ctx)
if (err == SOCKET_EWOULDBLOCK || err == SOCKET_EAGAIN) {
CYASSL_MSG(" Would Block");
return IO_ERR_WANT_WRITE;
return CYASSL_CBIO_ERR_WANT_WRITE;
}
else if (err == SOCKET_ECONNRESET) {
CYASSL_MSG(" Connection reset");
return IO_ERR_CONN_RST;
return CYASSL_CBIO_ERR_CONN_RST;
}
else if (err == SOCKET_EINTR) {
CYASSL_MSG(" Socket interrupted");
return IO_ERR_ISR;
return CYASSL_CBIO_ERR_ISR;
}
else if (err == SOCKET_EPIPE) {
CYASSL_MSG(" Socket EPIPE");
return IO_ERR_CONN_CLOSE;
return CYASSL_CBIO_ERR_CONN_CLOSE;
}
else {
CYASSL_MSG(" General error");
return IO_ERR_GENERAL;
return CYASSL_CBIO_ERR_GENERAL;
}
}