Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sock: change "no timeout" value from 0 to UINT32_MAX #5929

Merged
merged 1 commit into from
Oct 12, 2016

Conversation

kaspar030
Copy link
Contributor

IMHO specifying a timeout of "0" for "don't wait at all" makes much more sense.

@kaspar030 kaspar030 added Impact: minor The PR is small in size and might only require a quick look of a knowledgeable reviewer Process: API change Integration Process: PR contains or issue proposes an API change. Should be handled with care. labels Oct 11, 2016
@OlegHahm
Copy link
Member

I must confess to know next to nothing about sock, but this change makes sense to me.

@miri64
Copy link
Member

miri64 commented Oct 12, 2016

What does 0 then do?

@OlegHahm
Copy link
Member

IMHO specifying a timeout of "0" for "don't wait at all" makes much more sense.

@OlegHahm
Copy link
Member

I.e. return immediately - in any case.

@miri64
Copy link
Member

miri64 commented Oct 12, 2016

IMHO specifying a timeout of "0" for "don't wait at all" makes much more sense.

I should read more...

Nevertheless, I still don't think it's a good idea. 0 means to me no timeout at all, not 0 sec timeout. Also, though my assembly is quite rusty, I think if (t == 0) is translated into fewer instructions than if (t < UINT_MAX32).

@miri64
Copy link
Member

miri64 commented Oct 12, 2016

I.e. return immediately - in any case.

I wouldn't know how to implement such a case with stacks where 0 means no timeout... I would set it to one, maybe...

* @ref sys_xtimer module is not present or the
* implementation does not support timeouts on its own.
* May be 0 for no timeout.
* If 0 and no data is available, return immediately.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean "the operation is non-blocking"? "return immediately" sounds more like implementation-speak...

Copy link
Contributor Author

@kaspar030 kaspar030 Oct 12, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, better. I'll change if you approve the change in general. (edit before here was a reply to another comment)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, better

Then this is null and void:

I wouldn't know how to implement such a case with stacks where 0 means no timeout... I would set it to one, maybe...

Then please add the return value -EWOULDBLOCK or -EAGAIN.

I'll change if you approve the change in general.

I still see some implementation confusions, but I guess that is the reviewers job to spot these ;-)

@kaspar030
Copy link
Contributor Author

0 means to me no timeout at all, not 0 sec timeout.

If you read the parameter as "how much time to wait at most until data arrives", "0" meaning "don't wait at all" is quite natural, don't you think?

Also, though my assembly is quite rusty, I think if (t == 0) is translated into fewer instructions than if (t < UINT_MAX32).

You might save one instruction...

@kaspar030
Copy link
Contributor Author

I wouldn't know how to implement such a case with stacks where 0 means no timeout... I would set it to one, maybe...

Just add timeout += 1; at a strategically useful location. ;)

@miri64
Copy link
Member

miri64 commented Oct 12, 2016

Marginally related: do you remember, why we decided against a configurable timeout for sock_accept()? It's basically the receive function of a sock_tcp_queue_t.

@kaspar030
Copy link
Contributor Author

Marginally related: do you remember, why we decided against a configurable timeout for sock_accept()? It's basically the receive function of a sock_tcp_queue_t.

Actually, no, don't even remember discussing it. Seems to be missing.

@miri64
Copy link
Member

miri64 commented Oct 12, 2016

I have a slither of a memory, that Simon brought it up...

@kaspar030
Copy link
Contributor Author

You mean "the operation is non-blocking"? "return immediately" sounds more like implementation-speak...

Actually "the operation is non-blocking" seems less clear to me than "returns immediately". Would that extra s for return change your mind, too?

@miri64
Copy link
Member

miri64 commented Oct 12, 2016

Yes.

* value `> 0`. If an error occurs on receive we just ignore it and continue
* looping.
* value `!= SOCK_NO_TIMEOUT`. If an error occurs on receive we just ignore it
* and continue looping.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder to self: fix this for #5923.

@kaspar030
Copy link
Contributor Author

@miri64 I think I got all your comments?

Copy link
Member

@miri64 miri64 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last wording issue. Other then that I'm fine with this PR.

* @ref sys_xtimer module is not present or the
* implementation does not support timeouts on its own.
* May be 0 for no timeout.
* If 0 and no data is available, returns immediately.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, now I'm seeing this I immediately wonder: "What returns immediately" (the half-sentence is missing a subject ;-)).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so "the function returns immediately." ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

* @ref sys_xtimer module is not present and the
* implementation does not support timeouts on its own.
* May be 0 for no timeout.
* If 0 and no data is available, returns immediately.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dito

* @ref sys_xtimer module is not present or the
* implementation does not support timeouts on its own.
* May be 0 for no timeout.
* If 0 and no data is available, returns immediately.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dito

