summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/idevicedebugserverproxy.c46
1 files changed, 23 insertions, 23 deletions
diff --git a/tools/idevicedebugserverproxy.c b/tools/idevicedebugserverproxy.c
index 035a231..37d03ea 100644
--- a/tools/idevicedebugserverproxy.c
+++ b/tools/idevicedebugserverproxy.c
@@ -91,19 +91,12 @@ static void print_usage(int argc, char **argv)
91 printf("Bug Reports: <" PACKAGE_BUGREPORT ">\n"); 91 printf("Bug Reports: <" PACKAGE_BUGREPORT ">\n");
92} 92}
93 93
94struct service_client_private {
95 idevice_connection_t connection;
96};
97struct debugserver_client_private {
98 struct service_client_private* parent;
99 int noack_mode;
100};
101
102static void* connection_handler(void* data) 94static void* connection_handler(void* data)
103{ 95{
104 debugserver_error_t derr = DEBUGSERVER_E_SUCCESS; 96 debugserver_error_t derr = DEBUGSERVER_E_SUCCESS;
105 socket_info_t* socket_info = (socket_info_t*)data; 97 socket_info_t* socket_info = (socket_info_t*)data;
106 char buf[4096]; 98 const int bufsize = 65536;
99 char* buf;
107 100
108 int client_fd = socket_info->client_fd; 101 int client_fd = socket_info->client_fd;
109 102
@@ -114,30 +107,29 @@ static void* connection_handler(void* data)
114 fprintf(stderr, "Could not start debugserver on device!\nPlease make sure to mount a developer disk image first.\n"); 107 fprintf(stderr, "Could not start debugserver on device!\nPlease make sure to mount a developer disk image first.\n");
115 return NULL; 108 return NULL;
116 } 109 }
117 int dbgsvr_fd = -1; 110
118 idevice_connection_get_fd(socket_info->debugserver_client->parent->connection, &dbgsvr_fd); 111 buf = malloc(bufsize);
119 if (dbgsvr_fd == -1) { 112 if (!buf) {
120 fprintf(stderr, "Could not get debugserver connection fd.\n"); 113 fprintf(stderr, "Failed to allocate buffer\n");
121 return NULL; 114 return NULL;
122 } 115 }
123 116
124 fd_set fds; 117 fd_set fds;
125 int maxfd = 0;
126 FD_ZERO(&fds); 118 FD_ZERO(&fds);
127 FD_SET(client_fd, &fds); 119 FD_SET(client_fd, &fds);
128 if (client_fd > maxfd) maxfd = client_fd; 120
129 FD_SET(dbgsvr_fd, &fds); 121 int dtimeout = 1;
130 if (dbgsvr_fd > maxfd) maxfd = dbgsvr_fd;
131 122
132 while (!quit_flag) { 123 while (!quit_flag) {
133 fd_set read_fds = fds; 124 fd_set read_fds = fds;
134 int ret_sel = select(maxfd+1, &read_fds, NULL, NULL, NULL); 125 struct timeval tv = { 0, 1000 };
126 int ret_sel = select(client_fd+1, &read_fds, NULL, NULL, &tv);
135 if (ret_sel < 0) { 127 if (ret_sel < 0) {
136 perror("select"); 128 perror("select");
137 break; 129 break;
138 } 130 }
139 if (FD_ISSET(client_fd, &read_fds)) { 131 if (FD_ISSET(client_fd, &read_fds)) {
140 ssize_t n = socket_receive(client_fd, buf, sizeof(buf)); 132 ssize_t n = socket_receive(client_fd, buf, bufsize);
141 if (n < 0) { 133 if (n < 0) {
142 fprintf(stderr, "Failed to read from client fd: %s\n", strerror(-n)); 134 fprintf(stderr, "Failed to read from client fd: %s\n", strerror(-n));
143 break; 135 break;
@@ -149,17 +141,25 @@ static void* connection_handler(void* data)
149 uint32_t sent = 0; 141 uint32_t sent = 0;
150 debugserver_client_send(socket_info->debugserver_client, buf, n, &sent); 142 debugserver_client_send(socket_info->debugserver_client, buf, n, &sent);
151 } 143 }
152 if (FD_ISSET(dbgsvr_fd, &read_fds)) { 144 do {
153 uint32_t r = 0; 145 uint32_t r = 0;
154 derr = debugserver_client_receive_with_timeout(socket_info->debugserver_client, buf, sizeof(buf), &r, 1); 146 derr = debugserver_client_receive_with_timeout(socket_info->debugserver_client, buf, bufsize, &r, dtimeout);
155 if (r > 0) { 147 if (r > 0) {
156 socket_send(client_fd, buf, r); 148 socket_send(client_fd, buf, r);
157 } else if (derr != DEBUGSERVER_E_TIMEOUT) { 149 dtimeout = 1;
158 fprintf(stderr, "Failed to read from debugserver (%d)\n", derr); 150 } else if (derr == DEBUGSERVER_E_TIMEOUT) {
151 dtimeout = 5;
152 break;
153 } else {
154 fprintf(stderr, "debugserver connection closed\n");
159 break; 155 break;
160 } 156 }
157 } while (derr == DEBUGSERVER_E_SUCCESS);
158 if (derr != DEBUGSERVER_E_TIMEOUT && derr != DEBUGSERVER_E_SUCCESS) {
159 break;
161 } 160 }
162 } 161 }
162 free(buf);
163 163
164 debug("%s: shutting down...\n", __func__); 164 debug("%s: shutting down...\n", __func__);
165 165