static int wolfSSH_SFTP_buffer_send(WOLFSSH* ssh, WS_SFTP_BUFFER* buffer)
{
    int ret;

    if (buffer == NULL) {
        return WS_BAD_ARGUMENT;
    }

    if (buffer->idx > buffer->sz) {
        return WS_BUFFER_E;
    }

    do {
        ret = wolfSSH_stream_send(ssh, buffer->data + buffer->idx,
            buffer->sz - buffer->idx);
        if (ret == WS_WINDOW_FULL || ret == WS_REKEYING) {
            ret = wolfSSH_worker(ssh, NULL);
            if (ret == WS_SUCCESS)
                continue; /* skip past increment and send more */
        }
        if (ret > 0) {
            buffer->idx += ret;
        }
    } while (buffer->idx < buffer->sz && (ret > 0 || ret == WS_SUCCESS));

    return ret;
}
static int wolfSSH_SFTP_buffer_send(WOLFSSH* ssh, WS_SFTP_BUFFER* buffer)
{
    int ret;

    if (buffer == NULL) {
        return WS_BAD_ARGUMENT;
    }

    if (buffer->idx > buffer->sz) {
        return WS_BUFFER_E;
    }

    do {
        ret = wolfSSH_stream_send(ssh, buffer->data + buffer->idx,
            buffer->sz - buffer->idx);
        if (ret == WS_WINDOW_FULL || ret == WS_REKEYING) {
            ret = wolfSSH_worker(ssh, NULL);
            if (ret == WS_SUCCESS)
                continue;  
        }
        if (ret > 0) {
            buffer->idx += ret;
        }
    } while (buffer->idx < buffer->sz && (ret > 0 || ret == WS_SUCCESS));

    return ret;
}