summaryrefslogtreecommitdiff
path: root/toxcore/TCP_client.c
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/TCP_client.c')
-rw-r--r--toxcore/TCP_client.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/toxcore/TCP_client.c b/toxcore/TCP_client.c
index 4aed0ff5..02d4e7dc 100644
--- a/toxcore/TCP_client.c
+++ b/toxcore/TCP_client.c
@@ -137,20 +137,21 @@ static int send_pending_data_nonpriority(TCP_Client_Connection *con)
137static int send_pending_data(TCP_Client_Connection *con) 137static int send_pending_data(TCP_Client_Connection *con)
138{ 138{
139 /* finish sending current non-priority packet */ 139 /* finish sending current non-priority packet */
140 if(send_pending_data_nonpriority(con) == -1) { 140 if (send_pending_data_nonpriority(con) == -1) {
141 return -1; 141 return -1;
142 } 142 }
143 143
144 TCP_Priority_List *p = con->priority_queue_start; 144 TCP_Priority_List *p = con->priority_queue_start;
145 145
146 while(p) { 146 while (p) {
147 uint16_t left = p->size - p->sent; 147 uint16_t left = p->size - p->sent;
148 int len = send(con->sock, p->data + p->sent, left, MSG_NOSIGNAL); 148 int len = send(con->sock, p->data + p->sent, left, MSG_NOSIGNAL);
149 149
150 if(len != left) { 150 if (len != left) {
151 if(len > 0) { 151 if (len > 0) {
152 p->sent += len; 152 p->sent += len;
153 } 153 }
154
154 break; 155 break;
155 } 156 }
156 157
@@ -160,7 +161,8 @@ static int send_pending_data(TCP_Client_Connection *con)
160 } 161 }
161 162
162 con->priority_queue_start = p; 163 con->priority_queue_start = p;
163 if(!p) { 164
165 if (!p) {
164 con->priority_queue_end = NULL; 166 con->priority_queue_end = NULL;
165 return 0; 167 return 0;
166 } 168 }
@@ -175,7 +177,8 @@ static _Bool add_priority(TCP_Client_Connection *con, const uint8_t *packet, uin
175{ 177{
176 TCP_Priority_List *p = con->priority_queue_end, *new; 178 TCP_Priority_List *p = con->priority_queue_end, *new;
177 new = malloc(sizeof(TCP_Priority_List) + size); 179 new = malloc(sizeof(TCP_Priority_List) + size);
178 if(!new) { 180
181 if (!new) {
179 return 0; 182 return 0;
180 } 183 }
181 184
@@ -184,7 +187,7 @@ static _Bool add_priority(TCP_Client_Connection *con, const uint8_t *packet, uin
184 new->sent = sent; 187 new->sent = sent;
185 memcpy(new->data, packet, size); 188 memcpy(new->data, packet, size);
186 189
187 if(p) { 190 if (p) {
188 p->next = new; 191 p->next = new;
189 } else { 192 } else {
190 con->priority_queue_start = new; 193 con->priority_queue_start = new;
@@ -198,12 +201,14 @@ static _Bool add_priority(TCP_Client_Connection *con, const uint8_t *packet, uin
198 * return 0 if could not send packet. 201 * return 0 if could not send packet.
199 * return -1 on failure (connection must be killed). 202 * return -1 on failure (connection must be killed).
200 */ 203 */
201static int write_packet_TCP_secure_connection(TCP_Client_Connection *con, const uint8_t *data, uint16_t length, _Bool priority) 204static int write_packet_TCP_secure_connection(TCP_Client_Connection *con, const uint8_t *data, uint16_t length,
205 _Bool priority)
202{ 206{
203 if (length + crypto_box_MACBYTES > MAX_PACKET_SIZE) 207 if (length + crypto_box_MACBYTES > MAX_PACKET_SIZE)
204 return -1; 208 return -1;
205 209
206 _Bool sendpriority = 1; 210 _Bool sendpriority = 1;
211
207 if (send_pending_data(con) == -1) { 212 if (send_pending_data(con) == -1) {
208 if (priority) { 213 if (priority) {
209 sendpriority = 0; 214 sendpriority = 0;
@@ -223,13 +228,14 @@ static int write_packet_TCP_secure_connection(TCP_Client_Connection *con, const
223 228
224 if (priority) { 229 if (priority) {
225 len = sendpriority ? send(con->sock, packet, sizeof(packet), MSG_NOSIGNAL) : 0; 230 len = sendpriority ? send(con->sock, packet, sizeof(packet), MSG_NOSIGNAL) : 0;
226 if(len <= 0) { 231
232 if (len <= 0) {
227 len = 0; 233 len = 0;
228 } else { 234 } else {
229 increment_nonce(con->sent_nonce); 235 increment_nonce(con->sent_nonce);
230 } 236 }
231 237
232 if(len == sizeof(packet)) { 238 if (len == sizeof(packet)) {
233 return 1; 239 return 1;
234 } 240 }
235 241