Mercurial > hg > Members > nobuyasu > tightVNCProxy
changeset 51:089bd4510538
add MultiThreadTee.java
author | e085711 |
---|---|
date | Thu, 07 Jul 2011 20:31:41 +0900 |
parents | 458a231f060d |
children | 6eb7d0c8f11d |
files | src/myVncProxy/MyRfbProto.java src/myVncProxy/RfbProto.java src/myVncProxy/VncProxyService.java src/test/MultiThreadTee.java |
diffstat | 4 files changed, 91 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/myVncProxy/MyRfbProto.java Thu Jul 07 18:54:01 2011 +0900 +++ b/src/myVncProxy/MyRfbProto.java Thu Jul 07 20:31:41 2011 +0900 @@ -97,6 +97,7 @@ servSock = new ServerSocket(port); acceptPort = port; } + // 5550を開けるが、開いてないなら+1のポートを開ける。 void selectPort(){ int i = 5550; while(true){
--- a/src/myVncProxy/RfbProto.java Thu Jul 07 18:54:01 2011 +0900 +++ b/src/myVncProxy/RfbProto.java Thu Jul 07 20:31:41 2011 +0900 @@ -223,8 +223,8 @@ timeWaitedIn100us = 5; timedKbits = 0; } - - + + synchronized void close() { try {
--- a/src/myVncProxy/VncProxyService.java Thu Jul 07 18:54:01 2011 +0900 +++ b/src/myVncProxy/VncProxyService.java Thu Jul 07 20:31:41 2011 +0900 @@ -101,9 +101,8 @@ fatalError("Network error: could not connect to server: " + host + ":" + port, e); }catch(Exception e){} - + rfbThread = new Thread(this); - accThread = new Thread(new acceptThread(rfb)); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/MultiThreadTee.java Thu Jul 07 20:31:41 2011 +0900 @@ -0,0 +1,87 @@ +package test; + +import java.util.LinkedList; +import java.util.concurrent.SynchronousQueue; + +public class MultiThreadTee { + + static class Parent extends Thread { + LinkedList<SynchronousQueue<String>> clients = new LinkedList<SynchronousQueue<String>>(); + + + SynchronousQueue<String> accept() { + + SynchronousQueue<String> s = new SynchronousQueue<String>(); + clients.add(s); + + return s; + + + } + + void put(String s) throws InterruptedException { + for (SynchronousQueue<String> queue : clients) { + queue.put(s); + + } + + } + + } + + + + static class Client extends Thread { + Parent p; + private SynchronousQueue<String> queue; + + + + + public Client(Parent p2) { + p = p2; + } + + public void run() { + queue = p.accept(); + + String item; +// while(!(item = queue.poll()).equals("") ) { + while(true) { + item = queue.poll(); + if(item == null) continue; + if(item.equals("")) return; + System.out.println(item); + } + } + + } + + static public void main (String[] argv) throws InterruptedException { + int num = 3; + Parent p = new Parent(); + Client[] cs = new Client[num]; + for (int i=0; i < num; i++ ) { + cs[i] = new Client(p); + } + + p.start(); + for (int i = 0; i < num; i++) { + cs[i].start(); + } + p.put("TEST1"); + p.put("TEST2"); + p.put("TEST3"); + p.put(""); + + p.join(); + for (int i = 0; i < num; i++) { + cs[i].join(); + } + + + + + } +} +