request of "real timeout" in socket.read

  • Thread starter 顺航 游
  • Start date
É

顺航 游

Hi, few days ago I was confused with the behavior of socket.read when
timeout is used -- that the lifespan of the operation often is longer
than the time I've specified. So I go to python.org and get the source
code of python.
Yet I had read some lines of code from the Python-2.7.2/Modules/
socketmodule.c, and I found that the function was implemented in
internal_select by poll or select, this function will block at most a
span of timeout, so whenever it is called, another timeout time has to
be wasted if there's nothing coming.
So what if to change the code like this:
now = time(NULL); //may be other function
if( s->sock_timeout >= now + .5 )
return 1;

timeout = s->sock_timeout + .5 - now;
/*
.... poll or select
*/

here s->sock_timeout is a particular moment rather than a time span,
or:
s->sock_timeout = time(NULL) + timeout;
when init.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top