2 * INET An implementation of the TCP/IP protocol suite for the LINUX
3 * operating system. INET is implemented using the BSD Socket
4 * interface as the means of communication with the user level.
6 * TIMER - implementation of software timers for IP.
8 * Version: $Id: timer.c,v 1.15 1999/02/22 13:54:29 davem Exp $
10 * Authors: Ross Biro, <bir7@leland.Stanford.Edu>
11 * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
12 * Corey Minyard <wf-rch!minyard@relay.EU.net>
13 * Fred Baumgarten, <dc6iq@insu1.etec.uni-karlsruhe.de>
14 * Florian La Roche, <flla@stud.uni-sb.de>
17 * Alan Cox : To avoid destroying a wait queue as we use it
18 * we defer destruction until the destroy timer goes
20 * Alan Cox : Destroy socket doesn't write a status value to the
21 * socket buffer _AFTER_ freeing it! Also sock ensures
22 * the socket will get removed BEFORE this is called
23 * otherwise if the timer TIME_DESTROY occurs inside
24 * of inet_bh() with this socket being handled it goes
25 * BOOM! Have to stop timer going off if net_bh is
26 * active or the destroy causes crashes.
27 * Alan Cox : Cleaned up unused code.
29 * This program is free software; you can redistribute it and/or
30 * modify it under the terms of the GNU General Public License
31 * as published by the Free Software Foundation; either version
32 * 2 of the License, or (at your option) any later version.
35 #include <linux/types.h>
36 #include <linux/errno.h>
37 #include <linux/socket.h>
39 #include <linux/kernel.h>
40 #include <linux/sched.h>
41 #include <linux/timer.h>
42 #include <asm/system.h>
43 #include <linux/interrupt.h>
44 #include <linux/inet.h>
45 #include <linux/netdevice.h>
47 #include <net/protocol.h>
49 #include <linux/skbuff.h>
53 void net_delete_timer (struct sock
*t
)
56 del_timer (&t
->timer
);
60 void net_reset_timer (struct sock
*t
, int timeout
, unsigned long len
)
63 mod_timer(&t
->timer
, jiffies
+len
);
66 /* Now we will only be called whenever we need to do
67 * something, but we must be sure to process all of the
68 * sockets that need it.
70 void net_timer (unsigned long data
)
72 struct sock
*sk
= (struct sock
*) data
;
73 int why
= sk
->timeout
;
75 /* Only process if socket is not in use. */
78 /* Try again later. */
79 mod_timer(&sk
->timer
, jiffies
+HZ
/20);
84 /* Always see if we need to send an ack. */
85 if (sk
->tp_pinfo
.af_tcp
.delayed_acks
&& !sk
->zapped
) {
86 sk
->prot
->read_wakeup (sk
);
91 /* Now we need to figure out why the socket was on the timer. */
94 /* If the socket hasn't been closed off, re-try a bit later. */
96 net_reset_timer(sk
, TIME_DONE
, TCP_DONE_TIME
);
100 if (sk
->state
!= TCP_CLOSE
) {
101 printk (KERN_DEBUG
"non CLOSE socket in time_done\n");
108 /* We've waited for a while for all the memory associated with
109 * the socket to be freed.
115 /* We've waited long enough, close the socket. */
116 tcp_set_state(sk
, TCP_CLOSE
);
117 sk
->shutdown
= SHUTDOWN_MASK
;
119 sk
->state_change(sk
);
120 net_reset_timer (sk
, TIME_DONE
, TCP_DONE_TIME
);
124 /* I want to see these... */
125 printk ("net_timer: timer expired - reason %d is unknown\n", why
);
129 /* We only need to unlock if the socket was not destroyed. */