/// <summary> /// Receive and return a Command from the command-pipe. /// </summary> /// <param name="timeout">how long to wait for a command (in milliseconds) before returning</param> /// <param name="command"></param> public bool TryRecv(int timeout, out Command command) { // Try to get the command straight away. if (m_active) { if (m_commandPipe.TryRead(out command)) { return(true); } // If there are no more commands available, switch into passive state. m_active = false; m_signaler.Recv(); } // Wait for signal from the command sender. if (!m_signaler.WaitEvent(timeout)) { command = default(Command); return(false); } // We've got the signal. Now we can switch into active state. m_active = true; // Get a command. var ok = m_commandPipe.TryRead(out command); Debug.Assert(ok); return(ok); }
/// <summary> /// Receive and return a Command from the command-pipe. /// </summary> /// <param name="timeout">how long to wait for a command (in milliseconds) before returning</param> /// <param name="command"></param> public bool TryRecv(int timeout, out Command command) { // Try to get the command straight away. if (m_active) { if (m_commandPipe.TryRead(out command)) { return(true); } // If there are no more commands available, switch into passive state. m_active = false; m_signaler.Recv(); } // Wait for signal from the command sender. if (!m_signaler.WaitEvent(timeout)) { command = default(Command); return(false); } // We've got the signal. Now we can switch into active state. m_active = true; // Get a command. var ok = m_commandPipe.TryRead(out command); //Seems to get hung up occasionally if the ZMQ socket gets messed with //Debug.Assert(ok); if (!ok) { Console.WriteLine("Error reading a ZMQ frame."); } return(ok); }
public Command Recv(int timeout) { Command cmd; // Try to get the command straight away. if (m_active) { m_commandPipe.Read(out cmd); if (cmd != null) { return(cmd); } // If there are no more commands available, switch into passive state. m_active = false; m_signaler.Recv(); } // Wait for signal from the command sender. bool rc = m_signaler.WaitEvent(timeout); if (!rc) { return(null); } // We've got the signal. Now we can switch into active state. m_active = true; // Get a command. bool ok = m_commandPipe.Read(out cmd); Debug.Assert(ok); return(cmd); }