Пример #1
0
static int waitsocket(int socket_fd, LIBSSH2_SESSION *session)
{
    struct timeval timeout;
    int rc;
    fd_set fd;
    fd_set *writefd = NULL;
    fd_set *readfd = NULL;
    int dir;

    timeout.tv_sec = 10;
    timeout.tv_usec = 0;

    FD_ZERO(&fd);

    FD_SET(socket_fd, &fd);

    /* now make sure we wait in the correct direction */
    dir = libssh2_session_block_directions(session);

    if(dir & LIBSSH2_SESSION_BLOCK_INBOUND)
        readfd = &fd;

    if(dir & LIBSSH2_SESSION_BLOCK_OUTBOUND)
        writefd = &fd;

    rc = select(socket_fd + 1, readfd, writefd, NULL, &timeout);

    return rc;
}
RET_CODE StartLineProcessCollector::waitsocket(int socket_fd, LIBSSH2_SESSION *session) {
    struct timeval timeout;
    int rc;
    fd_set fd;
    fd_set *writefd = NULL;
    fd_set *readfd = NULL;
    int dir;

    timeout.tv_sec = 10;
    timeout.tv_usec = 0;

    FD_ZERO(&fd);

    FD_SET(socket_fd, &fd);

    dir = libssh2_session_block_directions(session);

    if (dir & LIBSSH2_SESSION_BLOCK_INBOUND)
        readfd = &fd;
    if (dir & LIBSSH2_SESSION_BLOCK_OUTBOUND)
        writefd = &fd;

    rc = select(socket_fd + 1, readfd, writefd, NULL, &timeout);

    return rc;
}
Пример #3
0
static int waitsocket(int socket_fd, LIBSSH2_SESSION* ssh_session, time_t timeout_sec)
{
    int ec;
    struct timeval timeout;
    
    fd_set fd;
    fd_set* writefd = NULL;
    fd_set* readfd = NULL;
    int dir;
    
    timeout.tv_sec = timeout_sec;
    timeout.tv_usec = 0;
    
    FD_ZERO(&fd);
    FD_SET(socket_fd, &fd);
    
    dir = libssh2_session_block_directions(ssh_session);
    
    if(dir & LIBSSH2_SESSION_BLOCK_INBOUND)
    {
        readfd = &fd;
    }
    if(dir & LIBSSH2_SESSION_BLOCK_OUTBOUND)
    {
        writefd = &fd;
    }
    
    ec = select(socket_fd + 1, readfd, writefd, NULL, &timeout);
    
    return ec;
}
Пример #4
0
Файл: ssh.c Проект: J-Liu/qemu
/* A non-blocking call returned EAGAIN, so yield, ensuring the
 * handlers are set up so that we'll be rescheduled when there is an
 * interesting event on the socket.
 */
static coroutine_fn void co_yield(BDRVSSHState *s, BlockDriverState *bs)
{
    int r;
    IOHandler *rd_handler = NULL, *wr_handler = NULL;
    Coroutine *co = qemu_coroutine_self();

    r = libssh2_session_block_directions(s->session);

    if (r & LIBSSH2_SESSION_BLOCK_INBOUND) {
        rd_handler = restart_coroutine;
    }
    if (r & LIBSSH2_SESSION_BLOCK_OUTBOUND) {
        wr_handler = restart_coroutine;
    }

    DPRINTF("s->sock=%d rd_handler=%p wr_handler=%p", s->sock,
            rd_handler, wr_handler);

    aio_set_fd_handler(bdrv_get_aio_context(bs), s->sock,
                       false, rd_handler, wr_handler, NULL, co);
    qemu_coroutine_yield();
    DPRINTF("s->sock=%d - back", s->sock);
    aio_set_fd_handler(bdrv_get_aio_context(bs), s->sock, false,
                       NULL, NULL, NULL, NULL);
}
Пример #5
0
int
sftpfs_waitsocket (sftpfs_super_data_t * super_data, GError ** mcerror)
{
    struct timeval timeout = { 10, 0 };
    fd_set fd;
    fd_set *writefd = NULL;
    fd_set *readfd = NULL;
    int dir;

    mc_return_val_if_error (mcerror, -1);

    FD_ZERO (&fd);
    FD_SET (super_data->socket_handle, &fd);

    /* now make sure we wait in the correct direction */
    dir = libssh2_session_block_directions (super_data->session);

    if ((dir & LIBSSH2_SESSION_BLOCK_INBOUND) != 0)
        readfd = &fd;

    if ((dir & LIBSSH2_SESSION_BLOCK_OUTBOUND) != 0)
        writefd = &fd;

    return select (super_data->socket_handle + 1, readfd, writefd, NULL, &timeout);
}
Пример #6
0
@return block directions\n\
@rtype int";

