Copy() public method

Close this Msg, and effectively make this Msg a copy of the given source Msg by simply setting it to point to the given source Msg. If this is a Pool Msg, then this also increases the reference-counter and sets the Shared bit.
The object is not initialised.
public Copy ( Msg &src ) : void
src Msg the source Msg to copy from
return void
Exemplo n.º 1
0
        private static void ProxyBetween(IReceivingSocket from, IOutgoingSocket to, [CanBeNull] IOutgoingSocket control)
        {
            var msg = new Msg();

            msg.InitEmpty();

            var copy = new Msg();

            copy.InitEmpty();

            while (true)
            {
                from.Receive(ref msg);
                var more = msg.HasMore;

                if (control != null)
                {
                    copy.Copy(ref msg);

                    control.Send(ref copy, more);
                }

                to.Send(ref msg, more);

                if (!more)
                {
                    break;
                }
            }

            copy.Close();
            msg.Close();
        }
Exemplo n.º 2
0
        private static void ProxyBetween(NetMQSocket from, NetMQSocket to, [CanBeNull] NetMQSocket control)
        {
            Msg msg = new Msg();

            msg.InitEmpty();

            Msg copy = new Msg();

            copy.InitEmpty();

            while (true)
            {
                from.Receive(ref msg, SendReceiveOptions.None);
                bool more = from.Options.ReceiveMore;

                if (control != null)
                {
                    copy.Copy(ref msg);

                    control.Send(ref copy, more ? SendReceiveOptions.SendMore : SendReceiveOptions.None);
                }

                to.Send(ref msg, more ? SendReceiveOptions.SendMore : SendReceiveOptions.None);

                if (!more)
                {
                    break;
                }
            }

            copy.Close();
            msg.Close();
        }
Exemplo n.º 3
0
        private void OnBackendReady(object sender, NetMQSocketEventArgs e)
        {
            Msg msg = new Msg();

            msg.InitEmpty();

            Msg copy = new Msg();

            copy.InitEmpty();

            while (true)
            {
                m_backend.Receive(ref msg, SendReceiveOptions.None);
                bool more = m_backend.Options.ReceiveMore;

                if (m_control != null)
                {
                    copy.Copy(ref msg);

                    m_control.Send(ref copy, more ? SendReceiveOptions.SendMore : SendReceiveOptions.None);
                }

                m_frontend.Send(ref msg, more ? SendReceiveOptions.SendMore : SendReceiveOptions.None);



                if (!more)
                {
                    break;
                }
            }

            copy.Close();
            msg.Close();
        }
Exemplo n.º 4
0
    public bool sendAndReceive(ref NetMQ.Msg req_msg, ref NetMQ.Msg resp_msg)
    {
        if (socket == null)
        {
            reconnect();
        }

        StdMessage m = new StdMessage(req_msg.Data[1], req_msg.Data[2]);

        NetMQ.Msg copy = new NetMQ.Msg();
        bool      ok   = false;

        for (uint i = 0; i < retries; i++)
        {
            copy.Copy(ref req_msg);

            // send
            if (!socket.TrySend(ref copy, TimeSpan.FromMilliseconds(min_trysend_ms), false))
            {
                ok = false;
                UnityEngine.Debug.Log("ReliableExternalClient: could not send");
                break;

                //TODO: clear enqueued messages when server is offline
            }
            //UnityEngine.Debug.Log("ReliableExternalClient: request sent " + m.to_string());

            // receive
            if (socket.TryReceive(ref resp_msg, timeout))
            {
                ok = true;
                // UnityEngine.Debug.Log("ReliableExternalClient: response received "
                //+ new StdMessage(resp_msg.Data[1], resp_msg.Data[2]).to_string());
                break;
            }

            //UnityEngine.Debug.Log(String.Format("ReliableExternalClient: no response from server {0}. Retrying", srvAddress));
            reconnect();
        }

        if (!ok)
        {
            UnityEngine.Debug.Log(String.Format("ReliableExternalClient: server {0} seems to be offline. Abandoning", srvAddress));
        }

        copy.Close();
        socket.Dispose();  //call Dispose on all sockets before cleanup the netmq context
        socket.Close();

        socket = null;

        if (socket == null)
        {
            UnityEngine.Debug.Log("ReliableExternalClient: socket closed and null");
        }

        return(ok);
    }
Exemplo n.º 5
0
        private static void ProxyBetween(IReceivingSocket from, IOutgoingSocket to, [CanBeNull] IOutgoingSocket control)
        {
            var msg = new Msg();
            msg.InitEmpty();

            var copy = new Msg();
            copy.InitEmpty();

            while (true)
            {
                from.Receive(ref msg);
                var more = msg.HasMore;

                if (control != null)
                {
                    copy.Copy(ref msg);

                    control.Send(ref copy, more);
                }

                to.Send(ref msg, more);

                if (!more)
                    break;
            }

            copy.Close();
            msg.Close();
        }
Exemplo n.º 6
0
        private static void ProxyBetween(NetMQSocket from, NetMQSocket to, [CanBeNull] NetMQSocket control)
        {
            var msg = new Msg();
            msg.InitEmpty();

            var copy = new Msg();
            copy.InitEmpty();

            while (true)
            {
                from.Receive(ref msg, SendReceiveOptions.None);
                bool more = from.Options.ReceiveMore;

                if (control != null)
                {
                    copy.Copy(ref msg);

                    control.Send(ref copy, more ? SendReceiveOptions.SendMore : SendReceiveOptions.None);
                }

                to.Send(ref msg, more ? SendReceiveOptions.SendMore : SendReceiveOptions.None);

                if (!more)
                {
                    break;
                }
            }

            copy.Close();
            msg.Close();
        }