static int connect_to_console(const char* serial) {
    int port = adb_get_emulator_console_port(serial);
    if (port == -1) {
        return -1;
    }

    std::string error;
    int fd = network_loopback_client(port, SOCK_STREAM, &error);
    if (fd == -1) {
        fprintf(stderr, "error: could not connect to TCP port %d: %s\n", port,
                error.c_str());
        return -1;
    }
    return fd;
}
Exemple #2
0
static int connect_to_console(void)
{
    int fd, port;

    port = adb_get_emulator_console_port();
    if (port < 0) {
        if (port == -2)
            fprintf(stderr,
                    "error: more than one emulator detected. use -s option\n");
        else
            fprintf(stderr, "error: no emulator detected\n");
        return -1;
    }
    fd = socket_loopback_client(port, SOCK_STREAM);
    if (fd < 0) {
        fprintf(stderr, "error: could not connect to TCP port %d\n", port);
        return -1;
    }
    return fd;
}