/*public*/ /*lock*/ public void write(Packet packet, Channel c, int length) { while(true) { if(in_kex) { try{Thread.Sleep(10);} catch(ThreadInterruptedException e){}; continue; } lock(c) { if(c.rwsize>=length) { c.rwsize-=length; break; } } if(c._close || !c.isConnected()) { throw new IOException("channel is broken"); } bool sendit=false; int s=0; byte command=0; int recipient=-1; lock(c) { if(c.rwsize>0) { int len=c.rwsize; s=packet.shift(len, (c2smac!=null ? c2smac.getBlockSize() : 0)); command=packet.buffer.buffer[5]; recipient=c.getRecipient(); length-=len; c.rwsize-=len; sendit=true; } } if(sendit) { _write(packet); packet.unshift(command, recipient, s, length); } try{Thread.Sleep(10);} catch(ThreadInterruptedException e){}; } _write(packet); }