* alternatively set the `timeout` parameter of @ref sock_udp_recv() to a
* value `> 0`. If an error occurs on receive we just ignore it and continue
* looping.
* The application then waits indefinitely for an incoming message in `buf`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor question: Why did you change the line wrapping here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I usually leave the line wrapping to vim. Mark the paragraph, press "gq", good.

* looping.
* The application then waits indefinitely for an incoming message in `buf`
* from `remote`. If we want to timeout this wait period we could alternatively
* set the `timeout` parameter of @ref sock_udp_recv() to a value != @ref
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer the @ref and SOCK_NO_TIMEOUT to be on the same line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but together with the line change above the line would cross the 80 characters mark...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could put the line change before the @ref or even the value != ;-)

@@ -407,6 +407,7 @@ int sock_ip_get_remote(sock_ip_t *sock, sock_ip_ep_t *ep);
* @return -EPROTO, if source address of received packet did not equal
* the remote of @p sock.
* @return -ETIMEDOUT, if @p timeout expired.
* @return -EAGAIN, if @p timeout is `0` and no data is available.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick-alert: The other return-values are lexicographically ordered ;-)

@@ -207,6 +206,7 @@ int sock_tcp_accept(sock_tcp_queue_t *queue, sock_tcp_t **sock);
* point of @p sock.
* @return -ENOTCONN, when @p sock is not connected to a remote end point.
* @return -ETIMEDOUT, if @p timeout expired.
* @return -EAGAIN, if @p timeout is `0` and no data is available.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick-alert: The other return-values are lexicographically ordered ;-)

@@ -395,6 +394,7 @@ int sock_udp_get_remote(sock_udp_t *sock, sock_udp_ep_t *ep);
* @return -EPROTO, if source address of received packet did not equal
* the remote of @p sock.
* @return -ETIMEDOUT, if @p timeout expired.
* @return -EAGAIN, if @p timeout is `0` and no data is available.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick-alert: The other return-values are lexicographically ordered ;-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:)

* value `> 0`. If an error occurs on receive we just ignore it and continue
* looping.
* value `!= SOCK_NO_TIMEOUT`. If an error occurs on receive we just ignore it
* and continue looping.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait... the code above needs adaption to to be in line with that text.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the snippet directly above too, please.

* alternatively set the `timeout` parameter of @ref sock_udp_recv() to a
* value `> 0`. If an error occurs on receive we just ignore it and continue
* looping.
* The application then waits indefinitely for an incoming message in `buf`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

@miri64
Copy link
Member

miri64 commented Oct 12, 2016

I hope I found everything now ^^"

@kaspar030
Copy link
Contributor Author

I hope I found everything now ^^"

Could we leave the formatting to "fill lines up to 80 chars, wrap before word"?

@miri64
Copy link
Member

miri64 commented Oct 12, 2016

Yapp

Copy link
Member

@miri64 miri64 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You forgot the snippets.

* value `> 0`. If an error occurs on receive we just ignore it and continue
* looping.
* value `!= SOCK_NO_TIMEOUT`. If an error occurs on receive we just ignore it
* and continue looping.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the snippet directly above too, please.

* alternatively set the `timeout` parameter of @ref sock_udp_recv() to a
* value `> 0`. If an error occurs on receive we just ignore it and continue
* looping.
* The application then waits indefinitely for an incoming message in `buf`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

@kaspar030
Copy link
Contributor Author

I don't see what you mean. Could you point me to file and line?

@miri64
Copy link
Member

miri64 commented Oct 12, 2016

I don't see what you mean. Could you point me to file and line?

Oops, sorry. My bad... You already changed it but I was confused due to the diff layout.

Copy link
Member

@miri64 miri64 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK, please squash.

@miri64 miri64 added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable labels Oct 12, 2016
@kaspar030 kaspar030 force-pushed the sock_change_no_timeout_value branch from cb4178c to aace136 Compare October 12, 2016 13:19
@miri64 miri64 added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Oct 12, 2016
@miri64 miri64 merged commit 8c56c90 into RIOT-OS:master Oct 12, 2016
miri64 added a commit to miri64/RIOT that referenced this pull request Oct 12, 2016
@miri64 miri64 added this to the Release 2016.10 milestone Oct 17, 2016
neiljay pushed a commit to neiljay/RIOT that referenced this pull request Nov 4, 2016
@kaspar030 kaspar030 deleted the sock_change_no_timeout_value branch February 7, 2017 22:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Impact: minor The PR is small in size and might only require a quick look of a knowledgeable reviewer Process: API change Integration Process: PR contains or issue proposes an API change. Should be handled with care.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants