1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-12-02 01:17:52 +03:00

socket: Return ssize_t for ssh_socket_unbuffered_write()

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
Andreas Schneider
2018-09-24 18:40:11 +02:00
parent a7604c7d6e
commit 35bf5334b8

View File

@@ -96,7 +96,8 @@ static int sockets_initialized = 0;
static ssize_t ssh_socket_unbuffered_read(ssh_socket s, static ssize_t ssh_socket_unbuffered_read(ssh_socket s,
void *buffer, void *buffer,
uint32_t len); uint32_t len);
static int ssh_socket_unbuffered_write(ssh_socket s, const void *buffer, static ssize_t ssh_socket_unbuffered_write(ssh_socket s,
const void *buffer,
uint32_t len); uint32_t len);
/** /**
@@ -583,9 +584,11 @@ static ssize_t ssh_socket_unbuffered_read(ssh_socket s,
/** \internal /** \internal
* \brief writes len bytes from buffer to socket * \brief writes len bytes from buffer to socket
*/ */
static int ssh_socket_unbuffered_write(ssh_socket s, const void *buffer, static ssize_t ssh_socket_unbuffered_write(ssh_socket s,
uint32_t len) { const void *buffer,
int w = -1; uint32_t len)
{
ssize_t w = -1;
if (s->data_except) { if (s->data_except) {
return -1; return -1;
@@ -674,7 +677,6 @@ int ssh_socket_nonblocking_flush(ssh_socket s)
{ {
ssh_session session = s->session; ssh_session session = s->session;
uint32_t len; uint32_t len;
int w;
if (!ssh_socket_is_open(s)) { if (!ssh_socket_is_open(s)) {
session->alive = 0; session->alive = 0;
@@ -702,8 +704,12 @@ int ssh_socket_nonblocking_flush(ssh_socket s)
} }
if (s->write_wontblock && len > 0) { if (s->write_wontblock && len > 0) {
w = ssh_socket_unbuffered_write(s, ssh_buffer_get(s->out_buffer), len); ssize_t bwritten;
if (w < 0) {
bwritten = ssh_socket_unbuffered_write(s,
ssh_buffer_get(s->out_buffer),
len);
if (bwritten < 0) {
session->alive = 0; session->alive = 0;
ssh_socket_close(s); ssh_socket_close(s);
@@ -722,9 +728,9 @@ int ssh_socket_nonblocking_flush(ssh_socket s)
return SSH_ERROR; return SSH_ERROR;
} }
ssh_buffer_pass_bytes(s->out_buffer, w); ssh_buffer_pass_bytes(s->out_buffer, bwritten);
if (s->session->socket_counter != NULL) { if (s->session->socket_counter != NULL) {
s->session->socket_counter->out_bytes += w; s->session->socket_counter->out_bytes += bwritten;
} }
} }