I'm using OpenSSL 1.1.1 to add TLS 1.3 support for a client written in C that has previously communicated with the server over plain TCP. The setup, handshake, cert authentication and communication with the server happens correctly.
The problem comes when I try to close the file descriptor. The TCP code was simply calling close(fd)
. I added SSL_shutdown(ssl)
and SSL_free(ssl)
(where ssl is the SSL object). Now, if I do a close(fd)
, I see 3 TCP RSTs being sent from the client to the server. On the other hand, if I do a shutdown(fd, SHUT_RDWR)
, these RSTs don't occur, probably because the FD is still around. I don't believe these RSTs were happening before the TLS support was added. I understand that shutdown()
only prevents data being sent and doesn't actually destroy the fd. We'd like to prevent that fd leak. I've tried calling shutdown(fd, SHUT_RDWR)
and then calling close(fd)
, but the same thing happens. I've also tried:
1. shutdown(fd, SHUT_RDWR)
2. int res=read(fd, buffer, 4000)
3. // check to make sure res is 0
4. close(fd)
What would be the right way to do this?