- Revert TCP delayed ACK fix, and fix correctly.
[davej-history.git] / net / ipv4 / timer.c
blob6e97b5b3a8417e187a6bae800e5ecf81ce86177f
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.10 1998/03/13 08:02:18 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 voidnet_delete_timer(struct sock *t)
55 if(t->timer.prev)
56 del_timer(&t->timer);
57 t->timeout =0;
60 voidnet_reset_timer(struct sock *t,int timeout,unsigned long len)
62 net_delete_timer(t);
63 t->timeout = timeout;
64 t->timer.expires = jiffies+len;
65 add_timer(&t->timer);
68 /* Now we will only be called whenever we need to do
69 * something, but we must be sure to process all of the
70 * sockets that need it.
72 voidnet_timer(unsigned long data)
74 struct sock *sk = (struct sock*)data;
75 int why = sk->timeout;
77 /* Only process if socket is not in use. */
78 if(sk->sock_readers) {
79 sk->timer.expires = jiffies+HZ;
80 add_timer(&sk->timer);
81 return;
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);
87 if(!sk->dead)
88 sk->data_ready(sk,0);
91 /* Now we need to figure out why the socket was on the timer. */
92 switch(why) {
93 case TIME_DONE:
94 /* If the socket hasn't been closed off, re-try a bit later. */
95 if(!sk->dead) {
96 net_reset_timer(sk, TIME_DONE, TCP_DONE_TIME);
97 break;
100 if(sk->state != TCP_CLOSE) {
101 printk(KERN_DEBUG "non CLOSE socket in time_done\n");
102 break;
104 destroy_sock(sk);
105 break;
107 case TIME_DESTROY:
108 /* We've waited for a while for all the memory associated with
109 * the socket to be freed.
111 destroy_sock(sk);
112 break;
114 case TIME_CLOSE:
115 /* We've waited long enough, close the socket. */
116 sk->state = TCP_CLOSE;
117 net_delete_timer(sk);
118 if(!sk->dead)
119 sk->state_change(sk);
120 sk->shutdown = SHUTDOWN_MASK;
121 net_reset_timer(sk, TIME_DONE, TCP_DONE_TIME);
122 break;
124 default:
125 /* I want to see these... */
126 printk("net_timer: timer expired - reason %d is unknown\n", why);
127 break;
close