Use select() with mbedtls library

92 Views Asked by At

I am creating a proxy using the mbedtls library.

In the library itself, there are example how to read and write in the ssl socket, using for example mbedtls_ssl_read function. There is also a minimalistic client example, in the file ssl_client1.c.

But I am stuck when I want to "wait for data", for example using a select function.

I tried (but it is wrong), to take the underlying file descriptor inside the mbedtls_net_context and do a select() on it.

The problem now is that if I don't read everything the first time I call mbedtls_ssl_read (that is, I am reading less data than what the ssl socket has received), anyway all the data is read from the underlying socket (so, the select() does not trigger anything because there is no data in the underlying socket anymore), but the data I have not read is somehow "stuck" in the ssl context of mbedtls library. If I force the mbedtls_ssl_read function, I can read the remaining data, so it is not lost. But I don't know that there is more data, because the select() function has not triggered anything.

Well, in conclusion, I would like to have a select function in the mbedtls library, that could check not only the underlying socket, but also the ssl context, and can tell me that I need to call mbedtls_ssl_read again.

I could not find any. Someone could point me to the right function, or give me an example?

0

There are 0 best solutions below