protected override void XAttachPipe(Pipe pipe, bool icanhasall) { Debug.Assert(pipe != null); // ZMQ_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.Terminate (false); }
private void AttachPipe(Pipe pipe, bool icanhasall) { // First, register the pipe so that we can terminate it later on. pipe.SetEventSink(this); m_pipes.Add(pipe); // Let the derived socket type know about new pipe. XAttachPipe(pipe, icanhasall); // If the socket is already being closed, ask any new pipes to terminate // straight away. if (IsTerminating) { RegisterTermAcks(1); pipe.Terminate(false); } }
public void Hiccuped(Pipe pipe) { if (m_options.DelayAttachOnConnect) pipe.Terminate(false); else // Notify derived sockets of the hiccup XHiccuped(pipe); }
protected override bool XSend(ref Msg msg, SendReceiveOptions flags) { // If this is the first part of the message it's the ID of the // peer to send the message to. if (!m_moreOut) { Debug.Assert(m_currentOut == null); // If we have malformed message (prefix with no subsequent message) // then just silently ignore it. // TODO: The connections should be killed instead. if (msg.HasMore) { m_moreOut = true; // Find the pipe associated with the identity stored in the prefix. // If there's no such pipe just silently ignore the message, unless // mandatory is set. Blob identity = new Blob(msg.Data, msg.Size); Outpipe op; if (m_outpipes.TryGetValue(identity, out op)) { m_currentOut = op.Pipe; if (!m_currentOut.CheckWrite()) { op.Active = false; m_currentOut = null; if (m_mandatory) { m_moreOut = false; return(false); } } } else if (m_mandatory) { m_moreOut = false; throw NetMQException.Create(ErrorCode.EHOSTUNREACH); } } // Detach the message from the data buffer. msg.Close(); msg.InitEmpty(); return(true); } if (m_options.RawSocket) { msg.ResetFlags(MsgFlags.More); } // Check whether this is the last part of the message. m_moreOut = msg.HasMore; // Push the message into the pipe. If there's no out pipe, just drop it. if (m_currentOut != null) { // Close the remote connection if user has asked to do so // by sending zero length message. // Pending messages in the pipe will be dropped (on receiving term- ack) if (m_rawSocket && msg.Size == 0) { m_currentOut.Terminate(false); msg.Close(); msg.InitEmpty(); m_currentOut = null; return(true); } bool ok = m_currentOut.Write(ref msg); if (!ok) { m_currentOut = null; } else if (!m_moreOut) { m_currentOut.Flush(); m_currentOut = null; } } else { msg.Close(); } // Detach the message from the data buffer. msg.InitEmpty(); return(true); }