I have a TCP networking library which implements a bunch of protocol (redis, http etc), and they are implemented using BSD sockets.
A lot of the code uses select() and other functions that are meant for BSD sockets. Am I right in assuming that this won’t work on the SSL sockets? Or will they work as is?
I’m just wondering if SSL and BSD sockets are so different that they require a completely different approach to implementation.
Assuming you are referring to OpenSSL, it sits on top of the socket, it does not replace it. So all direct-socket operations, like
select(), still work. The difference, however, is that OpenSSL handles reading and writing for you so you would replacerecv()withssl_read()andsend()withssl_write(), but you can (and in some cases need to) still useselect()directly. However, you can’t just call it whenever you want, you have to wait until OpenSSL tells you to call it. So, for example, if you have a reading loop that callsselect()first and then callsrecv()only whenselect()reports readability, you would have to swap that logic around. Callssl_read()first, and then callselect() only ifssl_read()returns eitherSSL_ERROR_WANT_READorSSL_ERROR_WANT_WRITE(note thatssl_read()can perform writing operations internally, andssl_write()can perform reading operations internally).