am 0500c6af: am c1557acb: am e434ad1d: Merge "Always explain why bind(2) failed."

* commit '0500c6af0dc98b2236c1874abb49f0b36bac2b59':
  Always explain why bind(2) failed.
This commit is contained in:
Elliott Hughes 2015-04-21 23:27:04 +00:00 committed by Android Git Automerger
commit e449346837
5 changed files with 27 additions and 23 deletions

View file

@ -69,6 +69,8 @@ LOCAL_SRC_FILES := \
qemu_tracing.cpp \
usb_linux_client.cpp \
LOCAL_SHARED_LIBRARIES := libbase
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
@ -80,6 +82,8 @@ LOCAL_SRC_FILES := \
$(LIBADB_$(HOST_OS)_SRC_FILES) \
adb_auth_host.cpp \
LOCAL_SHARED_LIBRARIES := libbase
# Even though we're building a static library (and thus there's no link step for
# this to take effect), this adds the SSL includes to our path.
LOCAL_STATIC_LIBRARIES := libcrypto_static

View file

@ -32,6 +32,8 @@
#include <string>
#include <base/stringprintf.h>
#include "adb_auth.h"
#include "adb_io.h"
#include "adb_listeners.h"
@ -802,7 +804,6 @@ int handle_forward_request(const char* service, transport_type ttype, char* seri
if (!strncmp(service, "forward:",8) ||
!strncmp(service, "killforward:",12)) {
char *local, *remote;
int r;
atransport *transport;
int createForward = strncmp(service, "kill", 4);
@ -845,12 +846,13 @@ int handle_forward_request(const char* service, transport_type ttype, char* seri
return 1;
}
install_status_t r;
if (createForward) {
r = install_listener(local, remote, transport, no_rebind);
} else {
r = remove_listener(local, transport);
}
if(r == 0) {
if (r == INSTALL_STATUS_OK) {
#if ADB_HOST
/* On the host: 1st OKAY is connect, 2nd OKAY is status */
WriteFdExactly(reply_fd, "OKAY", 4);
@ -859,22 +861,19 @@ int handle_forward_request(const char* service, transport_type ttype, char* seri
return 1;
}
if (createForward) {
const char* message;
switch (r) {
case INSTALL_STATUS_CANNOT_BIND:
message = "cannot bind to socket";
break;
case INSTALL_STATUS_CANNOT_REBIND:
message = "cannot rebind existing socket";
break;
default:
message = "internal error";
}
sendfailmsg(reply_fd, message);
} else {
sendfailmsg(reply_fd, "cannot remove listener");
std::string message;
switch (r) {
case INSTALL_STATUS_OK: message = " "; break;
case INSTALL_STATUS_INTERNAL_ERROR: message = "internal error"; break;
case INSTALL_STATUS_CANNOT_BIND:
message = android::base::StringPrintf("cannot bind to socket: %s", strerror(errno));
break;
case INSTALL_STATUS_CANNOT_REBIND:
message = android::base::StringPrintf("cannot rebind existing socket: %s", strerror(errno));
break;
case INSTALL_STATUS_LISTENER_NOT_FOUND: message = "listener not found"; break;
}
sendfailmsg(reply_fd, message.c_str());
return 1;
}
return 0;

View file

@ -190,17 +190,17 @@ int format_listeners(char* buf, size_t buflen)
return result;
}
int remove_listener(const char *local_name, atransport* transport)
install_status_t remove_listener(const char *local_name, atransport* transport)
{
alistener *l;
for (l = listener_list.next; l != &listener_list; l = l->next) {
if (!strcmp(local_name, l->local_name)) {
listener_disconnect(l, l->transport);
return 0;
return INSTALL_STATUS_OK;
}
}
return -1;
return INSTALL_STATUS_LISTENER_NOT_FOUND;
}
void remove_all_listeners(void)
@ -268,10 +268,10 @@ install_status_t install_listener(const char *local_name,
listener->fd = local_name_to_fd(local_name);
if (listener->fd < 0) {
printf("cannot bind '%s': %s\n", local_name, strerror(errno));
free(listener->local_name);
free(listener->connect_to);
free(listener);
printf("cannot bind '%s'\n", local_name);
return INSTALL_STATUS_CANNOT_BIND;
}

View file

@ -25,6 +25,7 @@ enum install_status_t {
INSTALL_STATUS_INTERNAL_ERROR = -1,
INSTALL_STATUS_CANNOT_BIND = -2,
INSTALL_STATUS_CANNOT_REBIND = -3,
INSTALL_STATUS_LISTENER_NOT_FOUND = -4,
};
extern alistener listener_list;
@ -40,7 +41,7 @@ install_status_t install_listener(const char *local_name,
int format_listeners(char* buf, size_t buflen);
int remove_listener(const char *local_name, atransport* transport);
install_status_t remove_listener(const char* local_name, atransport* transport);
void remove_all_listeners(void);
#endif /* __ADB_LISTENERS_H */

View file

@ -144,7 +144,7 @@ static void *server_socket_thread(void * arg)
if(serverfd == -1) {
serverfd = socket_inaddr_any_server(port, SOCK_STREAM);
if(serverfd < 0) {
D("server: cannot bind socket yet\n");
D("server: cannot bind socket yet: %s\n", strerror(errno));
adb_sleep_ms(1000);
continue;
}