From 2fdc412e364fc67fc54a48b1da816b380117ddd5 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Thu, 24 Oct 2013 16:37:39 -0400 Subject: [PATCH] Astyled some files. --- toxcore/Lossless_UDP.c | 3 ++- toxcore/misc_tools.h | 16 ++++++++-------- toxcore/network.c | 25 +++++++++++++++---------- toxcore/ping.h | 2 +- toxcore/util.c | 2 +- toxcore/util.h | 2 +- 6 files changed, 28 insertions(+), 22 deletions(-) diff --git a/toxcore/Lossless_UDP.c b/toxcore/Lossless_UDP.c index e291340d..04533a3b 100644 --- a/toxcore/Lossless_UDP.c +++ b/toxcore/Lossless_UDP.c @@ -455,8 +455,9 @@ uint32_t sendqueue_total(Lossless_UDP *ludp) { uint32_t i, total = 0; - for(i = 0; i < ludp->connections.len; i++) { + for (i = 0; i < ludp->connections.len; i++) { Connection *connection = &tox_array_get(&ludp->connections, i, Connection); + if (connection->status != 0) total += connection->sendbuff_packetnum - connection->successful_sent; } diff --git a/toxcore/misc_tools.h b/toxcore/misc_tools.h index 5fd0cb7a..4bf28ac7 100644 --- a/toxcore/misc_tools.h +++ b/toxcore/misc_tools.h @@ -89,7 +89,7 @@ int main() { tox_list_t head; tox_list_new(&head); //initialize head - + //input a new character, until user enters q or e char c = '\0'; while (c != 'q' && c != 'e') { @@ -98,16 +98,16 @@ int main() tmp->c = c; tox_list_add(&head, &tmp->tox_lst); //add it to the list } - + TOX_LIST_FOR_EACH() takes a struct tox_list and a name for a temporary pointer to use in the loop. - + TOX_LIST_GET_VALUE() uses magic to return an instance of a structure that contains tox_list_t. You have to give it a temporary tox_string_t, name of tox_list_t member inside our structure (tox_lst), and the type of structure to return. - + TOX_LIST_FOR_EACH(head, tmp) printf("%c", TOX_LIST_GET_VALUE(*tmp, tox_lst, tox_string_t).c); - + TOX_LIST_FOR_EACH(head, tmp) { if (TOX_LIST_GET_VALUE(*tmp, tox_lst, tox_string_t).c == 'z') { //If you delete tmp, you have to quit the loop, or it will go on infinitly. @@ -116,12 +116,12 @@ and the type of structure to return. break; } } - + printf("\n"); TOX_LIST_FOR_EACH(head, tmp) printf("%c", TOX_LIST_GET_VALUE(*tmp, tox_lst, tox_string_t).c); - - + + return 0; } */ diff --git a/toxcore/network.c b/toxcore/network.c index 53511df6..640311b3 100644 --- a/toxcore/network.c +++ b/toxcore/network.c @@ -20,10 +20,10 @@ * along with Tox. If not, see . * */ - + #if (_WIN32_WINNT >= _WIN32_WINNT_WINXP) -#define _WIN32_WINNT 0x501 -#endif +#define _WIN32_WINNT 0x501 +#endif #ifdef HAVE_CONFIG_H #include "config.h" @@ -371,13 +371,15 @@ int networking_wait_execute(uint8_t *data, uint16_t len, uint16_t milliseconds) /* returns -1 on error, 0 on timeout, the socket on activity */ int res = select(nfds, &readfds, &writefds, &exceptfds, &timeout); #ifdef LOGGING + /* only dump if not timeout */ if (res) { sprintf(logbuffer, "select(%d): %d (%d, %s) - %d %d %d\n", milliseconds, res, errno, - strerror(errno), FD_ISSET(s->sock, &readfds), FD_ISSET(s->sock, &writefds), - FD_ISSET(s->sock, &exceptfds)); + strerror(errno), FD_ISSET(s->sock, &readfds), FD_ISSET(s->sock, &writefds), + FD_ISSET(s->sock, &exceptfds)); loglog(logbuffer); } + #endif if (FD_ISSET(s->sock, &writefds)) @@ -525,14 +527,14 @@ Networking_Core *new_networking(IP ip, uint16_t port) } else return NULL; - if (ip.family == AF_INET6) - { + if (ip.family == AF_INET6) { char ipv6only = 0; socklen_t optsize = sizeof(ipv6only); #ifdef LOGGING errno = 0; #endif int res = getsockopt(temp->sock, IPPROTO_IPV6, IPV6_V6ONLY, &ipv6only, &optsize); + if ((res == 0) && (ipv6only == 0)) { #ifdef LOGGING loglog("Dual-stack socket: enabled per default.\n"); @@ -540,6 +542,7 @@ Networking_Core *new_networking(IP ip, uint16_t port) } else { ipv6only = 0; #ifdef LOGGING + if (res < 0) { sprintf(logbuffer, "Dual-stack socket: Failed to query default. (%d, %s)\n", errno, strerror(errno)); @@ -549,8 +552,9 @@ Networking_Core *new_networking(IP ip, uint16_t port) errno = 0; res = #endif - setsockopt(temp->sock, IPPROTO_IPV6, IPV6_V6ONLY, (char *)&ipv6only, sizeof(ipv6only)); + setsockopt(temp->sock, IPPROTO_IPV6, IPV6_V6ONLY, (char *)&ipv6only, sizeof(ipv6only)); #ifdef LOGGING + if (res < 0) { sprintf(logbuffer, "Dual-stack socket: Failed to enable, won't be able to receive from/send to IPv4 addresses. (%u, %s)\n", @@ -558,6 +562,7 @@ Networking_Core *new_networking(IP ip, uint16_t port) loglog(logbuffer); } else loglog("Dual-stack socket: Enabled successfully.\n"); + #endif } @@ -605,8 +610,7 @@ Networking_Core *new_networking(IP ip, uint16_t port) *portptr = htons(port_to_try); int tries, res; - for (tries = TOX_PORTRANGE_FROM; tries <= TOX_PORTRANGE_TO; tries++) - { + for (tries = TOX_PORTRANGE_FROM; tries <= TOX_PORTRANGE_TO; tries++) { res = bind(temp->sock, (struct sockaddr *)&addr, addrsize); if (!res) { @@ -674,6 +678,7 @@ int ip_equal(IP *a, IP *b) else if (a->family == AF_INET6) #ifdef WIN32 return IN6_ADDR_EQUAL(&a->ip6.in6_addr, &b->ip6.in6_addr); + #else return IN6_ARE_ADDR_EQUAL(&a->ip6.in6_addr, &b->ip6.in6_addr); #endif diff --git a/toxcore/ping.h b/toxcore/ping.h index 32742401..c2437e1b 100644 --- a/toxcore/ping.h +++ b/toxcore/ping.h @@ -3,7 +3,7 @@ * * This file is donated to the Tox Project. * Copyright 2013 plutooo - * + * * Copyright (C) 2013 Tox project All Rights Reserved. * * This file is part of Tox. diff --git a/toxcore/util.c b/toxcore/util.c index 576972b4..620d1f4f 100644 --- a/toxcore/util.c +++ b/toxcore/util.c @@ -3,7 +3,7 @@ * * This file is donated to the Tox Project. * Copyright 2013 plutooo - * + * * Copyright (C) 2013 Tox project All Rights Reserved. * * This file is part of Tox. diff --git a/toxcore/util.h b/toxcore/util.h index f7b30693..97f82f60 100644 --- a/toxcore/util.h +++ b/toxcore/util.h @@ -3,7 +3,7 @@ * * This file is donated to the Tox Project. * Copyright 2013 plutooo - * + * * Copyright (C) 2013 Tox project All Rights Reserved. * * This file is part of Tox.