diff options
-rw-r--r-- | testing/misc_tools.h | 12 | ||||
-rw-r--r-- | toxcore/Lossless_UDP.c | 13 |
2 files changed, 8 insertions, 17 deletions
diff --git a/testing/misc_tools.h b/testing/misc_tools.h index 3b71d8c4..272cca19 100644 --- a/testing/misc_tools.h +++ b/testing/misc_tools.h | |||
@@ -161,19 +161,9 @@ static inline void tox_array_pop(tox_array *arr, uint32_t num) | |||
161 | arr->data = realloc(arr->data, arr->elem_size*arr->len); | 161 | arr->data = realloc(arr->data, arr->elem_size*arr->len); |
162 | } | 162 | } |
163 | 163 | ||
164 | /* TODO: do not use type, since we track the needed info in | 164 | /* TODO: return ptr and do not take type */ |
165 | * elem_size (but array user will have to cast) | ||
166 | */ | ||
167 | #define tox_array_get(arr, i, type) (((type*)(arr)->data)[i]) | 165 | #define tox_array_get(arr, i, type) (((type*)(arr)->data)[i]) |
168 | 166 | ||
169 | /* This version requires C99 (declaring variables inside for loop) | ||
170 | #define tox_array_for_each(arr, type, tmp_name) \ | ||
171 | for ( \ | ||
172 | struct { type val; uint32_t i; } tmp_name = { tox_array_get(arr, 0, type), 0 }; \ | ||
173 | tmp_name.i != (arr)->len; \ | ||
174 | tmp_name.val = tox_array_get(arr, ++tmp_name.i, type) \ | ||
175 | ) | ||
176 | */ | ||
177 | 167 | ||
178 | #define tox_array_for_each(arr, type, tmp_name) \ | 168 | #define tox_array_for_each(arr, type, tmp_name) \ |
179 | type tmp_name; uint32_t tmp_name ## _i = 0; \ | 169 | type tmp_name; uint32_t tmp_name ## _i = 0; \ |
diff --git a/toxcore/Lossless_UDP.c b/toxcore/Lossless_UDP.c index d264a150..8ed25129 100644 --- a/toxcore/Lossless_UDP.c +++ b/toxcore/Lossless_UDP.c | |||
@@ -206,11 +206,13 @@ int incoming_connection(Lossless_UDP *ludp) | |||
206 | */ | 206 | */ |
207 | int kill_connection(Lossless_UDP *ludp, int connection_id) | 207 | int kill_connection(Lossless_UDP *ludp, int connection_id) |
208 | { | 208 | { |
209 | Connection* connection = &tox_array_get(&ludp->connections, connection_id, Connection); | ||
210 | |||
209 | if (connection_id >= 0 && connection_id < ludp->connections.len) { | 211 | if (connection_id >= 0 && connection_id < ludp->connections.len) { |
210 | if (tox_array_get(&ludp->connections, connection_id, Connection).status > 0) { | 212 | if (connection->status > 0) { |
211 | tox_array_get(&ludp->connections, connection_id, Connection).status = 0; | 213 | connection->status = 0; |
212 | change_handshake(ludp, tox_array_get(&ludp->connections, connection_id, Connection).ip_port); | 214 | change_handshake(ludp, connection->ip_port); |
213 | tox_array_pop(&ludp->connections, 0); | 215 | memset(connection, 0, sizeof(Connection)); |
214 | return 0; | 216 | return 0; |
215 | } | 217 | } |
216 | } | 218 | } |
@@ -320,9 +322,8 @@ int write_packet(Lossless_UDP *ludp, int connection_id, uint8_t *data, uint32_t | |||
320 | if (length > MAX_DATA_SIZE || length == 0) | 322 | if (length > MAX_DATA_SIZE || length == 0) |
321 | return 0; | 323 | return 0; |
322 | 324 | ||
323 | Connection *connection = &tox_array_get(&ludp->connections, connection_id, Connection); | ||
324 | |||
325 | if (sendqueue(ludp, connection_id) < BUFFER_PACKET_NUM) { | 325 | if (sendqueue(ludp, connection_id) < BUFFER_PACKET_NUM) { |
326 | Connection *connection = &tox_array_get(&ludp->connections, connection_id, Connection); | ||
326 | uint32_t index = connection->sendbuff_packetnum % MAX_QUEUE_NUM; | 327 | uint32_t index = connection->sendbuff_packetnum % MAX_QUEUE_NUM; |
327 | memcpy(connection->sendbuffer[index].data, data, length); | 328 | memcpy(connection->sendbuffer[index].data, data, length); |
328 | connection->sendbuffer[index].size = length; | 329 | connection->sendbuffer[index].size = length; |