Linux 2.2.0
[davej-history.git] / net / ipv4 / timer.c
blobdf3c9cce5801c8b4c8e604c2f26c4fe5fb98fec7
1 /*
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.14 1998/11/07 11:55:43 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>
16 * Fixes:
17 * Alan Cox : To avoid destroying a wait queue as we use it
18 * we defer destruction until the destroy timer goes
19 * off.
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>
38 #include <linux/in.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>
46 #include <net/ip.h>
47 #include <net/protocol.h>
48 #include <net/tcp.h>
49 #include <linux/skbuff.h>
50 #include <net/sock.h>
51 #include <net/arp.h>
53 void net_delete_timer (struct sock *t)
55 if(t->timer.prev)
56 del_timer (&t->timer);
57 t->timeout = 0;
60 void net_reset_timer (struct sock *t, int timeout, unsigned long len)
62 t->timeout = timeout;
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. */
76 if (atomic_read(&sk->sock_readers)) {
77 /* Try again later. */
78 sk->timer.expires = jiffies+HZ/20;
79 add_timer(&sk->timer);
80 return;
83 /* Always see if we need to send an ack. */
84 if (sk->tp_pinfo.af_tcp.delayed_acks && !sk->zapped) {
85 sk->prot->read_wakeup (sk);
86 if (!sk->dead)
87 sk->data_ready(sk,0);
90 /* Now we need to figure out why the socket was on the timer. */
91 switch (why) {
92 case TIME_DONE:
93 /* If the socket hasn't been closed off, re-try a bit later. */
94 if (!sk->dead) {
95 net_reset_timer(sk, TIME_DONE, TCP_DONE_TIME);
96 break;
99 if (sk->state != TCP_CLOSE) {
100 printk (KERN_DEBUG "non CLOSE socket in time_done\n");
101 break;
103 destroy_sock (sk);
104 break;
106 case TIME_DESTROY:
107 /* We've waited for a while for all the memory associated with
108 * the socket to be freed.
110 destroy_sock(sk);
111 break;
113 case TIME_CLOSE:
114 /* We've waited long enough, close the socket. */
115 tcp_set_state(sk, TCP_CLOSE);
116 sk->shutdown = SHUTDOWN_MASK;
117 if (!sk->dead)
118 sk->state_change(sk);
119 net_reset_timer (sk, TIME_DONE, TCP_DONE_TIME);
120 break;
122 default:
123 /* I want to see these... */
124 printk ("net_timer: timer expired - reason %d is unknown\n", why);
125 break;