fix several return -1 to return a proper error code

On many places in the code there have been laziness return -1
statements lying around that should be fixed to return sensible
error codes. Here's a take at fixing a few offenders.
This commit is contained in:
Daniel Stenberg 2009-08-24 22:28:27 +02:00
parent 314e61e545
commit 13e920d4ef
2 changed files with 16 additions and 13 deletions

View File

@ -1738,7 +1738,7 @@ static ssize_t channel_read(LIBSSH2_CHANNEL *channel, int stream_id,
rc = _libssh2_transport_read(session);
if ((rc < 0) && (rc != PACKET_EAGAIN))
return -1;
return rc;
/*
* =============================== NOTE ===============================
@ -1950,6 +1950,8 @@ _libssh2_channel_packet_data_len(LIBSSH2_CHANNEL * channel, int stream_id)
* Send data to a channel. Note that if this returns EAGAIN or simply didn't
* send the entire packet, the caller must call this function again with the
* SAME input arguments.
*
* If it returns a negative number, that is the error code!
*/
ssize_t
_libssh2_channel_write(LIBSSH2_CHANNEL *channel, int stream_id,
@ -1970,7 +1972,7 @@ _libssh2_channel_write(LIBSSH2_CHANNEL *channel, int stream_id,
if (channel->local.close) {
libssh2_error(session, LIBSSH2_ERROR_CHANNEL_CLOSED,
"We've already closed this channel", 0);
return -1;
return LIBSSH2_ERROR_CHANNEL_CLOSED;
}
if (channel->local.eof) {
@ -1988,7 +1990,7 @@ _libssh2_channel_write(LIBSSH2_CHANNEL *channel, int stream_id,
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocte space for data transmission packet",
0);
return -1;
return LIBSSH2_ERROR_ALLOC;
}
channel->write_state = libssh2_NB_state_allocated;
@ -2074,7 +2076,7 @@ _libssh2_channel_write(LIBSSH2_CHANNEL *channel, int stream_id,
LIBSSH2_FREE(session, channel->write_packet);
channel->write_packet = NULL;
channel->write_state = libssh2_NB_state_idle;
return -1;
return LIBSSH2_ERROR_SOCKET_SEND;
}
/* Shrink local window size */
channel->local.window_size -= channel->write_bufwrite;
@ -2134,7 +2136,7 @@ static int channel_send_eof(LIBSSH2_CHANNEL *channel)
else if (rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send EOF on channel", 0);
return -1;
return LIBSSH2_ERROR_SOCKET_SEND;
}
channel->local.eof = 1;

View File

@ -1403,7 +1403,8 @@ libssh2_sftp_readdir_ex(LIBSSH2_SFTP_HANDLE *hnd, char *buffer,
/*
* sftp_write
*
* Write data to an SFTP handle
* Write data to an SFTP handle. Returns the number of bytes written, or
* a negative error code.
*/
static ssize_t sftp_write(LIBSSH2_SFTP_HANDLE *handle, const char *buffer,
size_t count)
@ -1434,7 +1435,7 @@ static ssize_t sftp_write(LIBSSH2_SFTP_HANDLE *handle, const char *buffer,
if (!sftp->write_packet) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for FXP_WRITE", 0);
return -1;
return LIBSSH2_ERROR_ALLOC;
}
_libssh2_htonu32(s, packet_len - 4);
s += 4;
@ -1467,9 +1468,8 @@ static ssize_t sftp_write(LIBSSH2_SFTP_HANDLE *handle, const char *buffer,
return rc;
}
else if(0 == rc) {
/* an actual error */
fprintf(stderr, "WEIRDNESS\n");
return -1;
/* nothing sent is an error */
return LIBSSH2_ERROR_SOCKET_SEND;
}
else if (packet_len != rc) {
return rc;
@ -1483,11 +1483,12 @@ static ssize_t sftp_write(LIBSSH2_SFTP_HANDLE *handle, const char *buffer,
sftp->write_request_id, &data, &data_len);
if (rc == PACKET_EAGAIN) {
return PACKET_EAGAIN;
} else if (rc) {
}
else if (rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT,
"Timeout waiting for status message", 0);
sftp->write_state = libssh2_NB_state_idle;
return -1;
return rc;
}
sftp->write_state = libssh2_NB_state_idle;
@ -1503,7 +1504,7 @@ static ssize_t sftp_write(LIBSSH2_SFTP_HANDLE *handle, const char *buffer,
0);
sftp->last_errno = retcode;
return -1;
return LIBSSH2_ERROR_SFTP_PROTOCOL;
}
/* libssh2_sftp_write