1
10package org.jstk.ssl;
11
12import java.net.*;
13import java.io.*;
14import java.util.*;
15import javax.net.ssl.SSLSocket;
16import javax.net.ssl.SSLSession;
17import org.jstk.JSTKArgs;
18
19public class ServerThread extends Thread {
20 private JSTKSocket socket = null;
21 private JSTKBuffer buf = null;
22 private int outIdx;
23 private boolean verbose;
24 private boolean bench;
25 private boolean echo;
26 private boolean invalidate;
27
28 public ServerThread(JSTKSocket socket, JSTKBuffer buf, int outIdx,
29 boolean verbose, boolean bench, boolean echo, boolean invalidate) throws IOException {
30 super("ServerThread");
31 this.socket = socket;
32 this.buf = buf;
33 this.outIdx = outIdx;
34 this.verbose = verbose;
35 this.bench = bench;
36 this.echo = echo;
37 this.invalidate = invalidate;
38 }
39
40 public void run() {
41 int n;
42 try {
43 int inIdx = 0;
44 while ((n = socket.read(buf)) != -1){
45 if (!bench || verbose)
46 System.out.println("[" + outIdx + ", " + inIdx + "]ServerLoop:: read " + n + " bytes.");
47 if (echo){
48 socket.write(buf);
49 if (!bench || verbose)
50 System.out.println("[" + outIdx + ", " + inIdx + "]ServerLoop:: wrote " + n + " bytes.");
51 }
52 ++inIdx;
53 }
54
55 } catch (IOException ioe){
56 if (!bench || verbose)
57 System.out.println("[" + outIdx + "]ServerThread:: Exception on read: " + ioe);
58 }
59
60 if (invalidate && socket.getSocket() instanceof SSLSocket){
61 if (verbose)
62 System.out.println("[" + outIdx + "]Invalidating the SSLSession ...");
63 SSLSocket sslSock = (SSLSocket)socket.getSocket();
64 SSLSession sess = sslSock.getSession();
65 sess.invalidate();
66 }
67
68 socket.close();
69 if (!bench || verbose)
70 System.out.println("[" + outIdx + "]ServerThread:: Socket closed.");
71 }
72}
73