[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Flushing ssh_channel_write() ?
[Thread Prev] | [Thread Next]
- Subject: Re: Flushing ssh_channel_write() ?
- From: Jan Willamowius <jan@xxxxxxxxxxxxxx>
- Reply-to: libssh@xxxxxxxxxx
- Date: Mon, 21 Mar 2011 17:16:46 +0100
- To: libssh@xxxxxxxxxx
Hi Aris,
your method also works nicely. Updated patch attached.
Regards,
Jan
Aris Adamantiadis wrote:
> Hi Jan,
>
> It seems to me your patch has been done in reverse (inversion in the
> diff command ?)
>
> In my opinion, the flushing stuff should not bypass the ssh_poll loop.
> It should look like this:
>
> while(buffer_get_rest_len(s->out_buffer) && session->alive){
> ssh_handle_packets();
> }
>
> Aris
>
> Le 21/03/11 14:02, Jan Willamowius a écrit :
> > Hi,
> >
> > I would like to propose to add a new function to the API, so an
> > application can ensure its data gets sent:
> > int ssh_blocking_flush(ssh_session session)
> >
> > Please see the attached patch.
> >
> > It would be great if this could be included in the upcoming 0.5
> > release. I know its late in the cycle, but since it only adds a
> > function, it can't break any existing code.
> >
> > Regards,
> > Jan
> >
> >
> > Jan Willamowius wrote:
> >> Hi,
> >>
> >> while implementing my ssh server (with a 0.5 snapshot), I noticed that
> >> data sent to the client with ssh_channel_write() doesn't seem to be sent
> >> out immediately. Sometimes it only appears in the client when the client
> >> presses another key.
> >>
> >> Is there a way to flush the data written with ssh_ channel_write() to
> >> make sure it gets sent ?
> >>
> >> samplesshd doesn't have this issue, but my server doesn't enter
> >> ssh_channel_read immediately after ssh_channel_write(). It only
> >> does so when the client socket has new data to be read.
> >>
> >> Thanks,
> >> Jan
> >>
> >> --
> >> Jan Willamowius, jan@xxxxxxxxxxxxxx, http://www.gnugk.org/
> >
>
>
>
--
Jan Willamowius, jan@xxxxxxxxxxxxxx, http://www.gnugk.org/
--- ../orig/include/libssh/libssh.h 2011-03-09 18:33:49.000000000 +0100
+++ include/libssh/libssh.h 2011-03-21 13:45:16.000000000 +0100
@@ -386,6 +386,7 @@
LIBSSH_API int ssh_get_status(ssh_session session);
LIBSSH_API int ssh_init(void);
LIBSSH_API int ssh_is_blocking(ssh_session session);
+LIBSSH_API int ssh_blocking_flush(ssh_session session);
LIBSSH_API int ssh_is_connected(ssh_session session);
LIBSSH_API int ssh_is_server_known(ssh_session session);
LIBSSH_API void ssh_log(ssh_session session, int prioriry, const char *format, ...) PRINTF_ATTRIBUTE(3, 4);
--- ../orig/src/socket.c 2011-03-09 18:33:49.000000000 +0100
+++ src/socket.c 2011-03-21 17:13:37.000000000 +0100
@@ -564,6 +564,34 @@
return SSH_OK;
}
+/**
+ * \brief possibly blocking flush of the output buffer
+ *
+ */
+int ssh_blocking_flush(ssh_session session) {
+ ssh_socket s = session->socket;
+
+ enter_function();
+
+ if (!ssh_socket_is_open(s)) {
+ session->alive = 0;
+ /* FIXME use ssh_socket_get_errno */
+ ssh_set_error(session, SSH_FATAL,
+ "Writing packet: error on socket (or connection closed): %s",
+ strerror(s->last_errno));
+
+ leave_function();
+ return SSH_ERROR;
+ }
+
+ while (buffer_get_rest_len(s->out_buffer) && session->alive) {
+ ssh_handle_packets(session, -1);
+ }
+
+ leave_function();
+ return SSH_OK;
+}
+
/** \internal
* \brief starts a nonblocking flush of the output buffer
| Re: Flushing ssh_channel_write() ? | Jan Willamowius <jan@xxxxxxxxxxxxxx> |
| Re: Flushing ssh_channel_write() ? | Aris Adamantiadis <aris@xxxxxxxxxxxx> |