Skip to content

Commit 390e1a3

Browse files
committed
wip
1 parent f2568d1 commit 390e1a3

File tree

2 files changed

+56
-13
lines changed

2 files changed

+56
-13
lines changed

c_src/ex_dtls/dtls.c

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,34 +35,46 @@ SSL *create_ssl(SSL_CTX *ssl_ctx, int mode) {
3535
return NULL;
3636
}
3737

38-
BIO *frag_bio = BIO_new(BIO_f_frag());
39-
if (frag_bio == NULL) {
40-
DEBUG("Cannot create frag bio");
41-
return NULL;
42-
}
38+
// BIO *frag_bio = BIO_new(BIO_f_frag());
39+
// if (frag_bio == NULL) {
40+
// DEBUG("Cannot create frag bio");
41+
// return NULL;
42+
// }
4343

44-
BIO *wmem_bio = BIO_new(BIO_s_mem());
45-
if (wmem_bio == NULL) {
46-
DEBUG("Cannot create write mem bio");
47-
return NULL;
48-
}
44+
// BIO *wmem_bio = BIO_new(BIO_s_mem());
45+
// if (wmem_bio == NULL) {
46+
// DEBUG("Cannot create write mem bio");
47+
// return NULL;
48+
// }
4949

50-
BIO *wchain = BIO_push(frag_bio, wmem_bio);
50+
// BIO *wchain = BIO_push(frag_bio, wmem_bio);
5151

5252
BIO *rmem_bio = BIO_new(BIO_s_mem());
5353
if (rmem_bio == NULL) {
5454
DEBUG("Cannot create read mem bio");
5555
return NULL;
5656
}
5757

58-
SSL_set_bio(ssl, rmem_bio, wchain);
58+
BIO *rbio = BIO_new(BIO_s_dgram_mem());
59+
if (rbio == NULL) {
60+
DEBUG("Cannot create read dgram mem bio");
61+
return NULL;
62+
}
63+
64+
BIO *wbio = BIO_new(BIO_s_dgram_mem());
65+
if (wbio == NULL) {
66+
DEBUG("Cannot create write dgram mem bio");
67+
return NULL;
68+
}
69+
70+
// SSL_set_bio(ssl, rmem_bio, wchain);
71+
SSL_set_bio(ssl, rbio, wbio);
5972

6073
// printf("Setting MTU to 1000\n");
6174
// if (SSL_set_mtu(ssl, 1500) == 0) {
6275
// return NULL;
6376
// }
6477

65-
6678
return ssl;
6779
}
6880

c_src/ex_dtls/native.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,19 @@ UNIFEX_TERM handle_handshake_in_progress(State *state, int ret) {
444444
UNIFEX_TERM res_term = handle_data_result_handshake_packets(
445445
state->env, &gen_packets, timeout);
446446
unifex_payload_release(&gen_packets);
447+
448+
ssl_error = SSL_get_error(state->ssl, ret);
449+
switch (ssl_error) {
450+
case SSL_ERROR_WANT_READ:
451+
DEBUG("SSL WANT READ 2");
452+
pending_data_len = BIO_ctrl_pending(SSL_get_wbio(state->ssl));
453+
DEBUG("WBIO: pending data 2: %ld bytes", pending_data_len);
454+
break;
455+
default:
456+
DEBUG("SSL error: %d", ssl_error);
457+
}
458+
459+
447460
return res_term;
448461
} else {
449462
return handle_data_result_handshake_want_read(state->env);
@@ -513,6 +526,24 @@ static int verify_cb(int preverify_ok, X509_STORE_CTX *ctx) {
513526

514527
static int read_pending_data(UnifexPayload *gen_packets, int pending_data_len,
515528
State *state) {
529+
530+
531+
532+
int ssl_error = SSL_get_error(state->ssl, ret);
533+
switch (ssl_error) {
534+
case SSL_ERROR_WANT_READ:
535+
DEBUG("SSL WANT READ");
536+
size_t pending_data_len = BIO_ctrl_pending(SSL_get_wbio(state->ssl));
537+
DEBUG("WBIO: pending data: %ld bytes", pending_data_len);
538+
539+
default:
540+
return handle_read_error(state, ret);
541+
}
542+
543+
544+
545+
546+
516547
char *pending_data = (char *)malloc(pending_data_len * sizeof(char));
517548
memset(pending_data, 0, pending_data_len);
518549
BIO *wbio = SSL_get_wbio(state->ssl);

0 commit comments

Comments
 (0)