Home > Enterprise >  OpenSSL how to prevent ::send() from throwing exception when calling SSL_write()
OpenSSL how to prevent ::send() from throwing exception when calling SSL_write()

Time:01-13

I'm using OpenSSL and calling SSL_write(), which eventually calls ::send(). However, occasionally when there's too much traffic the other side disconnects. Consequently on my next write ::send() throws an exception.

I'd prefer to avoid this and return an error code so I can restart my application.

If I was calling ::send() myself I could pass the flag MSG_NOSIGNAL which causes ::send() to return an error code. However, I don't see such an argument for SSL_write().

Is there anything I can do instead?

CodePudding user response:

... prevent ::send() from throwing exception

You likely mean triggering the signal SIGPIPE, not "throwing exception".

If you want to have full control over the input and output of the SSL stack use your own BIO.

If you want to globally over all sockets get EPIPE returned instead of SIGPIPE triggered simply set the signal handler for SIGPIPE to SIG_IGN. If you want to control SIGPIPE for a single socket you can do this with setsockopt on some systems. See How to prevent SIGPIPEs (or handle them properly).

  • Related