am 8cf0d59f: adb: Add "adb disconnect" command for disconnecting TCP/IP devices.
Merge commit '8cf0d59f61ae0b8554ecf3fe051850508b761b79' into eclair-mr2-plus-aosp * commit '8cf0d59f61ae0b8554ecf3fe051850508b761b79': adb: Add "adb disconnect" command for disconnecting TCP/IP devices.
This commit is contained in:
commit
96b6bf3e92
33
adb/adb.c
33
adb/adb.c
|
@ -1020,19 +1020,24 @@ int handle_host_request(char *service, transport_type ttype, char* serial, int r
|
|||
char* portstr = strchr(host, ':');
|
||||
|
||||
if (!portstr) {
|
||||
snprintf(buffer, sizeof(buffer), "unable to parse %s as <host>:<port>\n", host);
|
||||
snprintf(buffer, sizeof(buffer), "unable to parse %s as <host>:<port>", host);
|
||||
goto done;
|
||||
}
|
||||
if (find_transport(host)) {
|
||||
snprintf(buffer, sizeof(buffer), "Already connected to %s", host);
|
||||
goto done;
|
||||
}
|
||||
|
||||
// zero terminate host by overwriting the ':'
|
||||
*portstr++ = 0;
|
||||
if (sscanf(portstr, "%d", &port) == 0) {
|
||||
snprintf(buffer, sizeof(buffer), "bad port number %s\n", portstr);
|
||||
snprintf(buffer, sizeof(buffer), "bad port number %s", portstr);
|
||||
goto done;
|
||||
}
|
||||
|
||||
fd = socket_network_client(host, port, SOCK_STREAM);
|
||||
if (fd < 0) {
|
||||
snprintf(buffer, sizeof(buffer), "unable to connect to %s:%d\n", host, port);
|
||||
snprintf(buffer, sizeof(buffer), "unable to connect to %s:%d", host, port);
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
@ -1041,10 +1046,28 @@ int handle_host_request(char *service, transport_type ttype, char* serial, int r
|
|||
disable_tcp_nagle(fd);
|
||||
snprintf(buf, sizeof buf, "%s:%d", host, port);
|
||||
register_socket_transport(fd, buf, port, 0);
|
||||
snprintf(buffer, sizeof(buffer), "connected to %s:%d\n", host, port);
|
||||
snprintf(buffer, sizeof(buffer), "connected to %s:%d", host, port);
|
||||
|
||||
done:
|
||||
snprintf(buf, sizeof(buf), "OKAY%04x%s",(unsigned)strlen(buffer),buffer);
|
||||
snprintf(buf, sizeof(buf), "OKAY%04x%s",(unsigned)strlen(buffer), buffer);
|
||||
writex(reply_fd, buf, strlen(buf));
|
||||
return 0;
|
||||
}
|
||||
|
||||
// remove TCP transport
|
||||
if (!strncmp(service, "disconnect:", 11)) {
|
||||
char buffer[4096];
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
char* serial = service + 11;
|
||||
atransport *t = find_transport(serial);
|
||||
|
||||
if (t) {
|
||||
unregister_transport(t);
|
||||
} else {
|
||||
snprintf(buffer, sizeof(buffer), "No such device %s", serial);
|
||||
}
|
||||
|
||||
snprintf(buf, sizeof(buf), "OKAY%04x%s",(unsigned)strlen(buffer), buffer);
|
||||
writex(reply_fd, buf, strlen(buf));
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -270,11 +270,17 @@ void close_usb_devices();
|
|||
|
||||
/* cause new transports to be init'd and added to the list */
|
||||
void register_socket_transport(int s, const char *serial, int port, int local);
|
||||
|
||||
/* this should only be used for the "adb disconnect" command */
|
||||
void unregister_transport(atransport *t);
|
||||
|
||||
void register_usb_transport(usb_handle *h, const char *serial, unsigned writeable);
|
||||
|
||||
/* this should only be used for transports with connection_state == CS_NOPERM */
|
||||
void unregister_usb_transport(usb_handle *usb);
|
||||
|
||||
atransport *find_transport(const char *serial);
|
||||
|
||||
int service_to_fd(const char *name);
|
||||
#if ADB_HOST
|
||||
asocket *host_service_to_socket(const char* name, const char *serial);
|
||||
|
|
|
@ -106,6 +106,7 @@ void help()
|
|||
" be an absolute path.\n"
|
||||
" devices - list all connected devices\n"
|
||||
" connect <host>:<port> - connect to a device via TCP/IP"
|
||||
" disconnect <host>:<port> - disconnect from a TCP/IP device"
|
||||
"\n"
|
||||
"device commands:\n"
|
||||
" adb push <local> <remote> - copy file/dir to device\n"
|
||||
|
@ -853,10 +854,10 @@ top:
|
|||
}
|
||||
}
|
||||
|
||||
if(!strcmp(argv[0], "connect")) {
|
||||
if(!strcmp(argv[0], "connect") || !strcmp(argv[0], "disconnect")) {
|
||||
char *tmp;
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "Usage: adb connect <host>:<port>\n");
|
||||
fprintf(stderr, "Usage: adb %s <host>:<port>\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
snprintf(buf, sizeof buf, "host:%s:%s", argv[0], argv[1]);
|
||||
|
|
|
@ -164,7 +164,7 @@ jdwp_process_free( JdwpProcess* proc )
|
|||
proc->next->prev = proc->prev;
|
||||
|
||||
if (proc->socket >= 0) {
|
||||
shutdown(proc->socket, SHUT_RDWR);
|
||||
adb_shutdown(proc->socket);
|
||||
adb_close(proc->socket);
|
||||
proc->socket = -1;
|
||||
}
|
||||
|
|
|
@ -113,6 +113,7 @@ extern int adb_creat(const char* path, int mode);
|
|||
extern int adb_read(int fd, void* buf, int len);
|
||||
extern int adb_write(int fd, const void* buf, int len);
|
||||
extern int adb_lseek(int fd, int pos, int where);
|
||||
extern int adb_shutdown(int fd);
|
||||
extern int adb_close(int fd);
|
||||
|
||||
static __inline__ int unix_close(int fd)
|
||||
|
@ -327,6 +328,13 @@ static __inline__ int adb_open( const char* pathname, int options )
|
|||
#undef open
|
||||
#define open ___xxx_open
|
||||
|
||||
static __inline__ int adb_shutdown(int fd)
|
||||
{
|
||||
return shutdown(fd, SHUT_RDWR);
|
||||
}
|
||||
#undef shutdown
|
||||
#define shutdown ____xxx_shutdown
|
||||
|
||||
static __inline__ int adb_close(int fd)
|
||||
{
|
||||
return close(fd);
|
||||
|
|
|
@ -435,6 +435,20 @@ int adb_lseek(int fd, int pos, int where)
|
|||
}
|
||||
|
||||
|
||||
int adb_shutdown(int fd)
|
||||
{
|
||||
FH f = _fh_from_int(fd);
|
||||
|
||||
if (!f) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
D( "adb_shutdown: %s\n", f->name);
|
||||
shutdown( f->fh_socket, SD_BOTH );
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int adb_close(int fd)
|
||||
{
|
||||
FH f = _fh_from_int(fd);
|
||||
|
|
|
@ -864,6 +864,38 @@ void register_socket_transport(int s, const char *serial, int port, int local)
|
|||
register_transport(t);
|
||||
}
|
||||
|
||||
#if ADB_HOST
|
||||
atransport *find_transport(const char *serial)
|
||||
{
|
||||
atransport *t;
|
||||
|
||||
adb_mutex_lock(&transport_lock);
|
||||
for(t = transport_list.next; t != &transport_list; t = t->next) {
|
||||
if (t->serial && !strcmp(serial, t->serial)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
adb_mutex_unlock(&transport_lock);
|
||||
|
||||
if (t != &transport_list)
|
||||
return t;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
void unregister_transport(atransport *t)
|
||||
{
|
||||
adb_mutex_lock(&transport_lock);
|
||||
t->next->prev = t->prev;
|
||||
t->prev->next = t->next;
|
||||
adb_mutex_unlock(&transport_lock);
|
||||
|
||||
kick_transport(t);
|
||||
transport_unref(t);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void register_usb_transport(usb_handle *usb, const char *serial, unsigned writeable)
|
||||
{
|
||||
atransport *t = calloc(1, sizeof(atransport));
|
||||
|
|
|
@ -204,6 +204,7 @@ static void remote_kick(atransport *t)
|
|||
{
|
||||
int fd = t->sfd;
|
||||
t->sfd = -1;
|
||||
adb_shutdown(fd);
|
||||
adb_close(fd);
|
||||
|
||||
#if ADB_HOST
|
||||
|
|
Loading…
Reference in New Issue