Update client-dtls-nonblocking.c
Fixed up the indentation problems & removed the C++ style comments.pull/55/head
parent
54eef3358f
commit
534b89fc1a
|
@ -50,16 +50,16 @@ enum {
|
||||||
|
|
||||||
int main (int argc, char** argv)
|
int main (int argc, char** argv)
|
||||||
{
|
{
|
||||||
int sockfd = 0;
|
int sockfd = 0;
|
||||||
struct sockaddr_in servAddr;
|
struct sockaddr_in servAddr;
|
||||||
const char* host = argv[1];
|
const char* host = argv[1];
|
||||||
WOLFSSL* ssl = 0;
|
WOLFSSL* ssl = 0;
|
||||||
WOLFSSL_CTX* ctx = 0;
|
WOLFSSL_CTX* ctx = 0;
|
||||||
WOLFSSL* sslResume = 0;
|
WOLFSSL* sslResume = 0;
|
||||||
WOLFSSL_SESSION* session = 0;
|
WOLFSSL_SESSION* session = 0;
|
||||||
char cert_array[] = "../certs/ca-cert.pem";
|
char cert_array[] = "../certs/ca-cert.pem";
|
||||||
char* certs = cert_array;
|
char* certs = cert_array;
|
||||||
char* srTest = "testing session resume";
|
char* srTest = "testing session resume";
|
||||||
|
|
||||||
if (argc != 2) {
|
if (argc != 2) {
|
||||||
printf("usage: udpcli <IP address>\n");
|
printf("usage: udpcli <IP address>\n");
|
||||||
|
@ -104,9 +104,9 @@ int main (int argc, char** argv)
|
||||||
wolfSSL_set_fd(ssl, sockfd);
|
wolfSSL_set_fd(ssl, sockfd);
|
||||||
wolfSSL_set_using_nonblock(ssl, 1);
|
wolfSSL_set_using_nonblock(ssl, 1);
|
||||||
fcntl(sockfd, F_SETFL, O_NONBLOCK);
|
fcntl(sockfd, F_SETFL, O_NONBLOCK);
|
||||||
//NonBlockingDTLS_Connect(ssl);
|
|
||||||
|
|
||||||
/********************* NonBlockingDTLS_Connect(ssl) code *********************/
|
/*****************************************************************************/
|
||||||
|
/* Non-blocking code for DTLS connect */
|
||||||
int ret = wolfSSL_connect(ssl);
|
int ret = wolfSSL_connect(ssl);
|
||||||
int error = wolfSSL_get_error(ssl, 0);
|
int error = wolfSSL_get_error(ssl, 0);
|
||||||
int nb_sockfd = (int) wolfSSL_get_fd(ssl);
|
int nb_sockfd = (int) wolfSSL_get_fd(ssl);
|
||||||
|
@ -114,19 +114,22 @@ int main (int argc, char** argv)
|
||||||
|
|
||||||
while (ret != SSL_SUCCESS && (error == SSL_ERROR_WANT_READ ||
|
while (ret != SSL_SUCCESS && (error == SSL_ERROR_WANT_READ ||
|
||||||
error == SSL_ERROR_WANT_WRITE)) {
|
error == SSL_ERROR_WANT_WRITE)) {
|
||||||
int currTimeout = 1;
|
|
||||||
if (error == SSL_ERROR_WANT_READ) {
|
/* Variables to reset each iteration */
|
||||||
printf("... client would read block\n");
|
int currTimeout = 1;
|
||||||
|
int nfds = nb_sockfd +1;
|
||||||
|
int result;
|
||||||
|
fd_set recvfds, errfds;
|
||||||
|
struct timeval timeout = { (currTimeout > 0) ? currTimeout : 0, 0};
|
||||||
|
|
||||||
|
if (error == SSL_ERROR_WANT_READ) {
|
||||||
|
printf("... client would read block\n");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
printf("... client would write block\n");
|
printf("... client would write block\n");
|
||||||
}
|
}
|
||||||
currTimeout = wolfSSL_dtls_get_current_timeout(ssl);
|
|
||||||
//select_ret = dtls_select(sockfd, currTimeout);
|
currTimeout = wolfSSL_dtls_get_current_timeout(ssl);
|
||||||
fd_set recvfds, errfds;
|
|
||||||
int nfds = nb_sockfd +1;
|
|
||||||
struct timeval timeout = { (currTimeout > 0) ? currTimeout : 0, 0};
|
|
||||||
int result;
|
|
||||||
|
|
||||||
FD_ZERO(&recvfds);
|
FD_ZERO(&recvfds);
|
||||||
FD_SET(nb_sockfd, &recvfds);
|
FD_SET(nb_sockfd, &recvfds);
|
||||||
|
@ -137,39 +140,43 @@ int main (int argc, char** argv)
|
||||||
|
|
||||||
select_ret = TEST_SELECT_FAIL;
|
select_ret = TEST_SELECT_FAIL;
|
||||||
|
|
||||||
if (result == 0)
|
if (result == 0) {
|
||||||
select_ret = TEST_TIMEOUT;
|
select_ret = TEST_TIMEOUT;
|
||||||
|
}
|
||||||
else if (result > 0) {
|
else if (result > 0) {
|
||||||
if (FD_ISSET(nb_sockfd, &recvfds)) {
|
if (FD_ISSET(nb_sockfd, &recvfds)) {
|
||||||
select_ret = TEST_RECV_READY;
|
select_ret = TEST_RECV_READY;
|
||||||
}
|
}
|
||||||
else if (FD_ISSET(nb_sockfd, &errfds)) {
|
else if (FD_ISSET(nb_sockfd, &errfds)) {
|
||||||
select_ret = TEST_ERROR_READY;
|
select_ret = TEST_ERROR_READY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ( select_ret == TEST_RECV_READY) ||
|
if ( ( select_ret == TEST_RECV_READY) ||
|
||||||
(select_ret == TEST_ERROR_READY)) {
|
( select_ret == TEST_ERROR_READY)) {
|
||||||
ret = wolfSSL_connect(ssl);
|
ret = wolfSSL_connect(ssl);
|
||||||
error = wolfSSL_get_error(ssl, 0);
|
error = wolfSSL_get_error(ssl, 0);
|
||||||
}
|
}
|
||||||
else if (select_ret == TEST_TIMEOUT && !wolfSSL_dtls(ssl)) {
|
else if (select_ret == TEST_TIMEOUT && !wolfSSL_dtls(ssl)) {
|
||||||
error = 2;
|
error = 2;
|
||||||
}
|
}
|
||||||
else if (select_ret == TEST_TIMEOUT && wolfSSL_dtls(ssl) &&
|
else if (select_ret == TEST_TIMEOUT && wolfSSL_dtls(ssl) &&
|
||||||
wolfSSL_dtls_got_timeout(ssl) >= 0) {
|
wolfSSL_dtls_got_timeout(ssl) >= 0) {
|
||||||
error = 2;
|
error = 2;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
error = SSL_FATAL_ERROR;
|
error = SSL_FATAL_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret != SSL_SUCCESS) {
|
if (ret != SSL_SUCCESS) {
|
||||||
printf("SSL_connect failed with");
|
printf("SSL_connect failed with");
|
||||||
}
|
}
|
||||||
|
/* */
|
||||||
//DatagramClient(ssl);
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Code for sending datagram to server */
|
||||||
int n = 0;
|
int n = 0;
|
||||||
char sendLine[MAXLINE], recvLine[MAXLINE - 1];
|
char sendLine[MAXLINE], recvLine[MAXLINE - 1];
|
||||||
|
|
||||||
|
@ -190,8 +197,11 @@ int main (int argc, char** argv)
|
||||||
recvLine[n] = '\0';
|
recvLine[n] = '\0';
|
||||||
fputs(recvLine, stdout);
|
fputs(recvLine, stdout);
|
||||||
}
|
}
|
||||||
|
/* */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
while ( (wolfSSL_write(ssl, srTest, sizeof(srTest))) != sizeof(srTest)) {
|
while ( (wolfSSL_write(ssl, srTest, sizeof(srTest))) != sizeof(srTest)) {
|
||||||
printf("failed to write");
|
printf("failed to write");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,4 +227,4 @@ int main (int argc, char** argv)
|
||||||
wolfSSL_Cleanup();
|
wolfSSL_Cleanup();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue