diff options
author | Andreas Schneider <mail@cynapses.org> | 2009-04-14 14:27:58 +0000 |
---|---|---|
committer | Andreas Schneider <mail@cynapses.org> | 2009-04-14 14:27:58 +0000 |
commit | cd5588aa75b089824aacec36a48ab4d18ebad55d (patch) | |
tree | 9cfdac96aca3ac31535ddb40fffa8e246acecc7d /libssh/socket.c | |
parent | f6e3f1d985dfe542ff4b5a67e69deed52f690730 (diff) | |
download | libssh-cd5588aa75b089824aacec36a48ab4d18ebad55d.tar.gz libssh-cd5588aa75b089824aacec36a48ab4d18ebad55d.tar.xz libssh-cd5588aa75b089824aacec36a48ab4d18ebad55d.zip |
Add more error checks to ssh_socket_blocking_flush().
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@470 7dcaeef0-15fb-0310-b436-a5af3365683c
Diffstat (limited to 'libssh/socket.c')
-rw-r--r-- | libssh/socket.c | 69 |
1 files changed, 41 insertions, 28 deletions
diff --git a/libssh/socket.c b/libssh/socket.c index b493eb8..265203d 100644 --- a/libssh/socket.c +++ b/libssh/socket.c @@ -670,35 +670,48 @@ int ssh_socket_nonblocking_flush(struct socket *s) { /** \internal * \brief locking flush of the output packet buffer */ -int ssh_socket_blocking_flush(struct socket *s){ - SSH_SESSION *session=s->session; - enter_function(); - if(!ssh_socket_is_open(s)) { - session->alive=0; - leave_function(); - return SSH_ERROR; - } - if(s->data_except){ - leave_function(); - return SSH_ERROR; - } - if(buffer_get_rest_len(s->out_buffer)==0){ - leave_function(); - return SSH_OK; - } - if(ssh_socket_completewrite(s,buffer_get_rest(s->out_buffer), - buffer_get_rest_len(s->out_buffer))){ - session->alive=0; - ssh_socket_close(s); - // FIXME use the proper errno - ssh_set_error(session,SSH_FATAL,"Writing packet : error on socket (or connection closed): %s", - strerror(errno)); - leave_function(); - return SSH_ERROR; - } - buffer_reinit(s->out_buffer); +int ssh_socket_blocking_flush(struct socket *s) { + SSH_SESSION *session = s->session; + + enter_function(); + + if (!ssh_socket_is_open(s)) { + session->alive = 0; + leave_function(); - return SSH_OK; // no data pending + return SSH_ERROR; + } + + if (s->data_except) { + leave_function(); + return SSH_ERROR; + } + + if (buffer_get_rest_len(s->out_buffer) == 0) { + leave_function(); + return SSH_OK; + } + + if (ssh_socket_completewrite(s, buffer_get_rest(s->out_buffer), + buffer_get_rest_len(s->out_buffer)) != SSH_OK) { + session->alive = 0; + ssh_socket_close(s); + /* FIXME use the proper errno */ + ssh_set_error(session, SSH_FATAL, + "Writing packet: error on socket (or connection closed): %s", + strerror(errno)); + + leave_function(); + return SSH_ERROR; + } + + if (buffer_reinit(s->out_buffer) < 0) { + leave_function(); + return SSH_ERROR; + } + + leave_function(); + return SSH_OK; // no data pending } void ssh_socket_set_towrite(struct socket *s){ |