diff options
| author | 2009-10-30 15:57:55 +0100 | |
|---|---|---|
| committer | 2009-11-05 20:46:47 -0800 | |
| commit | 748167d15c7848ec1a814e3c4f429f3a05714918 (patch) | |
| tree | 0b8523b2af842e29f928e3e3d3420112ad15aac2 /src/AFC.c | |
| parent | 94f77f6a4dbea03a1bca8aa55097638927591a5a (diff) | |
| download | libimobiledevice-748167d15c7848ec1a814e3c4f429f3a05714918.tar.gz libimobiledevice-748167d15c7848ec1a814e3c4f429f3a05714918.tar.bz2 | |
afc_dispatch_packet optimization: remove additional buffer
This patch removes the additional buffer that was used inside
afc_dispatch_packet. So instead of 'alloc, copy header, copy data, send,
free' it will now simply do 'send header, send data'. This should reduce
cpu usage.
Diffstat (limited to 'src/AFC.c')
| -rw-r--r-- | src/AFC.c | 49 |
1 files changed, 29 insertions, 20 deletions
| @@ -130,7 +130,7 @@ afc_error_t afc_client_free(afc_client_t client) | |||
| 130 | static int afc_dispatch_packet(afc_client_t client, const char *data, uint64_t length) | 130 | static int afc_dispatch_packet(afc_client_t client, const char *data, uint64_t length) |
| 131 | { | 131 | { |
| 132 | int bytes = 0, offset = 0; | 132 | int bytes = 0, offset = 0; |
| 133 | char *buffer; | 133 | uint32_t sent = 0; |
| 134 | 134 | ||
| 135 | if (!client || !client->connection || !client->afc_packet) | 135 | if (!client || !client->connection || !client->afc_packet) |
| 136 | return 0; | 136 | return 0; |
| @@ -150,8 +150,6 @@ static int afc_dispatch_packet(afc_client_t client, const char *data, uint64_t l | |||
| 150 | // this_length is the parameters | 150 | // this_length is the parameters |
| 151 | // And everything beyond that is the next packet. (for writing) | 151 | // And everything beyond that is the next packet. (for writing) |
| 152 | if (client->afc_packet->this_length != client->afc_packet->entire_length) { | 152 | if (client->afc_packet->this_length != client->afc_packet->entire_length) { |
| 153 | buffer = (char *) malloc(client->afc_packet->this_length); | ||
| 154 | memcpy(buffer, (char *) client->afc_packet, sizeof(AFCPacket)); | ||
| 155 | offset = client->afc_packet->this_length - sizeof(AFCPacket); | 153 | offset = client->afc_packet->this_length - sizeof(AFCPacket); |
| 156 | 154 | ||
| 157 | log_debug_msg("%s: Offset: %i\n", __func__, offset); | 155 | log_debug_msg("%s: Offset: %i\n", __func__, offset); |
| @@ -160,39 +158,50 @@ static int afc_dispatch_packet(afc_client_t client, const char *data, uint64_t l | |||
| 160 | log_debug_msg("to based on the packet.\n"); | 158 | log_debug_msg("to based on the packet.\n"); |
| 161 | log_debug_msg("%s: length minus offset: %i\n", __func__, length - offset); | 159 | log_debug_msg("%s: length minus offset: %i\n", __func__, length - offset); |
| 162 | log_debug_msg("%s: rest of packet: %i\n", __func__, client->afc_packet->entire_length - client->afc_packet->this_length); | 160 | log_debug_msg("%s: rest of packet: %i\n", __func__, client->afc_packet->entire_length - client->afc_packet->this_length); |
| 163 | free(buffer); | ||
| 164 | return -1; | 161 | return -1; |
| 165 | } | 162 | } |
| 166 | memcpy(buffer + sizeof(AFCPacket), data, offset); | 163 | |
| 167 | iphone_device_send(client->connection, buffer, client->afc_packet->this_length, (uint32_t*)&bytes); | 164 | iphone_device_send(client->connection, (void*)client->afc_packet, sizeof(AFCPacket), &sent); |
| 168 | free(buffer); | 165 | if (sent == 0) { |
| 169 | if (bytes <= 0) { | ||
| 170 | return bytes; | 166 | return bytes; |
| 171 | } | 167 | } |
| 168 | bytes += sent; | ||
| 169 | |||
| 170 | iphone_device_send(client->connection, data, offset, &sent); | ||
| 171 | if (sent == 0) { | ||
| 172 | return bytes; | ||
| 173 | } | ||
| 174 | bytes += sent; | ||
| 172 | 175 | ||
| 173 | log_debug_msg("%s: sent the first now go with the second\n", __func__); | 176 | log_debug_msg("%s: sent the first now go with the second\n", __func__); |
| 174 | log_debug_msg("%s: Length: %i\n", __func__, length - offset); | 177 | log_debug_msg("%s: Length: %i\n", __func__, length - offset); |
| 175 | log_debug_msg("%s: Buffer: \n", __func__); | 178 | log_debug_msg("%s: Buffer: \n", __func__); |
| 176 | log_debug_buffer(data + offset, length - offset); | 179 | log_debug_buffer(data + offset, length - offset); |
| 177 | 180 | ||
| 178 | iphone_device_send(client->connection, data + offset, length - offset, (uint32_t*)&bytes); | 181 | sent = 0; |
| 182 | iphone_device_send(client->connection, data + offset, length - offset, &sent); | ||
| 183 | |||
| 184 | bytes = sent; | ||
| 179 | return bytes; | 185 | return bytes; |
| 180 | } else { | 186 | } else { |
| 181 | log_debug_msg("%s: doin things the old way\n", __func__); | 187 | log_debug_msg("%s: doin things the old way\n", __func__); |
| 182 | buffer = (char *) malloc(sizeof(char) * client->afc_packet->this_length); | ||
| 183 | log_debug_msg("%s: packet length = %i\n", __func__, client->afc_packet->this_length); | 188 | log_debug_msg("%s: packet length = %i\n", __func__, client->afc_packet->this_length); |
| 184 | memcpy(buffer, (char *) client->afc_packet, sizeof(AFCPacket)); | 189 | |
| 185 | log_debug_msg("%s: packet data follows\n", __func__); | 190 | log_debug_buffer((char*)client->afc_packet, sizeof(AFCPacket)); |
| 186 | if (length > 0) { | ||
| 187 | memcpy(buffer + sizeof(AFCPacket), data, length); | ||
| 188 | } | ||
| 189 | log_debug_buffer(buffer, client->afc_packet->this_length); | ||
| 190 | log_debug_msg("\n"); | 191 | log_debug_msg("\n"); |
| 191 | iphone_device_send(client->connection, buffer, client->afc_packet->this_length, (uint32_t*)&bytes); | ||
| 192 | 192 | ||
| 193 | if (buffer) { | 193 | iphone_device_send(client->connection, (void*)client->afc_packet, sizeof(AFCPacket), &sent); |
| 194 | free(buffer); | 194 | if (sent == 0) { |
| 195 | buffer = NULL; | 195 | return bytes; |
| 196 | } | ||
| 197 | bytes += sent; | ||
| 198 | if (length > 0) { | ||
| 199 | log_debug_msg("%s: packet data follows\n", __func__); | ||
| 200 | |||
| 201 | log_debug_buffer(data, length); | ||
| 202 | log_debug_msg("\n"); | ||
| 203 | iphone_device_send(client->connection, data, length, &sent); | ||
| 204 | bytes += sent; | ||
| 196 | } | 205 | } |
| 197 | return bytes; | 206 | return bytes; |
| 198 | } | 207 | } |
