comparison src/fdl/MetaLinda.java @ 36:d5bca4b5ee95

meta.sync() recursive call fix.
author kono
date Sun, 24 Aug 2008 21:06:39 +0900
parents 64071f8e2e0d
children 2a366abc3f1f
comparison
equal deleted inserted replaced
35:fe338d497c72 36:d5bca4b5ee95
47 MetaReply r = new MetaReply(PSX.PSX_IN,id,ts, callback); 47 MetaReply r = new MetaReply(PSX.PSX_IN,id,ts, callback);
48 addReply(r); 48 addReply(r);
49 } 49 }
50 50
51 private void addReply(MetaReply r) { 51 private void addReply(MetaReply r) {
52 replies.add(r); 52 replies.addLast(r);
53 } 53 }
54 54
55 public PSXReply ck(int id) { 55 public PSXReply ck(int id) {
56 MetaReply r = new MetaReply(PSX.PSX_CHECK,id,ts); 56 MetaReply r = new MetaReply(PSX.PSX_CHECK,id,ts);
57 return r; 57 return r;
97 public int sync() { 97 public int sync() {
98 return sync(0); 98 return sync(0);
99 } 99 }
100 100
101 public int sync(long timeout) { 101 public int sync(long timeout) {
102 fds.checkTuple(timeout);
103 if (replies.size()>0) {
104 // copy replies to avoid insert during r.ready()
105 LinkedList<MetaReply> list = replies;
106 replies = new LinkedList<MetaReply>();
107 for(MetaReply r:list) {
108 if (!r.ready()) {
109 addReply(r);
110 }
111 }
112 }
113 if (fdl!=null) { 102 if (fdl!=null) {
114 try { 103 try {
115 fdl.sync(timeout); 104 fdl.sync(timeout);
116 } catch (IOException e) { 105 } catch (IOException e) {
117 e.printStackTrace(); 106 e.printStackTrace();
118 } 107 }
119 } 108 }
109 fds.checkTuple(timeout);
110 /*
111 * r.callback() may call meta.sync() and modifies the
112 * replies queue. Do current size of queue only. The
113 * rest is checked on the next sync call including
114 * the recursive case.
115 */
116 int count = replies.size();
117 while(count-->0) {
118 MetaReply r = replies.poll();
119 // previous call back may call this sync and make
120 // replies shorter.
121 if (r==null) break;
122 if (r.ready()) {
123 } else {
124 addReply(r);
125 }
126 }
120 return 0; 127 return 0;
121 } 128 }
122 129
123 public void send(ByteBuffer command, ByteBuffer data) { 130 public void send(ByteBuffer command, ByteBuffer data) {
124 131