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 sockfd = 0;
|
||||
struct sockaddr_in servAddr;
|
||||
const char* host = argv[1];
|
||||
WOLFSSL* ssl = 0;
|
||||
WOLFSSL_CTX* ctx = 0;
|
||||
WOLFSSL* sslResume = 0;
|
||||
WOLFSSL_SESSION* session = 0;
|
||||
char cert_array[] = "../certs/ca-cert.pem";
|
||||
char* certs = cert_array;
|
||||
char* srTest = "testing session resume";
|
||||
int sockfd = 0;
|
||||
struct sockaddr_in servAddr;
|
||||
const char* host = argv[1];
|
||||
WOLFSSL* ssl = 0;
|
||||
WOLFSSL_CTX* ctx = 0;
|
||||
WOLFSSL* sslResume = 0;
|
||||
WOLFSSL_SESSION* session = 0;
|
||||
char cert_array[] = "../certs/ca-cert.pem";
|
||||
char* certs = cert_array;
|
||||
char* srTest = "testing session resume";
|
||||
|
||||
if (argc != 2) {
|
||||
printf("usage: udpcli <IP address>\n");
|
||||
|
@ -104,9 +104,9 @@ int main (int argc, char** argv)
|
|||
wolfSSL_set_fd(ssl, sockfd);
|
||||
wolfSSL_set_using_nonblock(ssl, 1);
|
||||
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 error = wolfSSL_get_error(ssl, 0);
|
||||
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 ||
|
||||
error == SSL_ERROR_WANT_WRITE)) {
|
||||
int currTimeout = 1;
|
||||
if (error == SSL_ERROR_WANT_READ) {
|
||||
printf("... client would read block\n");
|
||||
|
||||
/* Variables to reset each iteration */
|
||||
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 {
|
||||
printf("... client would write block\n");
|
||||
else {
|
||||
printf("... client would write block\n");
|
||||
}
|
||||
currTimeout = wolfSSL_dtls_get_current_timeout(ssl);
|
||||
//select_ret = dtls_select(sockfd, currTimeout);
|
||||
fd_set recvfds, errfds;
|
||||
int nfds = nb_sockfd +1;
|
||||
struct timeval timeout = { (currTimeout > 0) ? currTimeout : 0, 0};
|
||||
int result;
|
||||
|
||||
currTimeout = wolfSSL_dtls_get_current_timeout(ssl);
|
||||
|
||||
FD_ZERO(&recvfds);
|
||||
FD_SET(nb_sockfd, &recvfds);
|
||||
|
@ -137,39 +140,43 @@ int main (int argc, char** argv)
|
|||
|
||||
select_ret = TEST_SELECT_FAIL;
|
||||
|
||||
if (result == 0)
|
||||
if (result == 0) {
|
||||
select_ret = TEST_TIMEOUT;
|
||||
}
|
||||
else if (result > 0) {
|
||||
if (FD_ISSET(nb_sockfd, &recvfds)) {
|
||||
select_ret = TEST_RECV_READY;
|
||||
}
|
||||
}
|
||||
else if (FD_ISSET(nb_sockfd, &errfds)) {
|
||||
select_ret = TEST_ERROR_READY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ( select_ret == TEST_RECV_READY) ||
|
||||
(select_ret == TEST_ERROR_READY)) {
|
||||
ret = wolfSSL_connect(ssl);
|
||||
error = wolfSSL_get_error(ssl, 0);
|
||||
}
|
||||
else if (select_ret == TEST_TIMEOUT && !wolfSSL_dtls(ssl)) {
|
||||
error = 2;
|
||||
}
|
||||
else if (select_ret == TEST_TIMEOUT && wolfSSL_dtls(ssl) &&
|
||||
wolfSSL_dtls_got_timeout(ssl) >= 0) {
|
||||
error = 2;
|
||||
}
|
||||
else {
|
||||
error = SSL_FATAL_ERROR;
|
||||
}
|
||||
if ( ( select_ret == TEST_RECV_READY) ||
|
||||
( select_ret == TEST_ERROR_READY)) {
|
||||
ret = wolfSSL_connect(ssl);
|
||||
error = wolfSSL_get_error(ssl, 0);
|
||||
}
|
||||
else if (select_ret == TEST_TIMEOUT && !wolfSSL_dtls(ssl)) {
|
||||
error = 2;
|
||||
}
|
||||
else if (select_ret == TEST_TIMEOUT && wolfSSL_dtls(ssl) &&
|
||||
wolfSSL_dtls_got_timeout(ssl) >= 0) {
|
||||
error = 2;
|
||||
}
|
||||
else {
|
||||
error = SSL_FATAL_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
if (ret != SSL_SUCCESS) {
|
||||
printf("SSL_connect failed with");
|
||||
}
|
||||
|
||||
//DatagramClient(ssl);
|
||||
/* */
|
||||
/*****************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Code for sending datagram to server */
|
||||
int n = 0;
|
||||
char sendLine[MAXLINE], recvLine[MAXLINE - 1];
|
||||
|
||||
|
@ -190,8 +197,11 @@ int main (int argc, char** argv)
|
|||
recvLine[n] = '\0';
|
||||
fputs(recvLine, stdout);
|
||||
}
|
||||
/* */
|
||||
/*****************************************************************************/
|
||||
|
||||
while ( (wolfSSL_write(ssl, srTest, sizeof(srTest))) != sizeof(srTest)) {
|
||||
printf("failed to write");
|
||||
printf("failed to write");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -217,4 +227,4 @@ int main (int argc, char** argv)
|
|||
wolfSSL_Cleanup();
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue