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

ReadHint in the readable callback of Handler #4

Closed
wycats opened this issue Sep 8, 2014 · 1 comment
Closed

ReadHint in the readable callback of Handler #4

wycats opened this issue Sep 8, 2014 · 1 comment

Comments

@wycats
Copy link
Contributor

wycats commented Sep 8, 2014

In #3, @rrichardson suggested that it would be useful for handlers to know when the remote side of a socket hangs up.

The epoll backend can support this via the EPOLLHUP and EPOLLRDHUP, but other backends do not expose this directly (and instead require the user to attempt to read from the fd to discover that the other side hung up). If this information is directly available, it can be useful as an optimization, even in portable code.

Since we want mio to make it easy to write portable code, it would be better not to expose this as an additional callback on Handler. If we did that, people who wanted to write portable code would have to write duplicate code in backend-specific handlers.

Instead, I suggest that we add a new parameter to the readable callback that provides backend-specific information if it's available. Since its goal is to make it easy to optimize portable code, in general, and cannot be generally relied on, I suggest calling an enum called ReadableHint.

enum ReadableHint {
    Data, // data is available
    Hup, // the other side of the socket hung up
    Error, // there was an error
    Unknown // the backend does not provide the hint
}
@wycats
Copy link
Contributor Author

wycats commented Sep 8, 2014

Just as a follow-up, I expect three usage patterns:

  • The totally portable consumer, which will just ignore the hint totally. It will discover a hangup in a portable way, by reading and getting 0. This consumer will ignore the hint.
  • The totally OS-specific consumer, which will expect a certain hint to be present if it is available. This consumer will expect one of the non-Unknown hints to be present (and fail if the value is Unknown).
  • The optimizing portable consumer, which will use the hint if it's present, but do the portable behavior if the hint is Unknown.

wycats added a commit that referenced this issue Sep 8, 2014
Closes #4.

We will also need to move IoError to a hint, since it's not supported by
all backends.
wycats added a commit that referenced this issue Sep 9, 2014
Closes #4.

We will also need to move IoError to a hint, since it's not supported by
all backends.
wycats added a commit that referenced this issue Sep 9, 2014
Closes #4.

We will also need to move IoError to a hint, since it's not supported by
all backends.
@carllerche carllerche added this to the 0.3.0 - Annouce milestone Sep 22, 2014
wycats added a commit that referenced this issue Oct 4, 2014
This implements the first part of the strategy outlined in #4.

It updates the tests to take the read hint in the handlers, and
specifically confirm that they get the DataHint first and then the
HupHint.

I believe that the hints are implementable on all of the backends we
intend to support, so I consider it a bug if those tests don't pass on a
supported platform.

Note that this information is called a "hint" because you still need to
handle errors in your read handler, but this may allow you to skip the
extra `read` syscall as an optimization.
wycats added a commit that referenced this issue Oct 6, 2014
This implements the first part of the strategy outlined in #4.

Closes #4.

It updates the tests to take the read hint in the handlers, and
specifically confirm that they get the DataHint first and then the
HupHint.

I believe that the hints are implementable on all of the backends we
intend to support, so I consider it a bug if those tests don't pass on a
supported platform.

Note that this information is called a "hint" because you still need to
handle errors in your read handler, but this may allow you to skip the
extra `read` syscall as an optimization.
@wycats wycats closed this as completed in 9a072b2 Oct 6, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants