Beispiel #1
0
        public void SharedMemIO_Basic()
        {
            SharedMemOutbox outBox;

            ready   = false;
            recvMsg = null;
            thread  = new Thread(new ThreadStart(BasicThreadFunc));
            thread.Start();

            while (!ready)
            {
                Thread.Sleep(100);
            }

            outBox = new SharedMemOutbox(100, TimeSpan.FromSeconds(10));
            outBox.Send("BasicIn", Encoding.UTF8.GetBytes("Hello World!"));
            outBox.Close();

            thread.Join();

            Assert.AreEqual("Hello World!", recvMsg);
        }
Beispiel #2
0
        /// <summary>
        /// Sends the query message to the named service instance and waits for
        /// a reply.
        /// </summary>
        /// <param name="serviceName">The service name.</param>
        /// <param name="query">The query message.</param>
        /// <returns>The reply message.</returns>
        /// <remarks>
        /// Throws a TimeoutException if the service doesn't respond by MaxWaitTime.
        /// </remarks>
        private ServiceMsg Query(string serviceName, ServiceMsg query)
        {
            using (TimedLock.Lock(this))
            {
                refID       = Helper.NewGuid();
                query.RefID = refID;
            }

            query["Reply-To"] = ControlMemPrefix + id.ToString();

            outbox.Send(ServiceMemPrefix + serviceName, query.ToBytes());
            if (!onReply.WaitOne(MaxWaitTime, false))
            {
                throw new System.TimeoutException();
            }

            if (reply.Command != "Ack")
            {
                throw new InvalidOperationException("Invalid Service response.");
            }

            return(reply);
        }
Beispiel #3
0
 /// <summary>
 /// Sends a reply to the query passed.
 /// </summary>
 /// <param name="query">The query message received.</param>
 /// <param name="ack">The reply.</param>
 private void ReplyTo(ServiceMsg query, ServiceMsg ack)
 {
     ack.RefID = query.RefID;
     outbox.Send(query["Reply-To"], ack.ToBytes());
 }