diff options
| author | 2013-12-23 21:46:20 +0100 | |
|---|---|---|
| committer | 2013-12-23 21:46:20 +0100 | |
| commit | 3d9687b71f73948319931943c75d28a61af36a31 (patch) | |
| tree | 5a65057e68ce129b99c05268d0214f46325e7920 | |
| parent | 1d9358ee9f59e655bbfe6ebf1119bace2ad0eb73 (diff) | |
| download | usbmuxd-3d9687b71f73948319931943c75d28a61af36a31.tar.gz usbmuxd-3d9687b71f73948319931943c75d28a61af36a31.tar.bz2 | |
enlarge input+output buffer sizes.
| -rw-r--r-- | src/client.c | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/src/client.c b/src/client.c index fdbea25..ba6a302 100644 --- a/src/client.c +++ b/src/client.c | |||
| @@ -41,8 +41,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |||
| 41 | #include "device.h" | 41 | #include "device.h" |
| 42 | #include "conf.h" | 42 | #include "conf.h" |
| 43 | 43 | ||
| 44 | #define CMD_BUF_SIZE 1024 | 44 | #define CMD_BUF_SIZE 0x10000 |
| 45 | #define REPLY_BUF_SIZE 1024 | 45 | #define REPLY_BUF_SIZE 0x10000 |
| 46 | 46 | ||
| 47 | enum client_state { | 47 | enum client_state { |
| 48 | CLIENT_COMMAND, // waiting for command | 48 | CLIENT_COMMAND, // waiting for command |
| @@ -172,10 +172,14 @@ static int send_pkt(struct mux_client *client, uint32_t tag, enum usbmuxd_msgtyp | |||
| 172 | hdr.message = msg; | 172 | hdr.message = msg; |
| 173 | hdr.tag = tag; | 173 | hdr.tag = tag; |
| 174 | usbmuxd_log(LL_DEBUG, "send_pkt fd %d tag %d msg %d payload_length %d", client->fd, tag, msg, payload_length); | 174 | usbmuxd_log(LL_DEBUG, "send_pkt fd %d tag %d msg %d payload_length %d", client->fd, tag, msg, payload_length); |
| 175 | if((client->ob_capacity - client->ob_size) < hdr.length) { | 175 | |
| 176 | usbmuxd_log(LL_ERROR, "Client %d output buffer full (%d bytes) while sending message %d (%d bytes)", client->fd, client->ob_capacity, hdr.message, hdr.length); | 176 | uint32_t available = client->ob_capacity - client->ob_size; |
| 177 | client_close(client); | 177 | /* the output buffer _should_ be large enough, but just in case */ |
| 178 | return -1; | 178 | if(available < hdr.length) { |
| 179 | uint32_t needed_buffer = hdr.length; | ||
| 180 | usbmuxd_log(LL_DEBUG, "Enlarging client %d output buffer %d -> %d", client->fd, client->ob_capacity, needed_buffer); | ||
| 181 | client->ob_buf = realloc(client->ob_buf, needed_buffer); | ||
| 182 | client->ob_capacity = needed_buffer; | ||
| 179 | } | 183 | } |
| 180 | memcpy(client->ob_buf + client->ob_size, &hdr, sizeof(hdr)); | 184 | memcpy(client->ob_buf + client->ob_size, &hdr, sizeof(hdr)); |
| 181 | if(payload && payload_length) | 185 | if(payload && payload_length) |
| @@ -376,13 +380,6 @@ static int start_listen(struct mux_client *client) | |||
| 376 | devs = malloc(sizeof(struct device_info) * count); | 380 | devs = malloc(sizeof(struct device_info) * count); |
| 377 | count = device_get_list(0, devs); | 381 | count = device_get_list(0, devs); |
| 378 | 382 | ||
| 379 | // going to need a larger buffer for many devices | ||
| 380 | uint32_t needed_buffer = count * (sizeof(struct usbmuxd_device_record) + sizeof(struct usbmuxd_header)) + REPLY_BUF_SIZE; | ||
| 381 | if(client->ob_capacity < needed_buffer) { | ||
| 382 | usbmuxd_log(LL_DEBUG, "Enlarging client %d reply buffer %d -> %d to make space for device notifications", client->fd, client->ob_capacity, needed_buffer); | ||
| 383 | client->ob_buf = realloc(client->ob_buf, needed_buffer); | ||
| 384 | client->ob_capacity = needed_buffer; | ||
| 385 | } | ||
| 386 | dev = devs; | 383 | dev = devs; |
| 387 | for(i=0; i<count; i++) { | 384 | for(i=0; i<count; i++) { |
| 388 | if(notify_device_add(client, dev++) < 0) { | 385 | if(notify_device_add(client, dev++) < 0) { |
