summaryrefslogtreecommitdiff
path: root/toxcore
diff options
context:
space:
mode:
authornotsecure <notsecure@marek.ca>2014-07-15 18:22:04 -0400
committernotsecure <notsecure@marek.ca>2014-07-15 18:22:04 -0400
commit96249e8b020c76e9f80da6538ea19699612479dc (patch)
tree331c478de72556d761068238be90c2043fa4dc53 /toxcore
parent22d28ddf36563e2d0018fc20cafdfe61278dd67f (diff)
fixed some issues
Diffstat (limited to 'toxcore')
-rw-r--r--toxcore/TCP_server.c46
1 files changed, 24 insertions, 22 deletions
diff --git a/toxcore/TCP_server.c b/toxcore/TCP_server.c
index 8b7d5fdd..15c2b45d 100644
--- a/toxcore/TCP_server.c
+++ b/toxcore/TCP_server.c
@@ -288,7 +288,7 @@ int read_packet_TCP_secure_connection(sock_t sock, uint16_t *next_packet_length,
288/* return 0 if pending data was sent completely 288/* return 0 if pending data was sent completely
289 * return -1 if it wasn't 289 * return -1 if it wasn't
290 */ 290 */
291static int send_pending_data(TCP_Secure_Connection *con) 291static int send_pending_data_nonpriority(TCP_Secure_Connection *con)
292{ 292{
293 if (con->last_packet_length == 0) { 293 if (con->last_packet_length == 0) {
294 return 0; 294 return 0;
@@ -314,8 +314,13 @@ static int send_pending_data(TCP_Secure_Connection *con)
314/* return 0 if pending data was sent completely 314/* return 0 if pending data was sent completely
315 * return -1 if it wasn't 315 * return -1 if it wasn't
316 */ 316 */
317static int send_pending_data_priority(TCP_Secure_Connection *con) 317static int send_pending_data(TCP_Secure_Connection *con)
318{ 318{
319 /* finish sending current non-priority packet */
320 if(send_pending_data_nonpriority(con) == -1) {
321 return -1;
322 }
323
319 TCP_Priority_List *p = con->priority_queue_start; 324 TCP_Priority_List *p = con->priority_queue_start;
320 325
321 while(p) { 326 while(p) {
@@ -346,16 +351,8 @@ static int send_pending_data_priority(TCP_Secure_Connection *con)
346/* return 0 on failure (only if malloc fails) 351/* return 0 on failure (only if malloc fails)
347 * return 1 on success 352 * return 1 on success
348 */ 353 */
349static _Bool add_priority(TCP_Secure_Connection *con, const uint8_t *packet, uint16_t size, int sent) 354static _Bool add_priority(TCP_Secure_Connection *con, const uint8_t *packet, uint16_t size, uint16_t sent)
350{ 355{
351 if(sent == size) {
352 return 1;
353 }
354
355 if(sent <= 0) {
356 sent = 0;
357 }
358
359 TCP_Priority_List *p = con->priority_queue_end, *new; 356 TCP_Priority_List *p = con->priority_queue_end, *new;
360 new = malloc(sizeof(TCP_Priority_List) + size); 357 new = malloc(sizeof(TCP_Priority_List) + size);
361 if(!new) { 358 if(!new) {
@@ -387,7 +384,7 @@ static int write_packet_TCP_secure_connection(TCP_Secure_Connection *con, const
387 return -1; 384 return -1;
388 385
389 _Bool sendpriority = 1; 386 _Bool sendpriority = 1;
390 if (send_pending_data_priority(con) == -1) { 387 if (send_pending_data(con) == -1) {
391 if (priority) { 388 if (priority) {
392 sendpriority = 0; 389 sendpriority = 0;
393 } else { 390 } else {
@@ -401,15 +398,23 @@ static int write_packet_TCP_secure_connection(TCP_Secure_Connection *con, const
401 memcpy(packet, &c_length, sizeof(uint16_t)); 398 memcpy(packet, &c_length, sizeof(uint16_t));
402 int len = encrypt_data_symmetric(con->shared_key, con->sent_nonce, data, length, packet + sizeof(uint16_t)); 399 int len = encrypt_data_symmetric(con->shared_key, con->sent_nonce, data, length, packet + sizeof(uint16_t));
403 400
401 if ((unsigned int)len != (sizeof(packet) - sizeof(uint16_t)))
402 return -1;
403
404 if (priority) { 404 if (priority) {
405 return add_priority(con, packet, sizeof(packet), sendpriority ? send(con->sock, packet, sizeof(packet), MSG_NOSIGNAL) : 0); 405 len = sendpriority ? send(con->sock, packet, sizeof(packet), MSG_NOSIGNAL) : 0;
406 } 406 if(len <= 0) {
407 len = 0;
408 } else {
409 increment_nonce(con->sent_nonce);
410 }
407 411
408 if (send_pending_data(con) == -1) 412 if(len == sizeof(packet)) {
409 return 0; 413 return 1;
414 }
410 415
411 if ((unsigned int)len != (sizeof(packet) - sizeof(uint16_t))) 416 return add_priority(con, packet, sizeof(packet), len);
412 return -1; 417 }
413 418
414 len = send(con->sock, packet, sizeof(packet), MSG_NOSIGNAL); 419 len = send(con->sock, packet, sizeof(packet), MSG_NOSIGNAL);
415 420
@@ -1152,10 +1157,7 @@ static void do_TCP_confirmed(TCP_Server *TCP_server)
1152 continue; 1157 continue;
1153 } 1158 }
1154 1159
1155 /* try sending queued priority packets first */ 1160 send_pending_data(conn);
1156 if(send_pending_data_priority(conn) == 0) {
1157 send_pending_data(conn);
1158 }
1159 1161
1160#ifndef TCP_SERVER_USE_EPOLL 1162#ifndef TCP_SERVER_USE_EPOLL
1161 1163