Netservices modded to read fragmented HTTP respsonse/payload from special purpose server - 180 bytes only

Committer:
RodColeman
Date:
Thu Sep 08 10:41:36 2011 +0000
Revision:
0:8f5825f330b0
setDataLen hacked to 180bytes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RodColeman 0:8f5825f330b0 1 /**
RodColeman 0:8f5825f330b0 2 * @file
RodColeman 0:8f5825f330b0 3 * Stack-internal timers implementation.
RodColeman 0:8f5825f330b0 4 * This file includes timer callbacks for stack-internal timers as well as
RodColeman 0:8f5825f330b0 5 * functions to set up or stop timers and check for expired timers.
RodColeman 0:8f5825f330b0 6 *
RodColeman 0:8f5825f330b0 7 */
RodColeman 0:8f5825f330b0 8
RodColeman 0:8f5825f330b0 9 /*
RodColeman 0:8f5825f330b0 10 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
RodColeman 0:8f5825f330b0 11 * All rights reserved.
RodColeman 0:8f5825f330b0 12 *
RodColeman 0:8f5825f330b0 13 * Redistribution and use in source and binary forms, with or without modification,
RodColeman 0:8f5825f330b0 14 * are permitted provided that the following conditions are met:
RodColeman 0:8f5825f330b0 15 *
RodColeman 0:8f5825f330b0 16 * 1. Redistributions of source code must retain the above copyright notice,
RodColeman 0:8f5825f330b0 17 * this list of conditions and the following disclaimer.
RodColeman 0:8f5825f330b0 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
RodColeman 0:8f5825f330b0 19 * this list of conditions and the following disclaimer in the documentation
RodColeman 0:8f5825f330b0 20 * and/or other materials provided with the distribution.
RodColeman 0:8f5825f330b0 21 * 3. The name of the author may not be used to endorse or promote products
RodColeman 0:8f5825f330b0 22 * derived from this software without specific prior written permission.
RodColeman 0:8f5825f330b0 23 *
RodColeman 0:8f5825f330b0 24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
RodColeman 0:8f5825f330b0 25 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
RodColeman 0:8f5825f330b0 26 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
RodColeman 0:8f5825f330b0 27 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
RodColeman 0:8f5825f330b0 28 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
RodColeman 0:8f5825f330b0 29 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
RodColeman 0:8f5825f330b0 30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
RodColeman 0:8f5825f330b0 31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
RodColeman 0:8f5825f330b0 32 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
RodColeman 0:8f5825f330b0 33 * OF SUCH DAMAGE.
RodColeman 0:8f5825f330b0 34 *
RodColeman 0:8f5825f330b0 35 * This file is part of the lwIP TCP/IP stack.
RodColeman 0:8f5825f330b0 36 *
RodColeman 0:8f5825f330b0 37 * Author: Adam Dunkels <adam@sics.se>
RodColeman 0:8f5825f330b0 38 * Simon Goldschmidt
RodColeman 0:8f5825f330b0 39 *
RodColeman 0:8f5825f330b0 40 */
RodColeman 0:8f5825f330b0 41
RodColeman 0:8f5825f330b0 42 #include "lwip/opt.h"
RodColeman 0:8f5825f330b0 43
RodColeman 0:8f5825f330b0 44 #include "lwip/timers.h"
RodColeman 0:8f5825f330b0 45
RodColeman 0:8f5825f330b0 46 #if LWIP_TIMERS
RodColeman 0:8f5825f330b0 47
RodColeman 0:8f5825f330b0 48 #include "lwip/def.h"
RodColeman 0:8f5825f330b0 49 #include "lwip/memp.h"
RodColeman 0:8f5825f330b0 50 #include "lwip/tcpip.h"
RodColeman 0:8f5825f330b0 51
RodColeman 0:8f5825f330b0 52 #include "lwip/tcp_impl.h"
RodColeman 0:8f5825f330b0 53 #include "lwip/ip_frag.h"
RodColeman 0:8f5825f330b0 54 #include "netif/etharp.h"
RodColeman 0:8f5825f330b0 55 #include "lwip/dhcp.h"
RodColeman 0:8f5825f330b0 56 #include "lwip/autoip.h"
RodColeman 0:8f5825f330b0 57 #include "lwip/igmp.h"
RodColeman 0:8f5825f330b0 58 #include "lwip/dns.h"
RodColeman 0:8f5825f330b0 59
RodColeman 0:8f5825f330b0 60
RodColeman 0:8f5825f330b0 61 /** The one and only timeout list */
RodColeman 0:8f5825f330b0 62 static struct sys_timeo *next_timeout;
RodColeman 0:8f5825f330b0 63 #if NO_SYS
RodColeman 0:8f5825f330b0 64 static u32_t timeouts_last_time;
RodColeman 0:8f5825f330b0 65 #endif /* NO_SYS */
RodColeman 0:8f5825f330b0 66
RodColeman 0:8f5825f330b0 67 #if LWIP_TCP
RodColeman 0:8f5825f330b0 68 /** global variable that shows if the tcp timer is currently scheduled or not */
RodColeman 0:8f5825f330b0 69 static int tcpip_tcp_timer_active;
RodColeman 0:8f5825f330b0 70
RodColeman 0:8f5825f330b0 71 /**
RodColeman 0:8f5825f330b0 72 * Timer callback function that calls tcp_tmr() and reschedules itself.
RodColeman 0:8f5825f330b0 73 *
RodColeman 0:8f5825f330b0 74 * @param arg unused argument
RodColeman 0:8f5825f330b0 75 */
RodColeman 0:8f5825f330b0 76 static void
RodColeman 0:8f5825f330b0 77 tcpip_tcp_timer(void *arg)
RodColeman 0:8f5825f330b0 78 {
RodColeman 0:8f5825f330b0 79 LWIP_UNUSED_ARG(arg);
RodColeman 0:8f5825f330b0 80
RodColeman 0:8f5825f330b0 81 /* call TCP timer handler */
RodColeman 0:8f5825f330b0 82 tcp_tmr();
RodColeman 0:8f5825f330b0 83 /* timer still needed? */
RodColeman 0:8f5825f330b0 84 if (tcp_active_pcbs || tcp_tw_pcbs) {
RodColeman 0:8f5825f330b0 85 /* restart timer */
RodColeman 0:8f5825f330b0 86 sys_timeout(TCP_TMR_INTERVAL, tcpip_tcp_timer, NULL);
RodColeman 0:8f5825f330b0 87 } else {
RodColeman 0:8f5825f330b0 88 /* disable timer */
RodColeman 0:8f5825f330b0 89 tcpip_tcp_timer_active = 0;
RodColeman 0:8f5825f330b0 90 }
RodColeman 0:8f5825f330b0 91 }
RodColeman 0:8f5825f330b0 92
RodColeman 0:8f5825f330b0 93 /**
RodColeman 0:8f5825f330b0 94 * Called from TCP_REG when registering a new PCB:
RodColeman 0:8f5825f330b0 95 * the reason is to have the TCP timer only running when
RodColeman 0:8f5825f330b0 96 * there are active (or time-wait) PCBs.
RodColeman 0:8f5825f330b0 97 */
RodColeman 0:8f5825f330b0 98 void
RodColeman 0:8f5825f330b0 99 tcp_timer_needed(void)
RodColeman 0:8f5825f330b0 100 {
RodColeman 0:8f5825f330b0 101 /* timer is off but needed again? */
RodColeman 0:8f5825f330b0 102 if (!tcpip_tcp_timer_active && (tcp_active_pcbs || tcp_tw_pcbs)) {
RodColeman 0:8f5825f330b0 103 /* enable and start timer */
RodColeman 0:8f5825f330b0 104 tcpip_tcp_timer_active = 1;
RodColeman 0:8f5825f330b0 105 sys_timeout(TCP_TMR_INTERVAL, tcpip_tcp_timer, NULL);
RodColeman 0:8f5825f330b0 106 }
RodColeman 0:8f5825f330b0 107 }
RodColeman 0:8f5825f330b0 108 #endif /* LWIP_TCP */
RodColeman 0:8f5825f330b0 109
RodColeman 0:8f5825f330b0 110 #if IP_REASSEMBLY
RodColeman 0:8f5825f330b0 111 /**
RodColeman 0:8f5825f330b0 112 * Timer callback function that calls ip_reass_tmr() and reschedules itself.
RodColeman 0:8f5825f330b0 113 *
RodColeman 0:8f5825f330b0 114 * @param arg unused argument
RodColeman 0:8f5825f330b0 115 */
RodColeman 0:8f5825f330b0 116 static void
RodColeman 0:8f5825f330b0 117 ip_reass_timer(void *arg)
RodColeman 0:8f5825f330b0 118 {
RodColeman 0:8f5825f330b0 119 LWIP_UNUSED_ARG(arg);
RodColeman 0:8f5825f330b0 120 LWIP_DEBUGF(TIMERS_DEBUG, ("tcpip: ip_reass_tmr()\n"));
RodColeman 0:8f5825f330b0 121 ip_reass_tmr();
RodColeman 0:8f5825f330b0 122 sys_timeout(IP_TMR_INTERVAL, ip_reass_timer, NULL);
RodColeman 0:8f5825f330b0 123 }
RodColeman 0:8f5825f330b0 124 #endif /* IP_REASSEMBLY */
RodColeman 0:8f5825f330b0 125
RodColeman 0:8f5825f330b0 126 #if LWIP_ARP
RodColeman 0:8f5825f330b0 127 /**
RodColeman 0:8f5825f330b0 128 * Timer callback function that calls etharp_tmr() and reschedules itself.
RodColeman 0:8f5825f330b0 129 *
RodColeman 0:8f5825f330b0 130 * @param arg unused argument
RodColeman 0:8f5825f330b0 131 */
RodColeman 0:8f5825f330b0 132 static void
RodColeman 0:8f5825f330b0 133 arp_timer(void *arg)
RodColeman 0:8f5825f330b0 134 {
RodColeman 0:8f5825f330b0 135 LWIP_UNUSED_ARG(arg);
RodColeman 0:8f5825f330b0 136 LWIP_DEBUGF(TIMERS_DEBUG, ("tcpip: etharp_tmr()\n"));
RodColeman 0:8f5825f330b0 137 etharp_tmr();
RodColeman 0:8f5825f330b0 138 sys_timeout(ARP_TMR_INTERVAL, arp_timer, NULL);
RodColeman 0:8f5825f330b0 139 }
RodColeman 0:8f5825f330b0 140 #endif /* LWIP_ARP */
RodColeman 0:8f5825f330b0 141
RodColeman 0:8f5825f330b0 142 #if LWIP_DHCP
RodColeman 0:8f5825f330b0 143 /**
RodColeman 0:8f5825f330b0 144 * Timer callback function that calls dhcp_coarse_tmr() and reschedules itself.
RodColeman 0:8f5825f330b0 145 *
RodColeman 0:8f5825f330b0 146 * @param arg unused argument
RodColeman 0:8f5825f330b0 147 */
RodColeman 0:8f5825f330b0 148 static void
RodColeman 0:8f5825f330b0 149 dhcp_timer_coarse(void *arg)
RodColeman 0:8f5825f330b0 150 {
RodColeman 0:8f5825f330b0 151 LWIP_UNUSED_ARG(arg);
RodColeman 0:8f5825f330b0 152 LWIP_DEBUGF(TIMERS_DEBUG, ("tcpip: dhcp_coarse_tmr()\n"));
RodColeman 0:8f5825f330b0 153 dhcp_coarse_tmr();
RodColeman 0:8f5825f330b0 154 sys_timeout(DHCP_COARSE_TIMER_MSECS, dhcp_timer_coarse, NULL);
RodColeman 0:8f5825f330b0 155 }
RodColeman 0:8f5825f330b0 156
RodColeman 0:8f5825f330b0 157 /**
RodColeman 0:8f5825f330b0 158 * Timer callback function that calls dhcp_fine_tmr() and reschedules itself.
RodColeman 0:8f5825f330b0 159 *
RodColeman 0:8f5825f330b0 160 * @param arg unused argument
RodColeman 0:8f5825f330b0 161 */
RodColeman 0:8f5825f330b0 162 static void
RodColeman 0:8f5825f330b0 163 dhcp_timer_fine(void *arg)
RodColeman 0:8f5825f330b0 164 {
RodColeman 0:8f5825f330b0 165 LWIP_UNUSED_ARG(arg);
RodColeman 0:8f5825f330b0 166 LWIP_DEBUGF(TIMERS_DEBUG, ("tcpip: dhcp_fine_tmr()\n"));
RodColeman 0:8f5825f330b0 167 dhcp_fine_tmr();
RodColeman 0:8f5825f330b0 168 sys_timeout(DHCP_FINE_TIMER_MSECS, dhcp_timer_fine, NULL);
RodColeman 0:8f5825f330b0 169 }
RodColeman 0:8f5825f330b0 170 #endif /* LWIP_DHCP */
RodColeman 0:8f5825f330b0 171
RodColeman 0:8f5825f330b0 172 #if LWIP_AUTOIP
RodColeman 0:8f5825f330b0 173 /**
RodColeman 0:8f5825f330b0 174 * Timer callback function that calls autoip_tmr() and reschedules itself.
RodColeman 0:8f5825f330b0 175 *
RodColeman 0:8f5825f330b0 176 * @param arg unused argument
RodColeman 0:8f5825f330b0 177 */
RodColeman 0:8f5825f330b0 178 static void
RodColeman 0:8f5825f330b0 179 autoip_timer(void *arg)
RodColeman 0:8f5825f330b0 180 {
RodColeman 0:8f5825f330b0 181 LWIP_UNUSED_ARG(arg);
RodColeman 0:8f5825f330b0 182 LWIP_DEBUGF(TIMERS_DEBUG, ("tcpip: autoip_tmr()\n"));
RodColeman 0:8f5825f330b0 183 autoip_tmr();
RodColeman 0:8f5825f330b0 184 sys_timeout(AUTOIP_TMR_INTERVAL, autoip_timer, NULL);
RodColeman 0:8f5825f330b0 185 }
RodColeman 0:8f5825f330b0 186 #endif /* LWIP_AUTOIP */
RodColeman 0:8f5825f330b0 187
RodColeman 0:8f5825f330b0 188 #if LWIP_IGMP
RodColeman 0:8f5825f330b0 189 /**
RodColeman 0:8f5825f330b0 190 * Timer callback function that calls igmp_tmr() and reschedules itself.
RodColeman 0:8f5825f330b0 191 *
RodColeman 0:8f5825f330b0 192 * @param arg unused argument
RodColeman 0:8f5825f330b0 193 */
RodColeman 0:8f5825f330b0 194 static void
RodColeman 0:8f5825f330b0 195 igmp_timer(void *arg)
RodColeman 0:8f5825f330b0 196 {
RodColeman 0:8f5825f330b0 197 LWIP_UNUSED_ARG(arg);
RodColeman 0:8f5825f330b0 198 LWIP_DEBUGF(TIMERS_DEBUG, ("tcpip: igmp_tmr()\n"));
RodColeman 0:8f5825f330b0 199 igmp_tmr();
RodColeman 0:8f5825f330b0 200 sys_timeout(IGMP_TMR_INTERVAL, igmp_timer, NULL);
RodColeman 0:8f5825f330b0 201 }
RodColeman 0:8f5825f330b0 202 #endif /* LWIP_IGMP */
RodColeman 0:8f5825f330b0 203
RodColeman 0:8f5825f330b0 204 #if LWIP_DNS
RodColeman 0:8f5825f330b0 205 /**
RodColeman 0:8f5825f330b0 206 * Timer callback function that calls dns_tmr() and reschedules itself.
RodColeman 0:8f5825f330b0 207 *
RodColeman 0:8f5825f330b0 208 * @param arg unused argument
RodColeman 0:8f5825f330b0 209 */
RodColeman 0:8f5825f330b0 210 static void
RodColeman 0:8f5825f330b0 211 dns_timer(void *arg)
RodColeman 0:8f5825f330b0 212 {
RodColeman 0:8f5825f330b0 213 LWIP_UNUSED_ARG(arg);
RodColeman 0:8f5825f330b0 214 LWIP_DEBUGF(TIMERS_DEBUG, ("tcpip: dns_tmr()\n"));
RodColeman 0:8f5825f330b0 215 dns_tmr();
RodColeman 0:8f5825f330b0 216 sys_timeout(DNS_TMR_INTERVAL, dns_timer, NULL);
RodColeman 0:8f5825f330b0 217 }
RodColeman 0:8f5825f330b0 218 #endif /* LWIP_DNS */
RodColeman 0:8f5825f330b0 219
RodColeman 0:8f5825f330b0 220 /** Initialize this module */
RodColeman 0:8f5825f330b0 221 void sys_timeouts_init(void)
RodColeman 0:8f5825f330b0 222 {
RodColeman 0:8f5825f330b0 223 next_timeout = NULL;
RodColeman 0:8f5825f330b0 224 #if IP_REASSEMBLY
RodColeman 0:8f5825f330b0 225 sys_timeout(IP_TMR_INTERVAL, ip_reass_timer, NULL);
RodColeman 0:8f5825f330b0 226 #endif /* IP_REASSEMBLY */
RodColeman 0:8f5825f330b0 227 #if LWIP_ARP
RodColeman 0:8f5825f330b0 228 sys_timeout(ARP_TMR_INTERVAL, arp_timer, NULL);
RodColeman 0:8f5825f330b0 229 #endif /* LWIP_ARP */
RodColeman 0:8f5825f330b0 230 #if LWIP_DHCP
RodColeman 0:8f5825f330b0 231 sys_timeout(DHCP_COARSE_TIMER_MSECS, dhcp_timer_coarse, NULL);
RodColeman 0:8f5825f330b0 232 sys_timeout(DHCP_FINE_TIMER_MSECS, dhcp_timer_fine, NULL);
RodColeman 0:8f5825f330b0 233 #endif /* LWIP_DHCP */
RodColeman 0:8f5825f330b0 234 #if LWIP_AUTOIP
RodColeman 0:8f5825f330b0 235 sys_timeout(AUTOIP_TMR_INTERVAL, autoip_timer, NULL);
RodColeman 0:8f5825f330b0 236 #endif /* LWIP_AUTOIP */
RodColeman 0:8f5825f330b0 237 #if LWIP_IGMP
RodColeman 0:8f5825f330b0 238 sys_timeout(IGMP_TMR_INTERVAL, igmp_timer, NULL);
RodColeman 0:8f5825f330b0 239 #endif /* LWIP_IGMP */
RodColeman 0:8f5825f330b0 240 #if LWIP_DNS
RodColeman 0:8f5825f330b0 241 sys_timeout(DNS_TMR_INTERVAL, dns_timer, NULL);
RodColeman 0:8f5825f330b0 242 #endif /* LWIP_DNS */
RodColeman 0:8f5825f330b0 243
RodColeman 0:8f5825f330b0 244 #if NO_SYS
RodColeman 0:8f5825f330b0 245 /* Initialise timestamp for sys_check_timeouts */
RodColeman 0:8f5825f330b0 246 timeouts_last_time = sys_now();
RodColeman 0:8f5825f330b0 247 #endif
RodColeman 0:8f5825f330b0 248 }
RodColeman 0:8f5825f330b0 249
RodColeman 0:8f5825f330b0 250 /**
RodColeman 0:8f5825f330b0 251 * Create a one-shot timer (aka timeout). Timeouts are processed in the
RodColeman 0:8f5825f330b0 252 * following cases:
RodColeman 0:8f5825f330b0 253 * - while waiting for a message using sys_timeouts_mbox_fetch()
RodColeman 0:8f5825f330b0 254 * - by calling sys_check_timeouts() (NO_SYS==1 only)
RodColeman 0:8f5825f330b0 255 *
RodColeman 0:8f5825f330b0 256 * @param msecs time in milliseconds after that the timer should expire
RodColeman 0:8f5825f330b0 257 * @param handler callback function to call when msecs have elapsed
RodColeman 0:8f5825f330b0 258 * @param arg argument to pass to the callback function
RodColeman 0:8f5825f330b0 259 */
RodColeman 0:8f5825f330b0 260 #if LWIP_DEBUG_TIMERNAMES
RodColeman 0:8f5825f330b0 261 void
RodColeman 0:8f5825f330b0 262 sys_timeout_debug(u32_t msecs, sys_timeout_handler handler, void *arg, const char* handler_name)
RodColeman 0:8f5825f330b0 263 #else /* LWIP_DEBUG_TIMERNAMES */
RodColeman 0:8f5825f330b0 264 void
RodColeman 0:8f5825f330b0 265 sys_timeout(u32_t msecs, sys_timeout_handler handler, void *arg)
RodColeman 0:8f5825f330b0 266 #endif /* LWIP_DEBUG_TIMERNAMES */
RodColeman 0:8f5825f330b0 267 {
RodColeman 0:8f5825f330b0 268 struct sys_timeo *timeout, *t;
RodColeman 0:8f5825f330b0 269
RodColeman 0:8f5825f330b0 270 timeout = (struct sys_timeo *)memp_malloc(MEMP_SYS_TIMEOUT);
RodColeman 0:8f5825f330b0 271 if (timeout == NULL) {
RodColeman 0:8f5825f330b0 272 LWIP_ASSERT("sys_timeout: timeout != NULL, pool MEMP_SYS_TIMEOUT is empty", timeout != NULL);
RodColeman 0:8f5825f330b0 273 return;
RodColeman 0:8f5825f330b0 274 }
RodColeman 0:8f5825f330b0 275 timeout->next = NULL;
RodColeman 0:8f5825f330b0 276 timeout->h = handler;
RodColeman 0:8f5825f330b0 277 timeout->arg = arg;
RodColeman 0:8f5825f330b0 278 timeout->time = msecs;
RodColeman 0:8f5825f330b0 279 #if LWIP_DEBUG_TIMERNAMES
RodColeman 0:8f5825f330b0 280 timeout->handler_name = handler_name;
RodColeman 0:8f5825f330b0 281 LWIP_DEBUGF(TIMERS_DEBUG, ("sys_timeout: %p msecs=%"U32_F" handler=%s arg=%p\n",
RodColeman 0:8f5825f330b0 282 (void *)timeout, msecs, handler_name, (void *)arg));
RodColeman 0:8f5825f330b0 283 #endif /* LWIP_DEBUG_TIMERNAMES */
RodColeman 0:8f5825f330b0 284
RodColeman 0:8f5825f330b0 285 if (next_timeout == NULL) {
RodColeman 0:8f5825f330b0 286 next_timeout = timeout;
RodColeman 0:8f5825f330b0 287 return;
RodColeman 0:8f5825f330b0 288 }
RodColeman 0:8f5825f330b0 289
RodColeman 0:8f5825f330b0 290 if (next_timeout->time > msecs) {
RodColeman 0:8f5825f330b0 291 next_timeout->time -= msecs;
RodColeman 0:8f5825f330b0 292 timeout->next = next_timeout;
RodColeman 0:8f5825f330b0 293 next_timeout = timeout;
RodColeman 0:8f5825f330b0 294 } else {
RodColeman 0:8f5825f330b0 295 for(t = next_timeout; t != NULL; t = t->next) {
RodColeman 0:8f5825f330b0 296 timeout->time -= t->time;
RodColeman 0:8f5825f330b0 297 if (t->next == NULL || t->next->time > timeout->time) {
RodColeman 0:8f5825f330b0 298 if (t->next != NULL) {
RodColeman 0:8f5825f330b0 299 t->next->time -= timeout->time;
RodColeman 0:8f5825f330b0 300 }
RodColeman 0:8f5825f330b0 301 timeout->next = t->next;
RodColeman 0:8f5825f330b0 302 t->next = timeout;
RodColeman 0:8f5825f330b0 303 break;
RodColeman 0:8f5825f330b0 304 }
RodColeman 0:8f5825f330b0 305 }
RodColeman 0:8f5825f330b0 306 }
RodColeman 0:8f5825f330b0 307 }
RodColeman 0:8f5825f330b0 308
RodColeman 0:8f5825f330b0 309 /**
RodColeman 0:8f5825f330b0 310 * Go through timeout list (for this task only) and remove the first matching
RodColeman 0:8f5825f330b0 311 * entry, even though the timeout has not triggered yet.
RodColeman 0:8f5825f330b0 312 *
RodColeman 0:8f5825f330b0 313 * @note This function only works as expected if there is only one timeout
RodColeman 0:8f5825f330b0 314 * calling 'handler' in the list of timeouts.
RodColeman 0:8f5825f330b0 315 *
RodColeman 0:8f5825f330b0 316 * @param handler callback function that would be called by the timeout
RodColeman 0:8f5825f330b0 317 * @param arg callback argument that would be passed to handler
RodColeman 0:8f5825f330b0 318 */
RodColeman 0:8f5825f330b0 319 void
RodColeman 0:8f5825f330b0 320 sys_untimeout(sys_timeout_handler handler, void *arg)
RodColeman 0:8f5825f330b0 321 {
RodColeman 0:8f5825f330b0 322 struct sys_timeo *prev_t, *t;
RodColeman 0:8f5825f330b0 323
RodColeman 0:8f5825f330b0 324 if (next_timeout == NULL) {
RodColeman 0:8f5825f330b0 325 return;
RodColeman 0:8f5825f330b0 326 }
RodColeman 0:8f5825f330b0 327
RodColeman 0:8f5825f330b0 328 for (t = next_timeout, prev_t = NULL; t != NULL; prev_t = t, t = t->next) {
RodColeman 0:8f5825f330b0 329 if ((t->h == handler) && (t->arg == arg)) {
RodColeman 0:8f5825f330b0 330 /* We have a match */
RodColeman 0:8f5825f330b0 331 /* Unlink from previous in list */
RodColeman 0:8f5825f330b0 332 if (prev_t == NULL) {
RodColeman 0:8f5825f330b0 333 next_timeout = t->next;
RodColeman 0:8f5825f330b0 334 } else {
RodColeman 0:8f5825f330b0 335 prev_t->next = t->next;
RodColeman 0:8f5825f330b0 336 }
RodColeman 0:8f5825f330b0 337 /* If not the last one, add time of this one back to next */
RodColeman 0:8f5825f330b0 338 if (t->next != NULL) {
RodColeman 0:8f5825f330b0 339 t->next->time += t->time;
RodColeman 0:8f5825f330b0 340 }
RodColeman 0:8f5825f330b0 341 memp_free(MEMP_SYS_TIMEOUT, t);
RodColeman 0:8f5825f330b0 342 return;
RodColeman 0:8f5825f330b0 343 }
RodColeman 0:8f5825f330b0 344 }
RodColeman 0:8f5825f330b0 345 return;
RodColeman 0:8f5825f330b0 346 }
RodColeman 0:8f5825f330b0 347
RodColeman 0:8f5825f330b0 348 #if NO_SYS
RodColeman 0:8f5825f330b0 349
RodColeman 0:8f5825f330b0 350 /** Handle timeouts for NO_SYS==1 (i.e. without using
RodColeman 0:8f5825f330b0 351 * tcpip_thread/sys_timeouts_mbox_fetch(). Uses sys_now() to call timeout
RodColeman 0:8f5825f330b0 352 * handler functions when timeouts expire.
RodColeman 0:8f5825f330b0 353 *
RodColeman 0:8f5825f330b0 354 * Must be called periodically from your main loop.
RodColeman 0:8f5825f330b0 355 */
RodColeman 0:8f5825f330b0 356 void
RodColeman 0:8f5825f330b0 357 sys_check_timeouts(void)
RodColeman 0:8f5825f330b0 358 {
RodColeman 0:8f5825f330b0 359 struct sys_timeo *tmptimeout;
RodColeman 0:8f5825f330b0 360 u32_t diff;
RodColeman 0:8f5825f330b0 361 sys_timeout_handler handler;
RodColeman 0:8f5825f330b0 362 void *arg;
RodColeman 0:8f5825f330b0 363 int had_one;
RodColeman 0:8f5825f330b0 364 u32_t now;
RodColeman 0:8f5825f330b0 365
RodColeman 0:8f5825f330b0 366 now = sys_now();
RodColeman 0:8f5825f330b0 367 if (next_timeout) {
RodColeman 0:8f5825f330b0 368 /* this cares for wraparounds */
RodColeman 0:8f5825f330b0 369 diff = LWIP_U32_DIFF(now, timeouts_last_time);
RodColeman 0:8f5825f330b0 370 do
RodColeman 0:8f5825f330b0 371 {
RodColeman 0:8f5825f330b0 372 had_one = 0;
RodColeman 0:8f5825f330b0 373 tmptimeout = next_timeout;
RodColeman 0:8f5825f330b0 374 if (tmptimeout->time <= diff) {
RodColeman 0:8f5825f330b0 375 /* timeout has expired */
RodColeman 0:8f5825f330b0 376 had_one = 1;
RodColeman 0:8f5825f330b0 377 timeouts_last_time = now;
RodColeman 0:8f5825f330b0 378 diff -= tmptimeout->time;
RodColeman 0:8f5825f330b0 379 next_timeout = tmptimeout->next;
RodColeman 0:8f5825f330b0 380 handler = tmptimeout->h;
RodColeman 0:8f5825f330b0 381 arg = tmptimeout->arg;
RodColeman 0:8f5825f330b0 382 #if LWIP_DEBUG_TIMERNAMES
RodColeman 0:8f5825f330b0 383 if (handler != NULL) {
RodColeman 0:8f5825f330b0 384 LWIP_DEBUGF(TIMERS_DEBUG, ("sct calling h=%s arg=%p\n",
RodColeman 0:8f5825f330b0 385 tmptimeout->handler_name, arg));
RodColeman 0:8f5825f330b0 386 }
RodColeman 0:8f5825f330b0 387 #endif /* LWIP_DEBUG_TIMERNAMES */
RodColeman 0:8f5825f330b0 388 memp_free(MEMP_SYS_TIMEOUT, tmptimeout);
RodColeman 0:8f5825f330b0 389 if (handler != NULL) {
RodColeman 0:8f5825f330b0 390 handler(arg);
RodColeman 0:8f5825f330b0 391 }
RodColeman 0:8f5825f330b0 392 }
RodColeman 0:8f5825f330b0 393 /* repeat until all expired timers have been called */
RodColeman 0:8f5825f330b0 394 }while(had_one);
RodColeman 0:8f5825f330b0 395 }
RodColeman 0:8f5825f330b0 396 }
RodColeman 0:8f5825f330b0 397
RodColeman 0:8f5825f330b0 398 /** Set back the timestamp of the last call to sys_check_timeouts()
RodColeman 0:8f5825f330b0 399 * This is necessary if sys_check_timeouts() hasn't been called for a long
RodColeman 0:8f5825f330b0 400 * time (e.g. while saving energy) to prevent all timer functions of that
RodColeman 0:8f5825f330b0 401 * period being called.
RodColeman 0:8f5825f330b0 402 */
RodColeman 0:8f5825f330b0 403 void
RodColeman 0:8f5825f330b0 404 sys_restart_timeouts(void)
RodColeman 0:8f5825f330b0 405 {
RodColeman 0:8f5825f330b0 406 timeouts_last_time = sys_now();
RodColeman 0:8f5825f330b0 407 }
RodColeman 0:8f5825f330b0 408
RodColeman 0:8f5825f330b0 409 #else /* NO_SYS */
RodColeman 0:8f5825f330b0 410
RodColeman 0:8f5825f330b0 411 /**
RodColeman 0:8f5825f330b0 412 * Wait (forever) for a message to arrive in an mbox.
RodColeman 0:8f5825f330b0 413 * While waiting, timeouts are processed.
RodColeman 0:8f5825f330b0 414 *
RodColeman 0:8f5825f330b0 415 * @param mbox the mbox to fetch the message from
RodColeman 0:8f5825f330b0 416 * @param msg the place to store the message
RodColeman 0:8f5825f330b0 417 */
RodColeman 0:8f5825f330b0 418 void
RodColeman 0:8f5825f330b0 419 sys_timeouts_mbox_fetch(sys_mbox_t *mbox, void **msg)
RodColeman 0:8f5825f330b0 420 {
RodColeman 0:8f5825f330b0 421 u32_t time_needed;
RodColeman 0:8f5825f330b0 422 struct sys_timeo *tmptimeout;
RodColeman 0:8f5825f330b0 423 sys_timeout_handler handler;
RodColeman 0:8f5825f330b0 424 void *arg;
RodColeman 0:8f5825f330b0 425
RodColeman 0:8f5825f330b0 426 again:
RodColeman 0:8f5825f330b0 427 if (!next_timeout) {
RodColeman 0:8f5825f330b0 428 time_needed = sys_arch_mbox_fetch(mbox, msg, 0);
RodColeman 0:8f5825f330b0 429 } else {
RodColeman 0:8f5825f330b0 430 if (next_timeout->time > 0) {
RodColeman 0:8f5825f330b0 431 time_needed = sys_arch_mbox_fetch(mbox, msg, next_timeout->time);
RodColeman 0:8f5825f330b0 432 } else {
RodColeman 0:8f5825f330b0 433 time_needed = SYS_ARCH_TIMEOUT;
RodColeman 0:8f5825f330b0 434 }
RodColeman 0:8f5825f330b0 435
RodColeman 0:8f5825f330b0 436 if (time_needed == SYS_ARCH_TIMEOUT) {
RodColeman 0:8f5825f330b0 437 /* If time == SYS_ARCH_TIMEOUT, a timeout occured before a message
RodColeman 0:8f5825f330b0 438 could be fetched. We should now call the timeout handler and
RodColeman 0:8f5825f330b0 439 deallocate the memory allocated for the timeout. */
RodColeman 0:8f5825f330b0 440 tmptimeout = next_timeout;
RodColeman 0:8f5825f330b0 441 next_timeout = tmptimeout->next;
RodColeman 0:8f5825f330b0 442 handler = tmptimeout->h;
RodColeman 0:8f5825f330b0 443 arg = tmptimeout->arg;
RodColeman 0:8f5825f330b0 444 #if LWIP_DEBUG_TIMERNAMES
RodColeman 0:8f5825f330b0 445 if (handler != NULL) {
RodColeman 0:8f5825f330b0 446 LWIP_DEBUGF(TIMERS_DEBUG, ("stmf calling h=%s arg=%p\n",
RodColeman 0:8f5825f330b0 447 tmptimeout->handler_name, arg));
RodColeman 0:8f5825f330b0 448 }
RodColeman 0:8f5825f330b0 449 #endif /* LWIP_DEBUG_TIMERNAMES */
RodColeman 0:8f5825f330b0 450 memp_free(MEMP_SYS_TIMEOUT, tmptimeout);
RodColeman 0:8f5825f330b0 451 if (handler != NULL) {
RodColeman 0:8f5825f330b0 452 /* For LWIP_TCPIP_CORE_LOCKING, lock the core before calling the
RodColeman 0:8f5825f330b0 453 timeout handler function. */
RodColeman 0:8f5825f330b0 454 LOCK_TCPIP_CORE();
RodColeman 0:8f5825f330b0 455 handler(arg);
RodColeman 0:8f5825f330b0 456 UNLOCK_TCPIP_CORE();
RodColeman 0:8f5825f330b0 457 }
RodColeman 0:8f5825f330b0 458 LWIP_TCPIP_THREAD_ALIVE();
RodColeman 0:8f5825f330b0 459
RodColeman 0:8f5825f330b0 460 /* We try again to fetch a message from the mbox. */
RodColeman 0:8f5825f330b0 461 goto again;
RodColeman 0:8f5825f330b0 462 } else {
RodColeman 0:8f5825f330b0 463 /* If time != SYS_ARCH_TIMEOUT, a message was received before the timeout
RodColeman 0:8f5825f330b0 464 occured. The time variable is set to the number of
RodColeman 0:8f5825f330b0 465 milliseconds we waited for the message. */
RodColeman 0:8f5825f330b0 466 if (time_needed < next_timeout->time) {
RodColeman 0:8f5825f330b0 467 next_timeout->time -= time_needed;
RodColeman 0:8f5825f330b0 468 } else {
RodColeman 0:8f5825f330b0 469 next_timeout->time = 0;
RodColeman 0:8f5825f330b0 470 }
RodColeman 0:8f5825f330b0 471 }
RodColeman 0:8f5825f330b0 472 }
RodColeman 0:8f5825f330b0 473 }
RodColeman 0:8f5825f330b0 474
RodColeman 0:8f5825f330b0 475 #endif /* NO_SYS */
RodColeman 0:8f5825f330b0 476
RodColeman 0:8f5825f330b0 477 #else /* LWIP_TIMERS */
RodColeman 0:8f5825f330b0 478 /* Satisfy the TCP code which calls this function */
RodColeman 0:8f5825f330b0 479 void
RodColeman 0:8f5825f330b0 480 tcp_timer_needed(void)
RodColeman 0:8f5825f330b0 481 {
RodColeman 0:8f5825f330b0 482 }
RodColeman 0:8f5825f330b0 483 #endif /* LWIP_TIMERS */