If you agree with it, i can submit a proper patch <br><br><div class="gmail_quote">On Wed, Apr 13, 2011 at 11:06 AM, Ahmed Omar <span dir="ltr"><<a href="mailto:spawn.think@gmail.com">spawn.think@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Indeed you are correct. I wrote it in a different way, removed the undefined and avoided subtraction if Timeout is 0 <div>
<div>diff --git a/lib/kernel/src/inet_res.erl b/lib/kernel/src/inet_res.erl</div><div>index de0f23b..0ba5969 100644</div><div class="im">
<div>--- a/lib/kernel/src/inet_res.erl</div><div>+++ b/lib/kernel/src/inet_res.erl</div></div><div>@@ -547,15 +547,16 @@ udp_recv(#sock{inet=I}, {A,B,C,D}=IP, Port, Timeout)</div><div> do_udp_recv(fun(T) -> gen_udp:recv(I, 0, T) end, IP, Port, Timeout).</div>
<div> </div><div> do_udp_recv(Recv, IP, Port, Timeout) -></div><div>- do_udp_recv(Recv, IP, Port, Timeout, </div><div>- if Timeout =/= 0 -> erlang:now(); true -> undefined end).</div><div>+ do_udp_recv(Recv, IP, Port, Timeout, erlang:now()). </div>
<div class="im">
<div> </div><div> do_udp_recv(Recv, IP, Port, Timeout, Then) -></div><div> case Recv(Timeout) of</div></div><div>+ {ok,{IP,Port,Answer}} when Timeout =:= 0-></div><div>+ {ok, Answer, Timeout};</div>
<div class="im"><div>
{ok,{IP,Port,Answer}} -></div><div> {ok,Answer,erlang:max(0, Timeout - now_ms(erlang:now(), Then))};</div><div>- {ok,_} when Timeout =:= 0 -></div><div>- {error,timeout};</div></div>
<div>
+ {ok,_} when Timeout =:= 0 -></div><div>+ {error,timeout};</div><div> {ok,_} -></div><div> Now = erlang:now(),</div><div> T = erlang:max(0, Timeout - now_ms(Now, Then)),</div>
<div><div></div><div class="h5">
<div><br></div><br><div class="gmail_quote">On Wed, Apr 13, 2011 at 10:43 AM, Raimo Niskanen <span dir="ltr"><<a href="mailto:raimo%2Berlang-bugs@erix.ericsson.se" target="_blank">raimo+erlang-bugs@erix.ericsson.se</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>On Tue, Apr 12, 2011 at 01:56:26PM +0200, Ahmed Omar wrote:<br>
> Then going back to my original message, the order of case clauses doesn't<br>
> sound right<br>
> {ok,{IP,Port,Answer}} -><br>
> {ok,Answer,erlang:max(0, Timeout - now_ms(erlang:now(), Then))};<br>
> {ok,_} when Timeout =:= 0 -><br>
> {error,timeout};<br>
><br>
><br>
> Cause even when the timeout is 0 now, now_ms/2 will be called with Then =<br>
> undefined<br>
<br>
</div>I will dig into this in a few days, after my current tasks, and will<br>
post a diff when the yet unwritten testcases start working...<br>
<div><div></div><div><br>
><br>
> On Tue, Apr 12, 2011 at 1:51 PM, Raimo Niskanen <<br>
> <a href="mailto:raimo%2Berlang-bugs@erix.ericsson.se" target="_blank">raimo+erlang-bugs@erix.ericsson.se</a>> wrote:<br>
><br>
> > On Tue, Apr 12, 2011 at 01:35:33PM +0200, Raimo Niskanen wrote:<br>
> > > On Tue, Apr 12, 2011 at 01:08:24PM +0200, Ahmed Omar wrote:<br>
> > > > Hmmm, the crash doesn't look to be in subtraction (otherwise it would<br>
> > have<br>
> > > > been badarg?), it's a crash because of a function clause in now_ms<br>
> > (because<br>
> > > > undefined won't match)<br>
> > > > (and undefined looks to be generated only when timeout is 0 )<br>
> > ><br>
> > > Well, I ment _conceptually_ subtract since now_ms/2 is supposed to<br>
> > > return the number of elapsed microseconds i.e subtract<br>
> ><br>
> > Milliseconds. Sorry. That should be milliseconds.<br>
> ><br>
> > > its now() arguments, and now got 'undefined' instead<br>
> > > of {MegaSec,Sec,MicroSec) as second argumnent.<br>
> > ><br>
> > > 'undefined' must be a leftover from an unfinished implementation<br>
> > > of either the case when you have timed out or when the<br>
> > > timeout is 'infinity'. Nevertheless it is incorrect.<br>
> > ><br>
> > > The Timeout variable is how long time still remains to wait of the<br>
> > > initial user interface timeout.<br>
> > ><br>
> > > ><br>
> > > > Maybe I'm missing something or my coffee doesn't work :)<br>
> > > ><br>
> > : :<br>
> > > > Follow me on twitter<br>
> > > > @spawn_think <<a href="http://twitter.com/#!/spawn_think" target="_blank">http://twitter.com/#!/spawn_think</a>><br>
> > ><br>
> > > --<br>
> > ><br>
> > > / Raimo Niskanen, Erlang/OTP, Ericsson AB<br>
> > > _______________________________________________<br>
> > > erlang-bugs mailing list<br>
> > > <a href="mailto:erlang-bugs@erlang.org" target="_blank">erlang-bugs@erlang.org</a><br>
> > > <a href="http://erlang.org/mailman/listinfo/erlang-bugs" target="_blank">http://erlang.org/mailman/listinfo/erlang-bugs</a><br>
> ><br>
> > --<br>
> ><br>
> > / Raimo Niskanen, Erlang/OTP, Ericsson AB<br>
> > _______________________________________________<br>
> > erlang-bugs mailing list<br>
> > <a href="mailto:erlang-bugs@erlang.org" target="_blank">erlang-bugs@erlang.org</a><br>
> > <a href="http://erlang.org/mailman/listinfo/erlang-bugs" target="_blank">http://erlang.org/mailman/listinfo/erlang-bugs</a><br>
> ><br>
><br>
><br>
><br>
> --<br>
> Best Regards,<br>
> - Ahmed Omar<br>
> <a href="http://nl.linkedin.com/in/adiaa" target="_blank">http://nl.linkedin.com/in/adiaa</a><br>
> Follow me on twitter<br>
> @spawn_think <<a href="http://twitter.com/#!/spawn_think" target="_blank">http://twitter.com/#!/spawn_think</a>><br>
<br>
--<br>
<br>
/ Raimo Niskanen, Erlang/OTP, Ericsson AB<br>
_______________________________________________<br>
erlang-bugs mailing list<br>
<a href="mailto:erlang-bugs@erlang.org" target="_blank">erlang-bugs@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-bugs" target="_blank">http://erlang.org/mailman/listinfo/erlang-bugs</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Best Regards,<br>- Ahmed Omar<div><a href="http://nl.linkedin.com/in/adiaa" target="_blank">http://nl.linkedin.com/in/adiaa</a></div><div>Follow me on twitter</div>
<div><a href="http://twitter.com/#!/spawn_think" target="_blank">@spawn_think</a></div><br>
</div></div></div>
</blockquote></div><br><br clear="all"><br>-- <br>Best Regards,<br>- Ahmed Omar<div><a href="http://nl.linkedin.com/in/adiaa" target="_blank">http://nl.linkedin.com/in/adiaa</a></div><div>Follow me on twitter</div><div><a href="http://twitter.com/#!/spawn_think" target="_blank">@spawn_think</a></div>
<br>