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> 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 voidnet_delete_timer(struct sock
*t
) 60 voidnet_reset_timer(struct sock
*t
,int timeout
,unsigned long len
) 64 t
->timer
.expires
= jiffies
+len
; 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
); 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 sk
->state
= TCP_CLOSE
; 117 net_delete_timer(sk
); 119 sk
->state_change(sk
); 120 sk
->shutdown
= SHUTDOWN_MASK
; 121 net_reset_timer(sk
, TIME_DONE
, TCP_DONE_TIME
); 125 /* I want to see these... */ 126 printk("net_timer: timer expired - reason %d is unknown\n", why
);