Source code: com/act365/net/tcp/TCPMSLTimer.java
1 /*
2 * JSocket Wrench
3 *
4 * Copyright (C) act365.com October 2003
5 *
6 * Web site: http://www.act365.com/wrench
7 * E-mail: developers@act365.com
8 *
9 * The JSocket Wrench library adds support for low-level Internet protocols
10 * to the Java programming language.
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the Free
14 * Software Foundation; either version 2 of the License, or (at your option)
15 * any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
20 * Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * this program; if not, write to the Free Software Foundation, Inc.,
24 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 */
26
27 package com.act365.net.tcp ;
28
29 /**
30 * Implements a MSL (Maximum Segment Lifetime) timer used to close a
31 * TCP connection.
32 */
33
34 public class TCPMSLTimer extends Thread {
35
36 TCPJSocketImpl socket ;
37
38 long msltimeout ;
39
40 /**
41 * Constructs the timer.
42 * @param socket socket used to create the timer
43 * @param msltimeout MSL in thousandths of a second
44 */
45
46 public TCPMSLTimer( TCPJSocketImpl socket , long msltimeout ) {
47 this.socket = socket ;
48 this.msltimeout = msltimeout ;
49 }
50
51 /**
52 * Starts the timer
53 */
54
55 public void run() {
56 try {
57 sleep( 2 * msltimeout );
58 socket.setState( TCP.CLOSED );
59 } catch ( InterruptedException ie ){
60 System.err.println("Interrupted Exception: " + ie.getMessage() );
61 }
62 }
63 }
64