Mercurial > hg > Members > nobuyasu > tightVNCProxy
comparison src/myVncProxy/MyRfbProto.java @ 40:dd1321b67f95
sendReadData : newSingleThreadExecutor()
author | e085711 |
---|---|
date | Mon, 06 Jun 2011 12:26:12 +0900 |
parents | f399eec66846 |
children | 08317224ce21 |
comparison
equal
deleted
inserted
replaced
39:f399eec66846 | 40:dd1321b67f95 |
---|---|
9 import java.io.IOException; | 9 import java.io.IOException; |
10 import java.io.InputStreamReader; | 10 import java.io.InputStreamReader; |
11 import java.net.BindException; | 11 import java.net.BindException; |
12 import java.net.ServerSocket; | 12 import java.net.ServerSocket; |
13 import java.net.Socket; | 13 import java.net.Socket; |
14 import java.nio.ByteBuffer; | |
15 import java.util.LinkedList; | 14 import java.util.LinkedList; |
16 | 15 |
17 import javax.imageio.ImageIO; | 16 import javax.imageio.ImageIO; |
18 | 17 |
19 import org.omg.CORBA.portable.OutputStream; | 18 import java.util.concurrent.ExecutorService; |
20 | 19 import java.util.concurrent.Executors; |
20 import java.io.OutputStream; | |
21 | 21 |
22 class MyRfbProto extends RfbProto { | 22 class MyRfbProto extends RfbProto { |
23 | 23 |
24 private int messageType; | 24 private int messageType; |
25 private int rectangles; | 25 private int rectangles; |
37 private LinkedList <Socket> cliListTmp; | 37 private LinkedList <Socket> cliListTmp; |
38 private LinkedList <Socket> cliList; | 38 private LinkedList <Socket> cliList; |
39 private LinkedList <Thread> sendThreads; | 39 private LinkedList <Thread> sendThreads; |
40 boolean createBimgFlag; | 40 boolean createBimgFlag; |
41 | 41 |
42 ExecutorService executor; | |
43 | |
44 | |
42 byte[] pngBytes; | 45 byte[] pngBytes; |
43 | 46 |
44 MyRfbProto(String h, int p, VncViewer v ) throws IOException { | 47 MyRfbProto(String h, int p, VncViewer v ) throws IOException { |
45 super(h, p, v); | 48 super(h, p, v); |
46 cliList = new LinkedList <Socket>(); | 49 cliList = new LinkedList <Socket>(); |
47 cliListTmp = new LinkedList <Socket>(); | 50 cliListTmp = new LinkedList <Socket>(); |
48 createBimgFlag = false; | 51 createBimgFlag = false; |
49 sendThreads = new LinkedList <Thread>(); | 52 sendThreads = new LinkedList <Thread>(); |
53 // executor = Executors.newCachedThreadPool(); | |
54 executor = Executors.newSingleThreadExecutor(); | |
50 } | 55 } |
51 | 56 |
52 MyRfbProto(String h, int p) throws IOException { | 57 MyRfbProto(String h, int p) throws IOException { |
53 super(h, p); | 58 super(h, p); |
54 cliList = new LinkedList <Socket>(); | 59 cliList = new LinkedList <Socket>(); |
55 cliListTmp = new LinkedList <Socket>(); | 60 cliListTmp = new LinkedList <Socket>(); |
56 createBimgFlag = false; | 61 createBimgFlag = false; |
57 sendThreads = new LinkedList <Thread>(); | 62 sendThreads = new LinkedList <Thread>(); |
63 // executor = Executors.newCachedThreadPool(); | |
64 executor = Executors.newSingleThreadExecutor(); | |
58 } | 65 } |
59 | 66 |
60 void initServSock(int port) throws IOException{ | 67 void initServSock(int port) throws IOException{ |
61 servSock = new ServerSocket(port); | 68 servSock = new ServerSocket(port); |
62 acceptPort = port; | 69 acceptPort = port; |
209 len = available(); | 216 len = available(); |
210 byte buffer[] = new byte[len]; | 217 byte buffer[] = new byte[len]; |
211 readFully(buffer); | 218 readFully(buffer); |
212 sendData(buffer); | 219 sendData(buffer); |
213 } | 220 } |
214 void readSendData()throws IOException { | 221 void readSendData()throws IOException{ |
215 byte buffer[] = new byte[dataLen]; | 222 byte buffer[] = new byte[dataLen]; |
216 readFully(buffer); | 223 readFully(buffer); |
217 reset(); | 224 reset(); |
218 | 225 |
219 LinkedList <Thread> threads; | |
220 threads = new LinkedList<Thread>(); | |
221 | |
222 for(Socket cli : cliList){ | 226 for(Socket cli : cliList){ |
223 // try{ | 227 try{ |
224 // OutputStream out = (OutputStream) cli.getOutputStream(); | 228 OutputStream out = cli.getOutputStream(); |
225 // Thread th = new Thread(new SendThread(out, buffer)); | 229 executor.execute(new SendThread(out, buffer)); |
226 Thread th = new Thread(new SendThread(cli, buffer)); | 230 }catch(IOException e){ |
227 threads.add(th); | 231 // if client socket closed |
228 /* | |
229 }catch(IOException e){ | |
230 // if socket closed | |
231 cliListTmp.remove(cli); | 232 cliListTmp.remove(cli); |
232 }catch(Exception e){ | 233 }catch(Exception e){ |
233 | 234 |
234 } | 235 } |
235 */ | 236 |
236 } | 237 } |
237 | |
238 for(Thread thread : threads){ | |
239 thread.start(); | |
240 } | |
241 try{ | |
242 for(Thread thread : threads){ | |
243 thread.join(); | |
244 } | |
245 }catch(InterruptedException e){ | |
246 | |
247 } | |
248 | |
249 } | 238 } |
250 void regiFramebufferUpdate()throws IOException{ | 239 void regiFramebufferUpdate()throws IOException{ |
251 mark(20); | 240 mark(20); |
252 messageType = readU8(); | 241 messageType = readU8(); |
253 skipBytes(1); | 242 skipBytes(1); |