static XSub() { s_sendSubscription = (data, size, arg) => { Pipe pipe = (Pipe) arg; // Create the subsctription message. Msg msg = new Msg(size + 1); msg.Put((byte)1); msg.Put(data,1, size); // Send it to the pipe. bool sent = pipe.Write (msg); // If we reached the SNDHWM, and thus cannot send the subscription, drop // the subscription message instead. This matches the behaviour of // zmq_setsockopt(ZMQ_SUBSCRIBE, ...), which also drops subscriptions // when the SNDHWM is reached. if (!sent) msg.Close (); }; }
public bool Send(Msg msg, SendRecieveOptions flags) { // Drop the message if required. If we are at the end of the message // switch back to non-dropping mode. if (m_dropping) { m_more = msg.HasMore; m_dropping = m_more; msg.Close (); return true; } while (m_active > 0) { if (m_pipes[m_current].Write (msg)) break; Debug.Assert(!m_more); m_active--; if (m_current < m_active) Utils.Swap (m_pipes, m_current, m_active); else m_current = 0; } // If there are no pipes we cannot send the message. if (m_active == 0) { ZError.ErrorNumber = ErrorNumber.EAGAIN; return false; } // If it's part of the message we can fluch it downstream and // continue round-robinning (load balance). m_more = msg.HasMore; if (!m_more) { m_pipes[m_current].Flush(); if (m_active > 1) m_current = (m_current + 1) % m_active; } return true; }