Ejemplo n.º 1
0
int tcp_start_incoming_migration(const char *host_port)
{
    SockAddress addr;
    int s;

    if (parse_host_port(&addr, host_port) < 0) {
        fprintf(stderr, "invalid host/port combination: %s\n", host_port);
        return -EINVAL;
    }

    s = socket_create_inet(SOCKET_STREAM);
    if (s == -1)
        return -socket_error();

    socket_set_xreuseaddr(s);

    if (socket_bind(s, &addr) == -1)
        goto err;

    if (socket_listen(s, 1) == -1)
        goto err;

    qemu_set_fd_handler2(s, NULL, tcp_accept_incoming_migration, NULL,
                         (void *)(unsigned long)s);

    return 0;

err:
    socket_close(s);
    return -socket_error();
}
ProxyConnection*
http_connector_connect( HttpService*  service,
                        SockAddress*  address )
{
    Connection*  conn;
    int          s;

    s = socket_create_inet( SOCKET_STREAM );
    if (s < 0)
        return NULL;

    conn = qemu_mallocz(sizeof(*conn));
    if (conn == NULL) {
        socket_close(s);
        return NULL;
    }

    proxy_connection_init( conn->root, s, address, service->root,
                           connection_free,
                           connection_select,
                           connection_poll );

    if ( connection_init( conn ) < 0 ) {
        connection_free( conn->root );
        return NULL;
    }

    return conn->root;
}
Ejemplo n.º 3
0
MigrationState *tcp_start_outgoing_migration(const char *host_port,
                                             int64_t bandwidth_limit,
                                             int detach)
{
    SockAddress  addr;
    FdMigrationState *s;
    int ret;

    if (parse_host_port(&addr, host_port) < 0)
        return NULL;

    s = g_malloc0(sizeof(*s));

    s->get_error = socket_errno;
    s->write = socket_write;
    s->close = tcp_close;
    s->mig_state.cancel = migrate_fd_cancel;
    s->mig_state.get_status = migrate_fd_get_status;
    s->mig_state.release = migrate_fd_release;

    s->state = MIG_STATE_ACTIVE;
    s->mon_resume = NULL;
    s->bandwidth_limit = bandwidth_limit;
    s->fd = socket_create_inet(SOCKET_STREAM);
    if (s->fd == -1) {
        g_free(s);
        return NULL;
    }

    socket_set_nonblock(s->fd);

    if (!detach)
        migrate_fd_monitor_suspend(s);

    do {
        ret = socket_connect(s->fd, &addr);
        if (ret == -1)
            ret = -(s->get_error(s));

        if (ret == -EINPROGRESS || ret == -EWOULDBLOCK || ret == -EAGAIN)
            qemu_set_fd_handler2(s->fd, NULL, NULL, tcp_wait_for_connect, s);
    } while (ret == -EINTR);

    if (ret < 0 && ret != -EINPROGRESS && ret != -EWOULDBLOCK && ret != -EAGAIN) {
        dprintf("connect failed\n");
        socket_close(s->fd);
        g_free(s);
        return NULL;
    } else if (ret >= 0)
        migrate_fd_connect(s);

    return &s->mig_state;
}
Ejemplo n.º 4
0
static void
coreconsole_init(CoreConsole* cc, const SockAddress* address, Looper* looper)
{
    int fd = socket_create_inet(SOCKET_STREAM);
    AsyncStatus status;
    cc->port = sock_address_get_port(address);
    cc->ok   = 0;
    loopIo_init(cc->io, looper, fd, coreconsole_io_func, cc);
    if (fd >= 0) {
        status = asyncConsoleConnector_connect(cc->connector, address, cc->io);
        if (status == ASYNC_ERROR) {
            cc->ok = 0;
        }
    }
}
/* Opens connection socket.
 * Param:
 *  connector - Initialized AsyncSocketConnector instance.
 * Return:
 *  0 on success, or -1 on failure.
 */
static int
_async_socket_connector_open_socket(AsyncSocketConnector* connector)
{
    /* Open socket. */
    connector->fd = socket_create_inet(SOCKET_STREAM);
    if (connector->fd < 0) {
        D("ASC %s: Unable to create socket: %d -> %s",
          _asc_socket_string(connector), errno, strerror(errno));
        return -1;
    }

    /* Prepare for async I/O on the connector. */
    socket_set_nonblock(connector->fd);

    T("ASC %s: Connector socket is opened with FD = %d",
      _asc_socket_string(connector), connector->fd);

    return 0;
}
Ejemplo n.º 6
0
calipso_socket_t * calipso_do_listen_sock(const char *naddr,
        int16_t portn)
{
    int sd = socket_create_inet(naddr, portn);
    calipso_socket_t * socket = calipso_socket_alloc();

    if (socket && sd != -1) {
        calipso_socket_set_port(socket, portn);
        calipso_socket_set_socketfd(socket, sd);
        /* init listener event */
        socket->event = cpo_event_alloc(EVENT_LISTENER);
        socket->event->data = socket;
    } else {
        cpo_log_error(calipso->log,
                      "Can't create lisnten socket %s",
                      strerror(errno));
        exit(-1);
    }

    return (socket);
}