<div dir="auto">The way to handle this situation is simply to never enter SSL_read() if there isn't anything to read on the socket.  select() or pselect() are your friends, here, because they'll tell you if there's data to read from the underlying file descriptor.<div dir="auto"><div dir="auto"><div dir="auto"><div dir="auto"><div dir="auto"><div dir="auto"><br></div><div dir="auto">I hope this helps!</div><div dir="auto"><br></div><div dir="auto">-Kyle H</div></div></div></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Oct 5, 2017 02:58, "mahesh gs" <<a href="mailto:mahesh116@gmail.com">mahesh116@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi All,<div><br></div><div>I have query regarding the SSL_read on blocking socket. How to come out of blocking SSL_read when we have to close the connection ?</div><div><br></div><div>As per the documentation SSL_read will only return if there is any data or an error occurred.</div><div><br></div><div> "<span style="color:rgb(0,0,0);font-family:sans-serif;font-size:12.7px">If the underlying BIO is </span><span style="color:rgb(0,0,0);font-family:sans-serif;font-size:12.7px"><b>blocking</b></span><span style="color:rgb(0,0,0);font-family:sans-serif;font-size:12.7px">, SSL_read() will only return, <i><b>once the read operation has been finished or an error occurred</b>,</i> except when a renegotiation take place, in which case a SSL_ERROR_WANT_READ may occur"</span></div><div><br></div><div>I am trying following methods </div><div><br></div><div><b><i>method 1:</i></b></div><div><br></div><div>1) Thread - 1 blocks in SSL_read</div><div>2) Thread - 2 receive indication to stop the connection from application. Call SSL_Shutdown() to unblock the SSL_read in thread - 1. But this is dangerous as calling SSL_shutdown and SSL_read from different threads on same context can lead to undefined behaviour.</div><div><br></div><div><b><i>method 2:</i></b></div><div><b><br></b></div><div>1) Thread - 1 blocks in SSL_read</div><div>2) Thread - 2 receive indication to stop the connection from application. shutdown the underlying TCP socket using system command (shutdown (socket_id, SHUT_WR)) that cause the SSL_read to unblock.</div><div>3) Thread - 1 unwind and close the TCP socket (using close(socket_id)). thread -1 cannot call SSL_Shutdown since the TCP socket is shutdown by thread - 2 for write operation. As per my understanding this violates the TLS standard because of not sending out the close notify handshake.</div><div><br></div><div>How to ensure to come out of blocking SSL_read and initiate SSL_shutdown from same thread?</div><div><br></div><div>Thanks,</div><div>Mahesh G S</div></div>
<br>--<br>
openssl-users mailing list<br>
To unsubscribe: <a href="https://mta.openssl.org/mailman/listinfo/openssl-users" rel="noreferrer" target="_blank">https://mta.openssl.org/<wbr>mailman/listinfo/openssl-users</a><br>
<br></blockquote></div></div>