Topic: Thread safety?
My approach is currently to use, after the initial initialization,
wolfSSL_connect(ssl)
wolfSSL_write(ssl, data, sz)
wolfSSL_read(ssl, data, sz)
Depending on whether or not `wolfSSL_connect(ssl)` already returned SSL_SUCCESS, indicating
the end of the handshake, I either call `wolfSSL_connect(ssl)` OR `wolfSSL_write(ssl, data, sz)`
whenever the socket fs is writable - and I was monitoring the socket for writability of course.
And I either call `wolfSSL_connect(ssl)` OR `wolfSSL_read(ssl, data, sz)` whenever there is
something to read on the socket fd.
One of the problems here is to know when to monitor the fd for writability: we only want to do
that when we have something to write, nl.,
1. Immediately after initialization: this is when the client HELLO message needs to be written.
2. When the last call to `wolfSSL_connect(ssl)` returned WANT_WRITE.
3. When the last call to `wolfSSL_write(ssl, data, sz)` returned WANT_WRITE.
4. When the handshake is finished and I have application data in the plain text buffer that I want to write.
Monitoring the fd for readability is basically always on, as it doesn't hurt.
However, my library (that I'm integrating with wolfssl) is able to read and write the same socket
at the same time, using two different threads (and separate input/output buffers).
So, it can happen that the socket becomes readable or writable while I'm already calling
one the mentioned functions.
In the ideal case, wolfsll would be able to deal with this. Not by blocking(!) but by having reading
and writing totally separated.
But is this the case?
For example, can I call `wolfSSL_write(ssl, data, sz)` and `wolfSSL_read(ssl, data, sz)` at
the same time (with the same ssl) in parallel?
Or, what if I'm calling `wolfSSL_connect(ssl)` from the write thread (because it was in the
state WANT_WRITE) and while doing so I'm receiving a message from the server (could
be anything - an ssl alert - or whatever, we can't rule it out), then what is the right action
to take?
On that note, does wolfSLL handle ssl alerts? How?