protected internal override void OnPipeClosed(Pipe pipe) { if (m_pipe == pipe) { m_pipe = null; } }
public static void SendBind(Socket destination, Pipe pipe, bool increaseSequenceNumber) { if(increaseSequenceNumber) destination.IncreaseSequenceNumber(); var command = new BindCommand(destination, pipe); SendCommand(command); }
protected internal override void OnNewPipe(Pipe pipe) { // Pair socket can only be connected to a single peer. // The socket rejects any further connection requests. if (m_pipe == null) m_pipe = pipe; else pipe.Close(false); }
public void Hiccuped(Pipe pipe) { if (m_options.DelayAttachOnConnect) pipe.Terminate(false); else // Notify derived sockets of the hiccup XHiccuped(pipe); }
/// <summary> /// Indicate that the given pipe is now ready for reading. /// Pipe calls this on it's sink in response to ProcessActivateRead. /// When called upon an instance of SocketBase, this simply calls XReadActivated. /// </summary> /// <param name="pipe">the pipe to indicate is ready for reading</param> public void ReadActivated(Pipe pipe) { XReadActivated(pipe); }
/// <summary> /// <see cref="PipePair"/> uses this function to let us know about the peer pipe object. /// </summary> /// <param name="peer">The peer to be assigned.</param> private void SetPeer([NotNull] Pipe peer) { // Peer can be set once only. Debug.Assert(peer != null); m_peer = peer; }
/// <summary> /// The parent SessionBase class calls this when the Detach method finishes detaching. /// </summary> private void Detached() { // Transient session self-destructs after peer disconnects. if (!m_connect) { Terminate(); return; } // For delayed connect situations, terminate the pipe // and reestablish later on if (m_pipe != null && m_options.DelayAttachOnConnect && m_addr.Protocol != Address.PgmProtocol && m_addr.Protocol != Address.EpgmProtocol) { m_pipe.Hiccup(); m_pipe.Terminate(false); m_terminatingPipes.Add(m_pipe); m_pipe = null; } Reset(); // Reconnect. if (m_options.ReconnectIvl != -1) StartConnecting(true); // For subscriber sockets we hiccup the inbound pipe, which will cause // the socket object to resend all the subscriptions. if (m_pipe != null && (m_options.SocketType == ZmqSocketType.Sub || m_options.SocketType == ZmqSocketType.Xsub)) m_pipe.Hiccup(); }
public void Hiccuped(Pipe pipe) { // Hiccups are always sent from session to socket, not the other // way round. throw new NotSupportedException("Must Override"); }
/// <summary> /// Indicate that the given pipe is now ready for reading. /// Pipe calls this on it's sink in response to ProcessActivateRead. /// </summary> /// <param name="pipe">the pipe to indicate is ready for reading</param> public void ReadActivated(Pipe pipe) { // Skip activating if we're detaching this pipe if (m_pipe != pipe) { Debug.Assert(m_terminatingPipes.Contains(pipe)); return; } if (m_engine != null) m_engine.ActivateOut(); else m_pipe.CheckRead(); }
/// <summary> /// Attach the given pipe to this session. /// </summary> /// <remarks> /// This is to be used once only, when creating the session. /// </remarks> public void AttachPipe([NotNull] Pipe pipe) { Debug.Assert(!IsTerminating); Debug.Assert(m_pipe == null); Debug.Assert(pipe != null); m_pipe = pipe; m_pipe.SetEventSink(this); }
/// <summary> /// Process the bind command with the given pipe. /// </summary> /// <param name="pipe"></param> /// <exception cref="NotSupportedException">Not supported on the ZObject class.</exception> protected virtual void ProcessBind( Pipe pipe) { throw new NotSupportedException(); }
public Endpoint(Own own, Pipe pipe) { Own = own; Pipe = pipe; }
/// <summary> /// Process the bind command with the given pipe. /// </summary> /// <param name="pipe"></param> /// <exception cref="NotSupportedException">Not supported on the ZObject class.</exception> protected virtual void ProcessBind([NotNull] Pipe pipe) { throw new NotSupportedException(); }
protected void SendPipeTermAck([NotNull] Pipe destination) { SendCommand(new Command(destination, CommandType.PipeTermAck)); }
protected void SendHiccup([NotNull] Pipe destination, [NotNull] object pipe) { SendCommand(new Command(destination, CommandType.Hiccup, pipe)); }
protected void SendActivateWrite([NotNull] Pipe destination, long msgsRead) { SendCommand(new Command(destination, CommandType.ActivateWrite, msgsRead)); }
protected void SendActivateRead([NotNull] Pipe destination) { SendCommand(new Command(destination, CommandType.ActivateRead)); }
public static void SendActivateRead(Pipe destination) { var command = new ActivateReadCommand(destination); SendCommand(command); }
private void AttachPipe(Pipe pipe) { // First, register the pipe so that we can terminate it later on. m_pipes.Add(pipe); pipe.PipeClosed += PipeClosed; pipe.WriteActivated += WriteActivated; pipe.ReadActivated += ReadActivated; pipe.Hiccuped += Hiccuped; // Let the protocol know about new pipe. m_protocol.OnNewPipe(pipe); // If the socket is already being closed, ask any new pipes to terminate // straight away. if (IsClosing) { RegisterCloseAcks(1); pipe.Close(false); } }
public static void SendActivateWrite(Pipe destination, long messagesRead) { var command = new ActivateWriteCommand(destination, messagesRead); SendCommand(command); }
/// <summary> /// This gets called by ProcessPipeTermAck or XTerminated to respond to the termination of the given pipe. /// </summary> /// <param name="pipe">the pipe that was terminated</param> public void Terminated(Pipe pipe) { // Drop the reference to the deallocated pipe. Debug.Assert(m_pipe == pipe || m_terminatingPipes.Contains(pipe)); if (m_pipe == pipe) // If this is our current pipe, remove it m_pipe = null; else // Remove the pipe from the detached pipes set m_terminatingPipes.Remove(pipe); if (!IsTerminating && m_options.RawSocket) { if (m_engine != null) { m_engine.Terminate(); m_engine = null; } Terminate(); } // If we are waiting for pending messages to be sent, at this point // we are sure that there will be no more messages and we can proceed // with termination safely. if (m_pending && m_pipe == null && m_terminatingPipes.Count == 0) ProceedWithTerm(); }
public static void SendClosePipe(Pipe destination) { var command = new ClosePipeCommand(destination); SendCommand(command); }
public void WriteActivated(Pipe pipe) { // Skip activating if we're detaching this pipe if (m_pipe != pipe) { Debug.Assert(m_terminatingPipes.Contains(pipe)); return; } if (m_engine != null) m_engine.ActivateIn(); }
public static void SendHiccup(Pipe destination, YPipe<Frame> pipe) { var command = new HiccupCommand(destination, pipe); SendCommand(command); }
/// <summary> /// Process the Attach-request by hooking up the pipes /// and plugging in the given engine. /// </summary> /// <param name="engine">the IEngine to plug in</param> protected override void ProcessAttach(IEngine engine) { Debug.Assert(engine != null); // Create the pipe if it does not exist yet. if (m_pipe == null && !IsTerminating) { ZObject[] parents = { this, m_socket }; int[] highWaterMarks = { m_options.ReceiveHighWatermark, m_options.SendHighWatermark }; int[] lowWaterMarks = { m_options.ReceiveLowWatermark, m_options.SendLowWatermark }; bool[] delays = { m_options.DelayOnClose, m_options.DelayOnDisconnect }; Pipe[] pipes = Pipe.PipePair(parents, highWaterMarks, lowWaterMarks, delays); // Plug the local end of the pipe. pipes[0].SetEventSink(this); // Remember the local end of the pipe. Debug.Assert(m_pipe == null); m_pipe = pipes[0]; // Ask socket to plug into the remote end of the pipe. SendBind(m_socket, pipes[1]); } // Plug in the engine. Debug.Assert(m_engine == null); m_engine = engine; m_engine.Plug(m_ioThread, this); }
/// <summary> /// Send the Bind command /// </summary> /// <param name="destination"></param> /// <param name="pipe"></param> /// <param name="incSeqnum"></param> protected void SendBind( Own destination, Pipe pipe, bool incSeqnum = true) { if (incSeqnum) destination.IncSeqnum(); SendCommand(new Command(destination, CommandType.Bind, pipe)); }
/// <summary> /// Create a new Pipe object with the given parent, and inbound and outbound YPipes. /// </summary> /// <remarks> /// Constructor is private as pipe can only be created using <see cref="PipePair"/> method. /// </remarks> private Pipe( [NotNull] ZObject parent, [NotNull] YPipe<Msg> inboundPipe, [NotNull] YPipe<Msg> outboundPipe, int inHighWatermark, int outHighWatermark, int predefinedLowWatermark, bool delay) : base(parent) { m_parent = parent; m_inboundPipe = inboundPipe; m_outboundPipe = outboundPipe; m_inActive = true; m_outActive = true; m_highWatermark = outHighWatermark; m_lowWatermark = ComputeLowWatermark(inHighWatermark, predefinedLowWatermark); m_numberOfMessagesRead = 0; m_numberOfMessagesWritten = 0; m_peersMsgsRead = 0; m_peer = null; m_sink = null; m_state = State.Active; m_delay = delay; }
protected void SendActivateRead( Pipe destination) { SendCommand(new Command(destination, CommandType.ActivateRead)); }
/// <summary> /// Process a Bind command by attaching the given Pipe. /// </summary> /// <param name="pipe">the Pipe to attach</param> protected override void ProcessBind(Pipe pipe) { AttachPipe(pipe); }
protected void SendActivateWrite( Pipe destination, long msgsRead) { SendCommand(new Command(destination, CommandType.ActivateWrite, msgsRead)); }
/// <summary> /// When called upon an instance of SocketBase, this simply calls XWriteActivated. /// </summary> /// <param name="pipe">the pipe to indicate is ready for writing</param> public void WriteActivated(Pipe pipe) { XWriteActivated(pipe); }
protected void SendHiccup( Pipe destination, object pipe) { SendCommand(new Command(destination, CommandType.Hiccup, pipe)); }
/// <summary> /// This gets called by ProcessPipeTermAck or XTerminated to respond to the termination of the given pipe. /// </summary> /// <param name="pipe">the pipe that was terminated</param> public void Terminated(Pipe pipe) { // Notify the specific socket type about the pipe termination. XTerminated(pipe); // Remove pipe from inproc pipes var pipesToDelete = m_inprocs.Where(i => i.Value == pipe).Select(i => i.Key).ToArray(); foreach (var addr in pipesToDelete) { m_inprocs.Remove(addr); } // Remove the pipe from the list of attached pipes and confirm its // termination if we are already shutting down. m_pipes.Remove(pipe); if (IsTerminating) UnregisterTermAck(); }
protected void SendPipeTermAck( Pipe destination) { SendCommand(new Command(destination, CommandType.PipeTermAck)); }
/// <summary> /// Take ownership of the given <paramref name="endpoint"/> and register it against the given <paramref name="address"/>. /// </summary> private void AddEndpoint([NotNull] string address, [NotNull] Own endpoint, Pipe pipe) { // Activate the session. Make it a child of this socket. LaunchChild(endpoint); m_endpoints[address] = new Endpoint(endpoint, pipe); }