diff options
Diffstat (limited to 'toxcore/TCP_server.c')
-rw-r--r-- | toxcore/TCP_server.c | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/toxcore/TCP_server.c b/toxcore/TCP_server.c index 15c2b45d..f3cdd287 100644 --- a/toxcore/TCP_server.c +++ b/toxcore/TCP_server.c | |||
@@ -317,20 +317,21 @@ static int send_pending_data_nonpriority(TCP_Secure_Connection *con) | |||
317 | static int send_pending_data(TCP_Secure_Connection *con) | 317 | static int send_pending_data(TCP_Secure_Connection *con) |
318 | { | 318 | { |
319 | /* finish sending current non-priority packet */ | 319 | /* finish sending current non-priority packet */ |
320 | if(send_pending_data_nonpriority(con) == -1) { | 320 | if (send_pending_data_nonpriority(con) == -1) { |
321 | return -1; | 321 | return -1; |
322 | } | 322 | } |
323 | 323 | ||
324 | TCP_Priority_List *p = con->priority_queue_start; | 324 | TCP_Priority_List *p = con->priority_queue_start; |
325 | 325 | ||
326 | while(p) { | 326 | while (p) { |
327 | uint16_t left = p->size - p->sent; | 327 | uint16_t left = p->size - p->sent; |
328 | int len = send(con->sock, p->data + p->sent, left, MSG_NOSIGNAL); | 328 | int len = send(con->sock, p->data + p->sent, left, MSG_NOSIGNAL); |
329 | 329 | ||
330 | if(len != left) { | 330 | if (len != left) { |
331 | if(len > 0) { | 331 | if (len > 0) { |
332 | p->sent += len; | 332 | p->sent += len; |
333 | } | 333 | } |
334 | |||
334 | break; | 335 | break; |
335 | } | 336 | } |
336 | 337 | ||
@@ -340,7 +341,8 @@ static int send_pending_data(TCP_Secure_Connection *con) | |||
340 | } | 341 | } |
341 | 342 | ||
342 | con->priority_queue_start = p; | 343 | con->priority_queue_start = p; |
343 | if(!p) { | 344 | |
345 | if (!p) { | ||
344 | con->priority_queue_end = NULL; | 346 | con->priority_queue_end = NULL; |
345 | return 0; | 347 | return 0; |
346 | } | 348 | } |
@@ -355,7 +357,8 @@ static _Bool add_priority(TCP_Secure_Connection *con, const uint8_t *packet, uin | |||
355 | { | 357 | { |
356 | TCP_Priority_List *p = con->priority_queue_end, *new; | 358 | TCP_Priority_List *p = con->priority_queue_end, *new; |
357 | new = malloc(sizeof(TCP_Priority_List) + size); | 359 | new = malloc(sizeof(TCP_Priority_List) + size); |
358 | if(!new) { | 360 | |
361 | if (!new) { | ||
359 | return 0; | 362 | return 0; |
360 | } | 363 | } |
361 | 364 | ||
@@ -364,7 +367,7 @@ static _Bool add_priority(TCP_Secure_Connection *con, const uint8_t *packet, uin | |||
364 | new->sent = sent; | 367 | new->sent = sent; |
365 | memcpy(new->data, packet, size); | 368 | memcpy(new->data, packet, size); |
366 | 369 | ||
367 | if(p) { | 370 | if (p) { |
368 | p->next = new; | 371 | p->next = new; |
369 | } else { | 372 | } else { |
370 | con->priority_queue_start = new; | 373 | con->priority_queue_start = new; |
@@ -378,12 +381,14 @@ static _Bool add_priority(TCP_Secure_Connection *con, const uint8_t *packet, uin | |||
378 | * return 0 if could not send packet. | 381 | * return 0 if could not send packet. |
379 | * return -1 on failure (connection must be killed). | 382 | * return -1 on failure (connection must be killed). |
380 | */ | 383 | */ |
381 | static int write_packet_TCP_secure_connection(TCP_Secure_Connection *con, const uint8_t *data, uint16_t length, _Bool priority) | 384 | static int write_packet_TCP_secure_connection(TCP_Secure_Connection *con, const uint8_t *data, uint16_t length, |
385 | _Bool priority) | ||
382 | { | 386 | { |
383 | if (length + crypto_box_MACBYTES > MAX_PACKET_SIZE) | 387 | if (length + crypto_box_MACBYTES > MAX_PACKET_SIZE) |
384 | return -1; | 388 | return -1; |
385 | 389 | ||
386 | _Bool sendpriority = 1; | 390 | _Bool sendpriority = 1; |
391 | |||
387 | if (send_pending_data(con) == -1) { | 392 | if (send_pending_data(con) == -1) { |
388 | if (priority) { | 393 | if (priority) { |
389 | sendpriority = 0; | 394 | sendpriority = 0; |
@@ -403,13 +408,14 @@ static int write_packet_TCP_secure_connection(TCP_Secure_Connection *con, const | |||
403 | 408 | ||
404 | if (priority) { | 409 | if (priority) { |
405 | len = sendpriority ? send(con->sock, packet, sizeof(packet), MSG_NOSIGNAL) : 0; | 410 | len = sendpriority ? send(con->sock, packet, sizeof(packet), MSG_NOSIGNAL) : 0; |
406 | if(len <= 0) { | 411 | |
412 | if (len <= 0) { | ||
407 | len = 0; | 413 | len = 0; |
408 | } else { | 414 | } else { |
409 | increment_nonce(con->sent_nonce); | 415 | increment_nonce(con->sent_nonce); |
410 | } | 416 | } |
411 | 417 | ||
412 | if(len == sizeof(packet)) { | 418 | if (len == sizeof(packet)) { |
413 | return 1; | 419 | return 1; |
414 | } | 420 | } |
415 | 421 | ||