/*[MethodImpl(MethodImplOptions.Synchronized)]*/ /*public*/ /*synchronized*/ internal void write(Packet packet, Channel c, int length) { while (true) { if (in_kex) { Thread.Sleep(10); 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; if (len > length) { len = length; } if (len != length) { s = packet.shift(len, (c2smac != null ? c2smac.getBlockSize() : 0)); } command = packet.buffer.getCommand(); recipient = c.getRecipient(); length -= len; c.rwsize -= len; sendit = true; } } if (sendit) { _write(packet); if (length == 0) { return; } packet.unshift(command, recipient, s, length); } lock (c) { if (in_kex) { continue; } if (c.rwsize >= length) { c.rwsize -= length; break; } try { c.notifyme++; Monitor.Wait(c, 100); } catch (ThreadInterruptedException ) { } finally { c.notifyme--; } } } _write(packet); }