/// <summary> /// Create a new packet store for a given channel. /// </summary> /// <param name="manager"></param> /// <param name="channel"></param> /// <param name="name"></param> public SSHPacketStore(SSHPacketRouter manager, SSHAbstractChannel channel, String name) { this.manager = manager; this.channel = channel; this.name = name; this.header = new HeaderPacket(); // Dummy, never used header.Next = header.Previous = header; }
/// <summary> /// Free an existing channel /// </summary> /// <param name="channel"></param> protected internal virtual void FreeChannel(SSHAbstractChannel channel) { lock (channels) { channels[channel.ChannelID] = null; count--; } }
/// <summary> /// Allocate a new channel /// </summary> /// <param name="channel"></param> /// <returns></returns> protected internal virtual int AllocateChannel(SSHAbstractChannel channel) { lock (channels) { for (int i = 0; i < channels.Length; i++) { if (channels[i] == null) { channels[i] = channel; count++; return(i); } } return(-1); } }
/// <summary> /// Get the next message from the <see cref="Maverick.SSH.Packets.SSHPacketRouter"/> that matches one of the /// ids supplied in the message filter and return its index in the channels message store. /// </summary> /// <param name="channel"></param> /// <param name="observer"></param> /// <returns></returns> protected internal SSHPacket NextMessage(SSHAbstractChannel channel, PacketObserver observer) { SSHPacketStore store = channel == null? global : channel.MessageStore; PacketHolder holder = new PacketHolder(); while (!store.Closed && holder.msg == null) { // Check for an error from the buffering thread if (buffered) { if (!isClosing) { if (lastError != null) { if (lastError is SSHException) { throw lastError; } else { throw new SSHException(lastError); } } } } if (sync.RequestBlock(store, observer, holder)) { try { BlockForMessage(); } finally { // Release the block so that other threads may block or return with the // newly arrived message sync.ReleaseBlock(); } } } return(holder.msg); }
private bool BlockForMessage() { SSHPacket packet = reader.NextMessage(); #if DEBUG System.Diagnostics.Trace.WriteLine("Received message id " + packet.MessageID); #endif if (IsChannelMessage(packet.MessageID)) { packet = new SSHChannelMessage(packet); } // Determine the destination channel (if any) SSHAbstractChannel destination = null; if (packet is SSHChannelMessage) { destination = channels[((SSHChannelMessage)packet).ChannelID]; } // Call the destination so that they may process the message bool processed = destination == null ? ProcessGlobalMessage(packet) : destination.ProcessChannelMessage((SSHChannelMessage)packet); // If the previous call did not process the message then add to the // destinations message store if (!processed) { SSHPacketStore ms = destination == null? global : destination.MessageStore; //#if DEBUG // System.Diagnostics.Trace.WriteLine("Adding message " + packet.MessageID + " to store " + ms.ToString() ); //#endif ms.AddMessage(packet); } return(!processed); }
internal SSHAbstractStream(SSHAbstractChannel enclosingInstance) { InitBlock(enclosingInstance); }
private void InitBlock(SSHAbstractChannel enclosingInstance) { this.enclosingInstance = enclosingInstance; }