-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSinkWorker.java
72 lines (66 loc) · 1.68 KB
/
SinkWorker.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
* SinkWorker
*
* Receive connection and fork of a child to read data
* from it.
*
* You must follow the coding standards distributed
* on the class web page.
*
* (C) 2007 Mike Dahlin
*
*/
import java.net.ServerSocket;
import java.net.Socket;
import java.io.InputStream;
import java.io.IOException;
import java.io.InterruptedIOException;
public class SinkWorker extends Thread{
ServerSocket s;
boolean verbose;
//-------------------------------------------------
// Constructor
//-------------------------------------------------
public SinkWorker(ServerSocket s, boolean verbose)
{
this.s = s;
this.verbose = verbose;
}
//-------------------------------------------------
// run -- thread main loop. Invoked by jvm when
// thread.start() is called.
//-------------------------------------------------
public void run()
{
Socket sock = null;
try{
while(!this.isInterrupted()){
sock = s.accept();
if(verbose){
System.out.println("# SinkWorker::run accept connection returns");
}
InputStream is = sock.getInputStream();
SinkWorkerWorker sww = new SinkWorkerWorker(is, verbose);
sww.start();
}
}
catch(InterruptedIOException iioe){
if(verbose){
System.out.println("SinkWorker::run interrupted for normal shutdown");
}
}
catch(IOException ioe){
System.out.println("SinkWorker::run IOException" + ioe.toString());
}
finally{
try{
if(sock != null){
sock.close();
}
}
catch(IOException e){
// ignore
}
}
}
}