static int _adb_connect(const std::string& service, std::string* error) { D("_adb_connect: %s", service.c_str()); if (service.empty() || service.size() > MAX_PAYLOAD) { *error = android::base::StringPrintf("bad service name length (%zd)", service.size()); return -1; } std::string reason; int fd = socket_spec_connect(__adb_server_socket_spec, &reason); if (fd < 0) { *error = android::base::StringPrintf("cannot connect to daemon at %s: %s", __adb_server_socket_spec, reason.c_str()); return -2; } if (memcmp(&service[0], "host", 4) != 0 && switch_socket_transport(fd, error)) { return -1; } if (!SendProtocolString(fd, service)) { *error = perror_str("write failure during connection"); adb_close(fd); return -1; } if (!adb_status(fd, error)) { adb_close(fd); return -1; } D("_adb_connect: return fd %d", fd); return fd; }
int _adb_connect(const std::string& service, std::string* error) { D("_adb_connect: %s", service.c_str()); if (service.empty() || service.size() > MAX_PAYLOAD_V1) { *error = android::base::StringPrintf("bad service name length (%zd)", service.size()); return -1; } int fd; std::string reason; if (__adb_server_name) { fd = network_connect(__adb_server_name, __adb_server_port, SOCK_STREAM, 0, &reason); if (fd == -1) { *error = android::base::StringPrintf("can't connect to %s:%d: %s", __adb_server_name, __adb_server_port, reason.c_str()); return -2; } } else { fd = network_loopback_client(__adb_server_port, SOCK_STREAM, &reason); if (fd == -1) { *error = android::base::StringPrintf("cannot connect to daemon: %s", reason.c_str()); return -2; } } if ((memcmp(&service[0],"host",4) != 0 || service == "host:reconnect") && switch_socket_transport(fd, error)) { return -1; } if (!SendProtocolString(fd, service)) { *error = perror_str("write failure during connection"); adb_close(fd); return -1; } if (service != "reconnect") { if (!adb_status(fd, error)) { adb_close(fd); return -1; } } D("_adb_connect: return fd %d", fd); return fd; }
int _adb_connect(const char *service) { char tmp[5]; int len; int fd; D("_adb_connect: %s\n", service); len = strlen(service); if((len < 1) || (len > 1024)) { strcpy(__adb_error, "service name too long"); return -1; } snprintf(tmp, sizeof tmp, "%04x", len); if (__adb_server_name) fd = socket_network_client(__adb_server_name, __adb_server_port, SOCK_STREAM); else fd = socket_loopback_client(__adb_server_port, SOCK_STREAM); if(fd < 0) { strcpy(__adb_error, "cannot connect to daemon"); return -2; } if (memcmp(service,"host",4) != 0 && switch_socket_transport(fd)) { return -1; } if(!WriteFdExactly(fd, tmp, 4) || !WriteFdExactly(fd, service, len)) { strcpy(__adb_error, "write failure during connection"); adb_close(fd); return -1; } if(adb_status(fd)) { adb_close(fd); return -1; } D("_adb_connect: return fd %d\n", fd); return fd; }
int _adb_connect(const std::string& service, std::string* error) { D("_adb_connect: %s\n", service.c_str()); if (service.empty() || service.size() > 1024) { *error = android::base::StringPrintf("bad service name length (%d)", static_cast<int>(service.size())); return -1; } int fd; if (__adb_server_name) { fd = socket_network_client(__adb_server_name, __adb_server_port, SOCK_STREAM); } else { fd = socket_loopback_client(__adb_server_port, SOCK_STREAM); } if (fd < 0) { *error = perror_str("cannot connect to daemon"); return -2; } if (memcmp(&service[0],"host",4) != 0 && switch_socket_transport(fd, error)) { return -1; } if(!SendProtocolString(fd, service)) { *error = perror_str("write failure during connection"); adb_close(fd); return -1; } if (!adb_status(fd, error)) { adb_close(fd); return -1; } D("_adb_connect: return fd %d\n", fd); return fd; }
bool AdbClient::adb_connect(const char *service) { char tmp[5]; int len; len = strlen(service); if((len < 1) || (len > 1024)) { __adb_error = "service name too long"; return false; } snprintf(tmp, sizeof tmp, "%04x", len); if (memcmp(service,"host",4) != 0 && !switch_socket_transport()) { return false; } if(!writex(tmp, 4) || !writex(service, len)) { __adb_error = "write failure during connection"; adb_close(); return false; } return adb_status(); }