Ejemplo n.º 1
0
 public void PostResponse(Message msg, int messageNumber)
 {
     byte[] body = msg.GetBody();
     lock (stream)
     {
         writer.Write((int)msg.Type);
         writer.Write(-messageNumber);
         writer.Write(body.Length);
         writer.Flush();
         stream.Write(body, 0, body.Length);
     }
 }
Ejemplo n.º 2
0
 public Message SendMessage(Message msg)
 {
     byte[] body = msg.GetBody();
     int msgIndex = GetMessageIndex();
     EventWaitHandle waiter = new ManualResetEvent(false);
     // Have to add waithandle before we send data, incase the response comes back before we add it.
     lock (waitHandles)
     {
         waitHandles.Add(msgIndex, waiter);
     }
     lock (stream)
     {
         writer.Write((int)msg.Type);
         writer.Write(msgIndex);
         writer.Write(body.Length);
         writer.Flush();
         stream.Write(body, 0, body.Length);
     }
     waiter.WaitOne();
     lock (waitHandles)
     {
         waitHandles.Remove(msgIndex);
     }
     lock (responses)
     {
         if (responses.ContainsKey(msgIndex))
         {
             Message answer = responses[msgIndex];
             responses.Remove(msgIndex);
             return answer;
         }
         else
             throw new IOException("Send failed.");
     }
 }
Ejemplo n.º 3
0
 public void PostBroadcast(Message msg)
 {
     PostResponse(msg, 0);
 }