added accessors for CYASSL members for use in send/recv callbacks

This commit is contained in:
John Safranek 2012-09-25 15:51:56 -07:00
parent cd0226924a
commit dfb84dff37
3 changed files with 34 additions and 13 deletions

View File

@ -179,7 +179,8 @@ CYASSL_API CYASSL_CTX* CyaSSL_CTX_new(CYASSL_METHOD*);
CYASSL_API CYASSL* CyaSSL_new(CYASSL_CTX*);
CYASSL_API int CyaSSL_set_fd (CYASSL*, int);
CYASSL_API int CyaSSL_get_fd(const CYASSL*);
CYASSL_API void CyaSSL_using_nonblock(CYASSL*);
CYASSL_API void CyaSSL_set_using_nonblock(CYASSL*, int);
CYASSL_API int CyaSSL_get_using_nonblock(CYASSL*);
CYASSL_API int CyaSSL_connect(CYASSL*); /* please see note at top of README
if you get an error from connect */
CYASSL_API int CyaSSL_write(CYASSL*, const void*, int);
@ -219,6 +220,7 @@ CYASSL_API int CyaSSL_set_cipher_list(CYASSL*, const char*);
/* Nonblocking DTLS helper functions */
CYASSL_API int CyaSSL_dtls_get_current_timeout(CYASSL* ssl);
CYASSL_API int CyaSSL_dtls_got_timeout(CYASSL* ssl);
CYASSL_API int CyaSSL_dtls(CYASSL* ssl);
CYASSL_API int CyaSSL_ERR_GET_REASON(int err);
CYASSL_API char* CyaSSL_ERR_error_string(unsigned long,char*);

View File

@ -144,14 +144,19 @@ int EmbedReceive(CYASSL *ssl, char *buf, int sz, void *ctx)
int sd = *(int*)ctx;
#ifdef CYASSL_DTLS
if (ssl->options.dtls
&& !ssl->options.usingNonblock && ssl->dtls_timeout != 0) {
#ifdef USE_WINDOWS_API
DWORD timeout = ssl->dtls_timeout;
#else
struct timeval timeout = {ssl->dtls_timeout, 0};
#endif
setsockopt(sd, SOL_SOCKET,SO_RCVTIMEO, (char*)&timeout,sizeof(timeout));
{
int dtls_timeout = CyaSSL_dtls_get_current_timeout(ssl);
if (CyaSSL_dtls(ssl)
&& !CyaSSL_get_using_nonblock(ssl)
&& dtls_timeout != 0) {
#ifdef USE_WINDOWS_API
DWORD timeout = dtls_timeout;
#else
struct timeval timeout = {dtls_timeout, 0};
#endif
setsockopt(sd, SOL_SOCKET, SO_RCVTIMEO,
(char*)&timeout, sizeof(timeout));
}
}
#endif
@ -162,7 +167,7 @@ int EmbedReceive(CYASSL *ssl, char *buf, int sz, void *ctx)
CYASSL_MSG("Embed Receive error");
if (err == SOCKET_EWOULDBLOCK || err == SOCKET_EAGAIN) {
if (ssl->options.usingNonblock) {
if (CyaSSL_get_using_nonblock(ssl)) {
CYASSL_MSG(" Would block");
return IO_ERR_WANT_READ;
}

View File

@ -185,10 +185,24 @@ int CyaSSL_get_fd(const CYASSL* ssl)
}
void CyaSSL_using_nonblock(CYASSL* ssl)
void CyaSSL_set_using_nonblock(CYASSL* ssl, int nonblock)
{
CYASSL_ENTER("CyaSSL_using_nonblock");
ssl->options.usingNonblock = 1;
CYASSL_ENTER("CyaSSL_set_using_nonblock");
ssl->options.usingNonblock = (nonblock != 0);
}
int CyaSSL_get_using_nonblock(CYASSL* ssl)
{
CYASSL_ENTER("CyaSSL_get_using_nonblock");
CYASSL_LEAVE("CyaSSL_get_using_nonblock", ssl->options.usingNonblock);
return ssl->options.usingNonblock;
}
int CyaSSL_dtls(CYASSL* ssl)
{
return ssl->options.dtls;
}