OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [rc203soc/] [sw/] [uClinux/] [net/] [ipv4/] [timer.c] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1629 jcastillo
/*
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.
5
 *
6
 *              TIMER - implementation of software timers for IP.
7
 *
8
 * Version:     @(#)timer.c     1.0.7   05/25/93
9
 *
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>
15
 *
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.
28
 *
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.
33
 */
34
 
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>
52
 
53
void delete_timer (struct sock *t)
54
{
55
        unsigned long flags;
56
 
57
        save_flags (flags);
58
        cli();
59
 
60
        t->timeout = 0;
61
        del_timer (&t->timer);
62
 
63
        restore_flags (flags);
64
}
65
 
66
void reset_timer (struct sock *t, int timeout, unsigned long len)
67
{
68
        delete_timer (t);
69
        t->timeout = timeout;
70
#if 1
71
  /* FIXME: ??? */
72
        if ((int) len < 0)       /* prevent close to infinite timers. THEY _DO_ */
73
                len = 3;        /* happen (negative values ?) - don't ask me why ! -FB */
74
#endif
75
        t->timer.expires = jiffies+len;
76
        add_timer (&t->timer);
77
}
78
 
79
 
80
/*
81
 *      Now we will only be called whenever we need to do
82
 *      something, but we must be sure to process all of the
83
 *      sockets that need it.
84
 */
85
 
86
void net_timer (unsigned long data)
87
{
88
        struct sock *sk = (struct sock*)data;
89
        int why = sk->timeout;
90
 
91
        /*
92
         * only process if socket is not in use
93
         */
94
 
95
        if (sk->users)
96
        {
97
                sk->timer.expires = jiffies+HZ;
98
                add_timer(&sk->timer);
99
                sti();
100
                return;
101
        }
102
 
103
        /* Always see if we need to send an ack. */
104
 
105
        if (sk->ack_backlog && !sk->zapped)
106
        {
107
                sk->prot->read_wakeup (sk);
108
                if (! sk->dead)
109
                sk->data_ready(sk,0);
110
        }
111
 
112
        /* Now we need to figure out why the socket was on the timer. */
113
 
114
        switch (why)
115
        {
116
                case TIME_DONE:
117
                        /* If the socket hasn't been closed off, re-try a bit later */
118
                        if (!sk->dead) {
119
                                reset_timer(sk, TIME_DONE, TCP_DONE_TIME);
120
                                break;
121
                        }
122
 
123
                        if (sk->state != TCP_CLOSE)
124
                        {
125
                                printk ("non CLOSE socket in time_done\n");
126
                                break;
127
                        }
128
                        destroy_sock (sk);
129
                        break;
130
 
131
                case TIME_DESTROY:
132
                /*
133
                 *      We've waited for a while for all the memory associated with
134
                 *      the socket to be freed.
135
                 */
136
 
137
                        destroy_sock(sk);
138
                        break;
139
 
140
                case TIME_CLOSE:
141
                        /* We've waited long enough, close the socket. */
142
                        tcp_set_state(sk, TCP_CLOSE);
143
                        if (!sk->dead)
144
                                sk->state_change(sk);
145
                        sk->shutdown = SHUTDOWN_MASK;
146
                        break;
147
 
148
                default:
149
                        printk ("net_timer: timer expired - reason %d is unknown\n", why);
150
                        break;
151
        }
152
}
153
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.