Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #28838
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!news-out.readnews.com!transit4.readnews.com!panix!not-for-mail |
|---|---|
| From | Grant Edwards <invalid@invalid.invalid> |
| Newsgroups | comp.lang.python |
| Subject | Re: How to timeout a recv() on an ssl connection? |
| Date | Mon, 10 Sep 2012 17:37:37 +0000 (UTC) |
| Organization | PANIX Public Access Internet and UNIX, NYC |
| Lines | 36 |
| Message-ID | <k2l8h1$b47$1@reader1.panix.com> (permalink) |
| References | <k2l7jg$ja0$1@reader1.panix.com> |
| NNTP-Posting-Host | dsl.comtrol.com |
| X-Trace | reader1.panix.com 1347298657 11399 64.122.56.22 (10 Sep 2012 17:37:37 GMT) |
| X-Complaints-To | abuse@panix.com |
| NNTP-Posting-Date | Mon, 10 Sep 2012 17:37:37 +0000 (UTC) |
| User-Agent | slrn/pre1.0.0-18 (Linux) |
| Xref | csiph.com comp.lang.python:28838 |
Show key headers only | View raw
On 2012-09-10, Grant Edwards <invalid@invalid.invalid> wrote:
> I can't figure out how to timeout a recv() on an SSLSocket -- I'm using
> Python 2.6 nad 2.7. Here's what I've got so far (it needs to work on
> either a plain or SSL socket):
>
> s.settimeout(timeout)
> try:
> b = ord(s.recv(1))
> except socket.timeout:
> return None
> except ssl.SSLError as e:
> if e.message == 'The read operation timed out':
> return None
> else:
> raise
> finally:
> s.settimeout(None)
>
>
> It works fine on normal sockets. With an SSLSocket, it works the
> first time it's called with timeout set to something other than None
> (it times out properly). Subsequence reads with timeout set to None
> work, but then the second time it's called with a non-None timeout, it
> hangs for several minutes, and then the recv() returns an empty
> string.
Doh! Never mind.
The above code does appear to be working correctly. I had a different
bug that was misleading me...
--
Grant Edwards grant.b.edwards Yow! What GOOD is a
at CARDBOARD suitcase ANYWAY?
gmail.com
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
How to timeout a recv() on an ssl connection? Grant Edwards <invalid@invalid.invalid> - 2012-09-10 17:21 +0000 Re: How to timeout a recv() on an ssl connection? Grant Edwards <invalid@invalid.invalid> - 2012-09-10 17:37 +0000
csiph-web