diff src/main/java/jp/ac/u_ryukyu/treevnc/server/MyRfbProtoProxy.java @ 31:872d9bcbfe56

Before changing the Viewer.
author one
date Sat, 01 Sep 2012 21:23:30 +0900
parents 18fad65bc447
children 758d025ee24b
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/server/MyRfbProtoProxy.java	Sat Sep 01 20:33:48 2012 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/server/MyRfbProtoProxy.java	Sat Sep 01 21:23:30 2012 +0900
@@ -23,7 +23,6 @@
 //import myVncProxy.MulticastQueue.Client;
 
 import java.util.concurrent.ExecutorService;
-import java.util.concurrent.atomic.AtomicInteger;
 import java.util.zip.DataFormatException;
 import java.util.zip.Deflater;
 import java.util.zip.Inflater;
@@ -67,7 +66,6 @@
 	// private MulticastQueue<LinkedList<ByteBuffer>> multicastqueue = new
 	// MostRecentMultiCast<LinkedList<ByteBuffer>>(10);
 	private MulticastQueue<LinkedList<ByteBuffer>> multicastqueue = new MulticastQueue<LinkedList<ByteBuffer>>();
-	private int clients = 0;
 	private Inflater inflater = new Inflater();
 	private Deflater deflater = new Deflater();
 	// private Thread requestThread;
@@ -350,155 +348,6 @@
 		// here.
 	}
 
-	public void newClient(AcceptThread acceptThread, final Socket newCli,
-			final Writer os, final Reader is) throws IOException {
-		// createBimgFlag = true;
-		// rfb.addSockTmp(newCli);
-		// addSock(newCli);
-		final int myId = clients;
-		final MulticastQueue.Client<LinkedList<ByteBuffer>> c = multicastqueue.newClient();
-		final AtomicInteger writerRunning = new AtomicInteger();
-		writerRunning.set(1);
-		/**
-		 * Timeout thread. If a client is suspended, it has top of queue
-		 * indefinitely, which caused memory overflow. After the timeout, we
-		 * poll the queue and discard it. Start long wait if writer is running.
-		 */
-		final Runnable timer = new Runnable() {
-			public void run() {
-				int count = 0;
-				for (;;) {
-					long timeout = 50000 / 8;
-					try {
-						synchronized (this) {
-							int state, flag;
-							writerRunning.set(0);
-							wait(timeout);
-							flag = 0;
-							while ((state = writerRunning.get()) == 0) {
-								c.poll(); // discard, should be timeout
-								count++;
-								if (flag == 0) {
-									System.out.println("Discarding " + myId
-											+ " count=" + count);
-									flag = 1;
-								}
-								wait(10); // if this is too short, writer cannot
-											// take the poll, if this is too
-											// long, memory will overflow...
-							}
-							if (flag == 1)
-								System.out.println("Resuming " + myId
-										+ " count=" + count);
-							if (state != 1) {
-								System.out.println("Client died " + myId);
-								break;
-							}
-						}
-					} catch (InterruptedException e) {
-					}
-				}
-			}
-		};
-		new Thread(timer).start();
-		/**
-		 * discard all incoming from clients
-		 */
-		final Runnable reader = new Runnable() {
-			public void run() {
-				byte b[] = new byte[4096];
-				for (;;) {
-					try {
-						int c = is.readByte(b);
-						if (c <= 0)
-							throw new IOException();
-						// System.out.println("client read "+c);
-					} catch (IOException e) {
-						try {
-							writerRunning.set(2);
-							os.close();
-							is.close();
-						} catch (IOException e1) {
-						} catch (TransportException e1) {
-							e1.printStackTrace();
-						}
-						return;
-					} catch (TransportException e) {
-						e.printStackTrace();
-					}
-				}
-			}
-		};
-		/**
-		 * send packets to a client
-		 */
-		Runnable sender = new Runnable() {
-			public void run() {
-				writerRunning.set(1);
-				try {
-					requestThreadNotify();
-					// rThread.checkDelay();
-
-					/**
-					 * initial connection of RFB protocol
-					 */
-					sendRfbVersion(os);
-					// readVersionMsg(is);
-					readVersionMsg(is, os);
-					sendSecurityType(os);
-					readSecType(is);
-					sendSecResult(os);
-					readClientInit(is);
-					sendInitData(os);
-					new Thread(reader).start(); // discard incoming packet here
-												// after.
-					// writeFramebufferUpdateRequest(0,0, framebufferWidth,
-					// framebufferHeight, false );
-					for (;;) {
-						LinkedList<ByteBuffer> bufs = c.poll();
-						int inputIndex = 0;
-						ByteBuffer header = bufs.get(inputIndex);
-						if (header == null)
-							continue;
-						else if (header.get(0) == CheckDelay) {
-							writeToClient(os, bufs, inputIndex);
-							continue;
-						} else if (header.get(0) == FramebufferUpdate) {
-							// System.out.println("client "+ myId);
-						}
-						/*
-						 * if(i%20==0){ sendDataCheckDelay(); } i++;
-						 */
-						writeToClient(os, bufs, inputIndex);
-						writerRunning.set(1); // yes my client is awaking.
-					}
-				} catch (IOException e) {
-					try {
-						writerRunning.set(2);
-						os.close();
-					} catch (IOException e1) {
-					}
-					/* if socket closed cliList.remove(newCli); */
-				} catch (TransportException e) {
-					e.printStackTrace();
-				}
-			}
-
-			public void writeToClient(final Writer os,
-					LinkedList<ByteBuffer> bufs, int inputIndex)
-					throws TransportException {
-				while (inputIndex < bufs.size()) {
-					ByteBuffer b = bufs.get(inputIndex++);
-					os.write(b.array(), b.position(), b.limit());
-				}
-				os.flush();
-			}
-		};
-		clients++;
-		new Thread(sender).start();
-
-	}
-
 	public void dump32(LinkedList<ByteBuffer> bufs) {
 		int len = 0;
 		for (ByteBuffer b : bufs)