Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I assume the problems you're having is the following, you're opening a connection using PyOpenSSL and you always get a WantReadError exception. And you can't distinguish between this error and a timeout. Consider the following example:</p> <pre><code>#!/usr/bin/python import OpenSSL import socket import struct context = OpenSSL.SSL.Context(OpenSSL.SSL.TLSv1_METHOD) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.settimeout(5) connection = OpenSSL.SSL.Connection(context,s) connection.connect(("www.gmail.com",443)) # Put the socket in blocking mode connection.setblocking(1) # Set the timeout using the setsockopt tv = struct.pack('ii', int(6), int(0)) connection.setsockopt(socket.SOL_SOCKET, socket.SO_RCVTIMEO, tv) print "Connected to " , connection.getpeername() print "Sate " , connection.state_string() while True: try: connection.do_handshake() break except OpenSSL.SSL.WantReadError: print "Exception" pass print "Sate " , connection.state_string() print connection.send("koekoek\r\n") while True: try: recvstr = connection.recv(1024) break except OpenSSL.SSL.WantReadError: print "Exception" pass print recvstr </code></pre> <p>This will open an SSL connection to gmail, send an invalid string, read the response and print it. Note that: * the connection is explicitely set to blocking-mode * the recv timeout is explicitely set to in this case 6 seconds.</p> <p>Now what will the behavior be, when the timeout occurs, the WantReadError exception will be thornw, in this case after waiting for 6 seconds. (You can remove the while True to avoid the retry, but in this case i added them for testing). The timeout set on the socket only appears to be effective in the connect() call. </p> <p>An alternative would be when keeping the sockets in non-blocking mode which probably applies for the GNUTLS case as well is to perform the timekeeping yourself, you get the time when you launch the call, and in the while True, try: except WantReadError you perform the check every time yourself to see if you haven't been waiting for too long.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload