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

No apparent way to read both main channel and error channel #22

Closed
d3zd3z opened this issue Sep 4, 2015 · 2 comments
Closed

No apparent way to read both main channel and error channel #22

d3zd3z opened this issue Sep 4, 2015 · 2 comments

Comments

@d3zd3z
Copy link

d3zd3z commented Sep 4, 2015

Aside from setting a short timeout, I don't see any way of reading from multiple channels. Programs will often write to both stdout and stderr, and it'd be nice to be able to capture both. The channel and/or stream aren't Sync so threads can't be used, and there doesn't seem to be any way of blocking on multiple streams in order to multiplex them.

@alexcrichton
Copy link
Owner

Unfortunately it looks like this is actually a limitation of libssh2 itself. These methods in libssh2 aren't synchronized (e.g. no mutexes) so it's not safe to concurrently call the underlying libssh2_channel_read_ex function. I think the way libssh2 expects multiplexing cases like this to be handled is to set the sockets into nonblocking mode and then handle the errors via select. That definitely seems a little painful, but unfortunately I don't think there's much else that can be done in this regard :(.

Perhaps I can investigate a binding via mio using ssh2-rs to provide nonblocking support, but that may be a bit of aways off!

@d3zd3z
Copy link
Author

d3zd3z commented Sep 4, 2015

Thanks, fortunately, I think my use case either prints to stdout or stderr, and the prints to stderr won't overflow any buffers, so I can just read stderr after exhausting stdout.

At least rust made it obvious that it wasn't safe to use the Stream in another thread :-)

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

No branches or pull requests

2 participants