static PyObject *
PYLIBSSH2_Session_blockdirections(PYLIBSSH2_SESSION *self, PyObject *args)
{
    int blockedon;

    blockedon = libssh2_session_block_directions(self->session);
    
    return Py_BuildValue("i", blockedon);
}
Пример #7
0
// http://www.libssh2.org/examples/ssh2_exec.html
bool CLibssh2::timedwait_socket()
{
    int events_requested = 0;
    LIBSSH2_SESSION* session = static_cast<LIBSSH2_SESSION*>(_session);

    // now make sure we wait in the correct direction
    int direction = libssh2_session_block_directions(session);
    if(direction & LIBSSH2_SESSION_BLOCK_INBOUND)
        events_requested |= POLLIN;
    if(direction & LIBSSH2_SESSION_BLOCK_OUTBOUND)
        events_requested |= POLLOUT;

    return CUtils::timed_poll(_socket_fd, events_requested, _timeout_seconds*1000);
}
Пример #8
0
static int uwsgi_ssh_waitsocket(int socket_fd, LIBSSH2_SESSION *session) {
	int dir = libssh2_session_block_directions(session);

	if (dir & LIBSSH2_SESSION_BLOCK_INBOUND) {
		if (uwsgi.wait_read_hook(socket_fd, ulibssh2.ssh_timeout) < 0) {
			uwsgi_error("uwsgi_ssh_waitsocket()/wait_read_hook()");
			return -1;
		}
	}

	if (dir & LIBSSH2_SESSION_BLOCK_OUTBOUND) {
		if (uwsgi.wait_write_hook(socket_fd, ulibssh2.ssh_timeout) < 0) {
			uwsgi_error("uwsgi_ssh_waitsocket()/wait_write_hook()");
			return -1;
		}
	}

	return 0;
}
Пример #9
0
static coroutine_fn void set_fd_handler(BDRVSSHState *s)
{
    int r;
    IOHandler *rd_handler = NULL, *wr_handler = NULL;
    Coroutine *co = qemu_coroutine_self();

    r = libssh2_session_block_directions(s->session);

    if (r & LIBSSH2_SESSION_BLOCK_INBOUND) {
        rd_handler = restart_coroutine;
    }
    if (r & LIBSSH2_SESSION_BLOCK_OUTBOUND) {
        wr_handler = restart_coroutine;
    }

    DPRINTF("s->sock=%d rd_handler=%p wr_handler=%p", s->sock,
            rd_handler, wr_handler);

    qemu_aio_set_fd_handler(s->sock, rd_handler, wr_handler, return_true, co);
}
Пример #10
0
void FSSftp::WaitSocket( FSCInfo* info ) //throw int(errno) or int(-2) on stop
{
	while ( true )
	{
		if ( info && info->Stopped() ) { throw int( -2 ); } //stopped

		int dir = libssh2_session_block_directions( sshSession );

		if ( ( dir & ( LIBSSH2_SESSION_BLOCK_INBOUND | LIBSSH2_SESSION_BLOCK_OUTBOUND ) ) == 0 )
		{
			return ;
		}

		int n = _sock.Select2(
		           ( dir & LIBSSH2_SESSION_BLOCK_INBOUND ) != 0,
		           ( dir & LIBSSH2_SESSION_BLOCK_OUTBOUND ) != 0,
		           3 );

		if ( n > 0 ) { return; }
	}
}
Пример #11
0
int waitsocket(LIBSSH2_SESSION *session, int sock)
{
    struct timeval timeout;
    int rc;
    fd_set fd;
    fd_set *writefd = NULL;
    fd_set *readfd = NULL;
    int dir;

    timeout.tv_sec = 1;
    timeout.tv_usec = 0;

    FD_ZERO(&fd);
    FD_SET(sock, &fd);

    dir = libssh2_session_block_directions(session);
    if (dir & LIBSSH2_SESSION_BLOCK_INBOUND)
        readfd = &fd;
    if (dir & LIBSSH2_SESSION_BLOCK_OUTBOUND)
        writefd = &fd;

    rc = select(sock+1, readfd, writefd, NULL, &timeout);
    return rc;
}
Пример #12
0
/*
 * call-seq:
 *     session.block_directions
 *
 * Returns an int that determines the direction to wait on the socket
 * in the case of an EAGAIN. This will be a binary mask that can be
 * checked with `Native::SESSION_BLOCK_INBOUND` and
 * `Native::SESSION_BLOCK_OUTBOUND`.
 * */
static VALUE
block_directions(VALUE self) {
    return INT2FIX(libssh2_session_block_directions(get_session(self)));
}