Re: http.e feature
- Posted by jimcbrown (admin) Jul 15, 2016
- 2847 views
In response to posted by eukat on Mar 07, 2014 12:42:51,
Since no one has posted here in 3 days, i thought i'd start a new fight....
In http.e, there exists this code:
object has_data = sock:select(sock, {}, {}, timeout) if (length(has_data[1]) > 2) and equal(has_data[1][2],1) then object data = sock:receive(sock, 0)
It has always bothered me that sock:select is using the timeout, and that http.e isn't task-aware bothers me. These two deficencies mess up the speed and responsiveness of Euphoria. The tiny app news.ex runs much better if those lines are changed as follows:
object has_data = sock:select(sock, {}, {}, 0,0) if (length(has_data[1]) > 2) and not equal(has_data[1][2],1) -- if not readable then task_yield() -- pgm flow then falls to the bottom of while time()... else object data = sock:receive(sock,0)
You are still using a timeout, you just changed it from 15 milliseconds to zero milliseconds. It does make a certain amount of sense to do this so that if a 3rd party library uses a very long timeout in its http request, other tasks aren't held up for unreasonable periods of time. But a bad 3rd party library can do so anyways simply by calling select() directly on a socket. Once multithread support is implemented, this issue (and tasks generally) should become irrelevant.
Also, a timeout of zero will busy loop (using 100% cpu) on single task programs. Ideally, we'd fix the select machine func itself to be task aware and do the right thing depending on the # of tasks, but that's a huge change. Alternatively, we could implement a new builtin - get_num_of_waiting_tasks() or something, then execute_request() could decide if it should wait by yeilding to other tasks or if it should tell select() to wait.
I think this doesn't get most of the error cases. We might try to receive data if there's an error. This is better:
if (length(has_data[1]) > 2) and equal(has_data[1][2],1) then object data = sock:receive(sock,0) ... else -- if not readable task_yield() -- pgm flow then falls to the bottom of while time()...
Responsibility for keeping this code up was taken from me the day after it was handed to me (years ago),
It did not all happen in a single day or two. Your "responsibility" ended after you quit the dev team. If you had never been parted from the dev team (or if you had later rejoined) the "responsibility" (the ability to directly edit this file I guess) would be yours right now.
when someone else completely re-wrote http.e right out from under me,
This happens all the time in FOSS. It happens quite often in commercial software as well.
but i am just letting you know, you are still doing it wrong.
You are doing it wrong as well.