Ejemplo n.º 1
0
        private IErlObject executeRPC(ErlAtom module, ErlAtom func, ErlList args, ErlMbox mbox = null)
        {
            var lnode  = ensureLocalNode("executeRPC");
            var mowner = mbox == null;

            if (mowner)
            {
                mbox = lnode.CreateMbox();
            }
            try
            {
                var timeoutMs = this.CallTimeoutMs;
                if (timeoutMs <= 0)
                {
                    timeoutMs = DEFAULT_RPC_TIMEOUT_MS;
                }

                return(mbox.RPC(m_RemoteName, module, func, args, timeoutMs, remoteCookie: m_RemoteCookie));
            }
            catch (Exception error)
            {
                throw new ErlDataAccessException(StringConsts.ERL_DS_RPC_EXEC_ERROR.Args(
                                                     "{0}:{1}({2})".Args(module, func, args.ToString().TakeFirstChars(20)),
                                                     error.ToMessageWithType(), error));
            }
            finally
            {
                if (mowner)
                {
                    lnode.CloseMbox(mbox);
                }
            }
        }
Ejemplo n.º 2
0
        private bool register(ErlAtom name, ErlMbox mbox)
        {
            bool    added = false;
            ErlMbox m     = m_ByName.GetOrAdd(name, n => { added = true; return(mbox); });

            return(added);
        }
Ejemplo n.º 3
0
    public override void read(ErlKVMessage message)
    {
        ErlAtom str = (message.getValue("msg") as ErlAtom);

        if (str == null)
        {
            return;
        }

        if (str.Value == "ok")
        {
            if (callback != null)
            {
                callback();
            }
        }
        else if (str.Value == "aready_award")
        {
            UiManager.Instance.createMessageLintWindow(LanguageConfigManager.Instance.getLanguage("s0504"));
        }
        else if (str.Value == "error")
        {
            UiManager.Instance.createMessageLintWindow(LanguageConfigManager.Instance.getLanguage("s0204"));
        }
        else
        {
            MonoBase.print(GetType() + "error:" + str);
        }
    }
Ejemplo n.º 4
0
        internal ErlTuple ToCtrlTuple(ErlAtom cookie)
        {
            switch (Type)
            {
            case Tag.Link: return(new ErlTuple((int)Type, m_From, m_To));

            case Tag.Send: return(new ErlTuple((int)Type, cookie, m_To));

            case Tag.Exit: return(new ErlTuple((int)Type, m_From, m_To, Reason));

            case Tag.Unlink: return(new ErlTuple((int)Type, m_From, m_To));

            case Tag.NodeLink: return(new ErlTuple((int)Type));

            case Tag.RegSend: return(new ErlTuple((int)Type, m_From, cookie, m_To));

            case Tag.GroupLeader: return(new ErlTuple((int)Type, m_From, m_To));

            case Tag.Exit2: return(new ErlTuple((int)Type, m_From, m_To, Reason));

            case Tag.SendTT: return(new ErlTuple((int)Type, cookie, m_To, TraceToken));

            case Tag.Exit2TT:
            case Tag.ExitTT: return(new ErlTuple((int)Type, m_From, m_To, TraceToken, Reason));

            case Tag.RegSendTT: return(new ErlTuple((int)Type, m_From, cookie, m_To, TraceToken));

            case Tag.MonitorP:
            case Tag.DemonitorP: return(new ErlTuple((int)Type, m_From, Recipient, Ref));

            case Tag.MonitorPexit: return(new ErlTuple((int)Type, Sender, m_To, Ref, Reason));

            default: throw new ErlException(StringConsts.ERL_INVALID_VALUE_ERROR.Args(Type));
            }
        }
Ejemplo n.º 5
0
 private static ErlType[] getErlArr(List <object> jsonList)
 {
     ErlType[] arr = new ErlType[jsonList.Count];
     for (int i = 0; i < jsonList.Count; i++)
     {
         List <object> data = jsonList[i] as List <object>;
         ErlType       erl  = null;
         if (data[0] as string == typeof(ErlInt).Name)
         {
             erl = new ErlInt(StringKit.toInt(data[1].ToString()));
         }
         else if (data[0] as string == typeof(ErlString).Name)
         {
             erl = new ErlString(data[1].ToString());
         }
         else if (data[0] as string == typeof(ErlByte).Name)
         {
             erl = new ErlByte(byte.Parse(data[1].ToString()));
         }
         else if (data[0] as string == typeof(ErlAtom).Name)
         {
             erl = new ErlAtom(data[1].ToString());
         }
         else if (data[0] as string == typeof(ErlNullList).Name)
         {
             erl = new ErlNullList();
         }
         else if (data[0] as string == typeof(ErlArray).Name)
         {
             erl = new ErlArray(getErlArr(data[1] as List <object>));
         }
         arr[i] = erl;
     }
     return(arr);
 }
Ejemplo n.º 6
0
 internal static ErlTuple EncodeRPCcast(
     ErlPid from, ErlAtom mod, ErlAtom fun, ErlList args, IErlObject gleader)
 {
     /*{'$gen_cast', { cast, Mod, Fun, Args, GroupLeader}} */
     return(new ErlTuple(
                ConstAtoms.GenCast,
                new ErlTuple(ConstAtoms.Cast, mod, fun, args, gleader)));
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Register a named mailbox with the registry. Name must not be empty
 /// </summary>
 public bool Register(ErlAtom name, ErlMbox mbox)
 {
     if (name == ErlAtom.Null)
     {
         throw new ErlException(StringConsts.ERL_INVALID_MBOX_NAME_ERROR);
     }
     return(register(name, mbox));
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Look up a mailbox based on its name
 /// </summary>
 /// <returns>Mailbox or null if the name is not registered</returns>
 public ErlMbox this[ErlAtom name]
 {
     get
     {
         ErlMbox m;
         return(m_ByName.TryGetValue(name, out m) ? m : null);
     }
 }
Ejemplo n.º 9
0
 private IErlObject ioProcessGetLine(
     ErlAtom encoding, IErlObject prompt, IErlObject replyAs)
 {
     return(s_ReplyPattern.Subst(
                new ErlVarBind {
         { RA, replyAs },
         { R, (IErlObject)Tuple.Create(ConstAtoms.Error, ConstAtoms.Request) }
     }));
 }
Ejemplo n.º 10
0
 private IErlObject ioProcessPutChars(ErlAtom encoding,
                                      ErlString str, IErlObject replyAs)
 {
     Node.IoOutput(encoding, str);
     return(s_ReplyPattern.Subst(
                new ErlVarBind {
         { RA, replyAs }, { R, ConstAtoms.Ok }
     }));
 }
Ejemplo n.º 11
0
 private ErlAbstractConnection(ErlLocalNode home, ErlRemoteNode peer, TcpClient s, ErlAtom? cookie = null)
 {
   m_Peer = peer;
   m_Home = home;
   m_TcpClient = s;
   m_Cookie = !cookie.HasValue || cookie.Value == ErlAtom.Null
       ? (peer.Cookie == ErlAtom.Null ? home.Cookie : peer.Cookie) : cookie.Value;
   m_SentBytes = 0;
   m_ReceivedBytes = 0;
   m_MaxPayloadLength = DEFAULT_MAX_PAYLOAD_LENGTH;
 }
Ejemplo n.º 12
0
 private void node_NodeStatusChange(ErlLocalNode sender, ErlAtom node, bool up, object info)
 {
     if (!node.Equals(this.m_RemoteName))
     {
         return;                             //filter-out nodes that are not mine
     }
     if (!up)
     {
         asyncReconnect();
     }
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Create a named mailbox if one is not already registered, otherwise
        /// return registered mailbox
        /// </summary>
        public ErlMbox Create(ErlAtom name)
        {
            var mbox = m_ByName.GetOrAdd(name, n => {
                var pid      = m_Node.CreatePid();
                var m        = new ErlMbox(m_Node, pid, n);
                m_ByPid[pid] = m;
                return(m);
            });

            return(mbox);
        }
Ejemplo n.º 14
0
 public static ErlType complexAnalyse(ByteBuffer data)
 {
     int position = data.position;
     int num2 = data.readByte();
     data.position = position;
     if ((num2 == ErlArray.TAG[0]) || (num2 == ErlArray.TAG[1]))
     {
         ErlArray array = new ErlArray(null);
         array.bytesRead(data);
         return array;
     }
     switch (num2)
     {
     case 0x6a:
         {
             ErlNullList list = new ErlNullList();
             list.bytesRead(data);
             return list;
         }
     case 0x6c:
         {
             ErlList list2 = new ErlList(null);
             list2.bytesRead(data);
             return list2;
         }
     case 100:
         {
             ErlAtom atom = new ErlAtom(null);
             atom.bytesRead(data);
             return atom;
         }
     case 0x6b:
         {
             ErlString str = new ErlString(null);
             str.sampleBytesRead(data);
             return str;
         }
     case 110:
         {
             ErlLong @long = new ErlLong();
             @long.bytesRead(data);
             return @long;
         }
     case 0x6d:
         {
             ErlByteArray array2 = new ErlByteArray(null);
             array2.bytesRead(data);
             return array2;
         }
     }
     return null;
 }
Ejemplo n.º 15
0
 private ErlAbstractConnection(ErlLocalNode home, ErlRemoteNode peer, IErlTransport s, ErlAtom? cookie = null)
 {
   m_Peer = peer;
   m_Home = home;
   m_Transport = s;
   m_Cookie = !cookie.HasValue || cookie.Value == ErlAtom.Null
       ? (peer.Cookie == ErlAtom.Null ? home.Cookie : peer.Cookie) : cookie.Value;
   m_SentBytes = 0;
   m_ReceivedBytes = 0;
   m_MaxPayloadLength = DEFAULT_MAX_PAYLOAD_LENGTH;
   if (m_Transport != null)
     m_Transport.Trace += (o, t, d, msg) => home.OnTrace(t, d, msg);
 }
Ejemplo n.º 16
0
        /// <summary>
        /// Create a named mailbox if one is not already registered, otherwise
        /// return registered mailbox
        /// </summary>
        public ErlMbox Create(ErlAtom name)
        {
            if (name == ErlAtom.Null)
            {
                throw new NFXException(StringConsts.ERL_VALUE_MUST_NOT_BE_NULL_ERROR);
            }

            var mbox = m_ByName.GetOrAdd(name, n =>
            {
                var pid      = m_Node.CreatePid();
                var m        = new ErlMbox(m_Node, pid, n);
                m_ByPid[pid] = m;
                return(m);
            });

            return(mbox);
        }
Ejemplo n.º 17
0
        public void ErlAtomTest()
        {
            var am_test = new ErlAtom("test");

            Assert.IsTrue(am_test.Equals(new ErlAtom("test")));
            Assert.AreEqual(am_test, new ErlAtom("test"));
            Assert.AreEqual("test", am_test.Value);
            Assert.AreEqual("test", am_test.ToString());
            Assert.IsTrue(am_test.IsScalar);
            Assert.AreEqual(ErlTypeOrder.ErlAtom, am_test.TypeOrder);

            Assert.IsTrue(am_test.Matches(new ErlAtom("test")));
            Assert.AreEqual(new ErlVarBind(), am_test.Match(new ErlAtom("test")));

            var am_Test = new ErlAtom("Test");

            Assert.AreEqual("'Test'", am_Test.ToString());
            Assert.AreEqual(4, am_Test.Length);
            Assert.AreNotEqual(am_test, am_Test);

            IErlObject temp = null;

            Assert.IsFalse(am_test.Subst(ref temp, new ErlVarBind()));

            Assert.IsTrue(am_Test.Visit(true, (acc, o) => acc));

            Assert.DoesNotThrow(() => { var x = am_test.ValueAsObject; });
            Assert.Throws <ErlIncompatibleTypesException>(() => { var x = am_test.ValueAsInt; });
            Assert.Throws <ErlIncompatibleTypesException>(() => { var x = am_test.ValueAsLong; });
            Assert.Throws <ErlIncompatibleTypesException>(() => { var x = am_test.ValueAsDecimal; });
            Assert.Throws <ErlIncompatibleTypesException>(() => { var x = am_test.ValueAsDateTime; });
            Assert.Throws <ErlIncompatibleTypesException>(() => { var x = am_test.ValueAsTimeSpan; });
            Assert.Throws <ErlIncompatibleTypesException>(() => { var x = am_test.ValueAsDouble; });
            Assert.DoesNotThrow(() => { var x = am_test.ValueAsString; });
            Assert.DoesNotThrow(() => { var x = am_test.ValueAsBool; });
            Assert.AreEqual('a', new ErlAtom("a").ValueAsChar);
            Assert.Throws <ErlIncompatibleTypesException>(() => { var x = am_test.ValueAsByteArray; });

            string s = am_test; // Implicit conversion

            Assert.AreEqual("test", s);

            ErlAtom a = "abc"; // Implicit conversion

            Assert.AreEqual("abc", a.Value);
        }
Ejemplo n.º 18
0
        public void AtomTableTest()
        {
            Assert.AreEqual(0, AtomTable.Instance[string.Empty]);

              Assert.AreEqual(1, AtomTable.Instance["true"]);

              Assert.AreEqual(2, AtomTable.Instance["false"]);

              Assert.AreEqual(1, ErlAtom.True.Index);
              Assert.AreEqual(2, ErlAtom.False.Index);

              bool found = AtomTable.Instance.IndexOf("ok") != -1;
              int count = AtomTable.Instance.Count;

              var am_ok = new ErlAtom("ok");

              Assert.AreEqual(found ? am_ok.Index : AtomTable.Instance.Count - 1, am_ok.Index);
              Assert.AreEqual(found ? count : count + 1, AtomTable.Instance.Count);
        }
Ejemplo n.º 19
0
        public void AtomTableTest()
        {
            Assert.AreEqual(0, AtomTable.Instance[string.Empty]);

            Assert.AreEqual(1, AtomTable.Instance["true"]);

            Assert.AreEqual(2, AtomTable.Instance["false"]);

            Assert.AreEqual(1, ErlAtom.True.Index);
            Assert.AreEqual(2, ErlAtom.False.Index);

            bool found = AtomTable.Instance.IndexOf("ok") != -1;
            int  count = AtomTable.Instance.Count;

            var am_ok = new ErlAtom("ok");

            Assert.AreEqual(found ? am_ok.Index : AtomTable.Instance.Count - 1, am_ok.Index);
            Assert.AreEqual(found ? count : count + 1, AtomTable.Instance.Count);
        }
Ejemplo n.º 20
0
    /// <summary>
    /// 二进制数据解析 走到这里,肯定是erlang标准二进制数据
    /// </summary>
    /// <returns>The analyse.</returns>
    /// <param name="data">Data.</param>
    public static ErlType  complexAnalyse(ByteBuffer data)
    {
        int position = data.position;
        int tag      = data.readByte();

        data.position = position;
        //			 MonoBehaviour.print("----------complexAnalyse--------------"+tag);
        if (tag == ErlArray.TAG [0] || tag == ErlArray.TAG [1])
        {
            ErlArray erlArray = new ErlArray(null);
            erlArray.bytesRead(data);
            return(erlArray);
        }
        else if (tag == ErlNullList.TAG)
        {
            ErlNullList erlNullList = new ErlNullList();
            erlNullList.bytesRead(data);
            return(erlNullList);
        }
        else if (tag == ErlList.TAG)
        {
            ErlList erlList = new ErlList(null);
            erlList.bytesRead(data);
            return(erlList);
        }
        else if (tag == ErlAtom.TAG)
        {
            ErlAtom erlAtom = new ErlAtom(null);
            erlAtom.bytesRead(data);
            return(erlAtom);
        }
        else if (tag == ErlString.TAG)
        {
            ErlString erlString = new ErlString(null);
            erlString.sampleBytesRead(data);
            return(erlString);
        }
        else
        {
            return(null);
        }
    }
Ejemplo n.º 21
0
        private IErlObject ioProcessPutChars(ErlAtom encoding,
                                             ErlAtom mod, ErlAtom fun, ErlList args, IErlObject replyAs)
        {
            string term;

            if (mod == ConstAtoms.Io_Lib && fun == ConstAtoms.Format && args.Count == 2)
            {
                try   { term = ErlObject.Format(args); }
                catch { term = "{0}:{1}({2})".Args(mod, fun, args.ToString(true)); }
            }
            else
            {
                term = "{0}:{1}({2})".Args(mod, fun, args.ToString(true));
            }
            Node.IoOutput(encoding, new ErlString(term));
            return(s_ReplyPattern.Subst(
                       new ErlVarBind {
                { RA, replyAs }, { R, ConstAtoms.Ok }
            }));
        }
Ejemplo n.º 22
0
        public void ErlAtomTest()
        {
            var am_test = new ErlAtom("test");
              Assert.IsTrue(am_test.Equals(new ErlAtom("test")));
              Assert.AreEqual(am_test, new ErlAtom("test"));
              Assert.AreEqual("test", am_test.Value);
              Assert.AreEqual("test", am_test.ToString());
              Assert.IsTrue(am_test.IsScalar);
              Assert.AreEqual(ErlTypeOrder.ErlAtom, am_test.TypeOrder);

              Assert.IsTrue(am_test.Matches(new ErlAtom("test")));
              Assert.AreEqual(new ErlVarBind(), am_test.Match(new ErlAtom("test")));

              var am_Test = new ErlAtom("Test");
              Assert.AreEqual("'Test'", am_Test.ToString());
              Assert.AreEqual(4, am_Test.Length);
              Assert.AreNotEqual(am_test, am_Test);

              IErlObject temp = null;
              Assert.IsFalse(am_test.Subst(ref temp, new ErlVarBind()));

              Assert.IsTrue(am_Test.Visit(true, (acc, o) => acc));

              Assert.DoesNotThrow(() => { var x = am_test.ValueAsObject; });
              Assert.Throws<ErlIncompatibleTypesException>(() => { var x = am_test.ValueAsInt; });
              Assert.Throws<ErlIncompatibleTypesException>(() => { var x = am_test.ValueAsLong; });
              Assert.Throws<ErlIncompatibleTypesException>(() => { var x = am_test.ValueAsDecimal; });
              Assert.Throws<ErlIncompatibleTypesException>(() => { var x = am_test.ValueAsDateTime; });
              Assert.Throws<ErlIncompatibleTypesException>(() => { var x = am_test.ValueAsTimeSpan; });
              Assert.Throws<ErlIncompatibleTypesException>(() => { var x = am_test.ValueAsDouble; });
              Assert.DoesNotThrow(() => { var x = am_test.ValueAsString; });
              Assert.DoesNotThrow(() => { var x = am_test.ValueAsBool; });
              Assert.AreEqual('a', new ErlAtom("a").ValueAsChar);
              Assert.Throws<ErlIncompatibleTypesException>(() => { var x = am_test.ValueAsByteArray; });

              string s = am_test;  // Implicit conversion
              Assert.AreEqual("test", s);

              ErlAtom a = "abc";   // Implicit conversion
              Assert.AreEqual("abc", a.Value);
        }
Ejemplo n.º 23
0
 public void Down(ErlRef eref, ErlPid pid, ErlAtom reason)
 {
   // TODO
   throw new NotImplementedException();
 }
Ejemplo n.º 24
0
 public void RPCcast(ErlAtom node, ErlAtom mod, ErlAtom fun, ErlList args)
 {
   RPCcast(node, mod, fun, args, ConstAtoms.User);
 }
Ejemplo n.º 25
0
 public IErlObject RPC(ErlAtom node, ErlAtom mod, ErlAtom fun, ErlList args, ErlAtom? remoteCookie = null)
 {
   return RPC(node, mod, fun, args, -1, remoteCookie);
 }
Ejemplo n.º 26
0
 public bool Register(ErlAtom name)
 {
   var res = m_Node.Mailboxes.Register(name, this);
   if (res)
     m_RegName = name;
   return res;
 }
Ejemplo n.º 27
0
 /*
 * send to remote name
 * dest is recipient's registered name, the nodename is implied by
 * the choice of connection.
 */
 public void Send(ErlPid from, ErlAtom dest, IErlObject msg)
 {
   // encode and send the message
   base.Send(ErlMsg.RegSend(from, dest, msg, SendCookie));
 }
Ejemplo n.º 28
0
        public void ErlTermSerializeTest()
        {
            {
                var b  = new byte[] { 131, 100, 0, 3, 97, 98, 99 };
                var t  = new ErlAtom("abc");
                var os = new ErlOutputStream(t);
                Aver.IsTrue(b.MemBufferEquals(os.GetBuffer().TakeWhile((_, i) => i < b.Length).ToArray()));
                var es = new ErlInputStream(b);
                Aver.AreEqual(t, es.Read());
            }
            {
                var b  = new byte[] { 131, 109, 0, 0, 0, 3, 1, 2, 3 };
                var t  = new ErlBinary(new byte[] { 1, 2, 3 });
                var os = new ErlOutputStream(t);
                Aver.IsTrue(b.MemBufferEquals(os.GetBuffer().TakeWhile((_, i) => i < b.Length).ToArray()));
                var es = new ErlInputStream(b);
                Aver.AreEqual(t, es.Read());
            }
            {
                var b1  = new byte[] { 131, 100, 0, 4, 116, 114, 117, 101 };
                var t1  = new ErlBoolean(true);
                var os1 = new ErlOutputStream(t1);
                Aver.IsTrue(b1.MemBufferEquals(os1.GetBuffer().TakeWhile((_, i) => i < b1.Length).ToArray()));
                var es1 = new ErlInputStream(b1);
                Aver.AreEqual(t1, es1.Read());

                var b2  = new byte[] { 131, 100, 0, 5, 102, 97, 108, 115, 101 };
                var t2  = new ErlBoolean(false);
                var os2 = new ErlOutputStream(t2);
                Aver.IsTrue(b2.MemBufferEquals(os2.GetBuffer().TakeWhile((_, i) => i < b2.Length).ToArray()));
                var es2 = new ErlInputStream(b2);
                Aver.AreEqual(t2, es2.Read());
            }
            {
                var b  = new byte[] { 131, 97, 127 };
                var t  = new ErlByte(127);
                var os = new ErlOutputStream(t);
                Aver.IsTrue(b.MemBufferEquals(os.GetBuffer().TakeWhile((_, i) => i < b.Length).ToArray()));
                var es = new ErlInputStream(b);
                Aver.AreEqual(t, es.Read());
            }
            {
                var b  = new byte[] { 131, 70, 64, 36, 62, 249, 219, 34, 208, 229 };
                var t  = new ErlDouble(10.123);
                var os = new ErlOutputStream(t);
                Aver.IsTrue(b.MemBufferEquals(os.GetBuffer().TakeWhile((_, i) => i < b.Length).ToArray()));
                var es = new ErlInputStream(b);
                Aver.AreEqual(t, es.Read());
            }
            {
                var b  = new byte[] { 131, 108, 0, 0, 0, 2, 107, 0, 1, 1, 107, 0, 1, 2, 106 };
                var t  = new ErlList(new ErlList(1), new ErlList(2));
                var os = new ErlOutputStream(t);
                Aver.IsTrue(b.MemBufferEquals(os.GetBuffer().TakeWhile((_, i) => i < b.Length).ToArray()));
                var es = new ErlInputStream(b);
                Aver.AreEqual(t, es.Read());
            }
            {
                var b  = new byte[] { 131, 108, 0, 0, 0, 2, 108, 0, 0, 0, 2, 97, 1, 107, 0, 1, 2, 106, 107, 0, 1, 3, 106 };
                var t  = new ErlList(new ErlList(1, new ErlList(2)), new ErlList(3));
                var os = new ErlOutputStream(t);
                Aver.IsTrue(b.MemBufferEquals(os.GetBuffer().TakeWhile((_, i) => i < b.Length).ToArray()));
                var es = new ErlInputStream(b);
                Aver.AreEqual(t, es.Read());
            }
            {
                var b = new byte[] { 131, 108, 0, 0, 0, 3, 97, 1, 70, 64, 36, 61, 112, 163, 215, 10, 61, 108, 0, 0, 0, 2,
                                     100, 0, 4, 116, 114, 117, 101, 107, 0, 1, 97, 106, 106 };
                var t  = new ErlList(1, 10.12, new ErlList(true, "a"));
                var os = new ErlOutputStream(t);
                Aver.IsTrue(b.MemBufferEquals(os.GetBuffer().TakeWhile((_, i) => i < b.Length).ToArray()));
                var es = new ErlInputStream(b);
                Aver.AreEqual(t, es.Read());
            }
            {
                var b = new byte[] {
                    131, 108, 0, 0, 0, 3, 97, 23, 97, 4, 104, 1, 108, 0, 0, 0, 1, 104, 2, 109, 0, 0, 0, 5, 101, 118, 101,
                    110, 116, 104, 1, 108, 0, 0, 0, 2, 104, 2, 109, 0, 0, 0, 10, 102, 108, 101, 101, 116, 95, 104, 97,
                    115, 104, 109, 0, 0, 0, 36, 97, 54, 97, 50, 50, 100, 49, 52, 45, 56, 52, 56, 51, 45, 52, 49, 102, 99,
                    45, 97, 52, 54, 98, 45, 50, 56, 51, 98, 57, 55, 55, 55, 99, 50, 97, 50, 104, 2, 109, 0, 0, 0, 4, 116,
                    121, 112, 101, 109, 0, 0, 0, 13, 102, 108, 101, 101, 116, 95, 99, 104, 97, 110, 103, 101, 100,
                    106, 106, 106
                };
                var t = ErlObject.Parse("[23,4,{[{<<\"event\">>," +
                                        "{[{<<\"fleet_hash\">>,<<\"a6a22d14-8483-41fc-a46b-283b9777c2a2\">>}," +
                                        "{<<\"type\">>,<<\"fleet_changed\">>}]}}]}]");
                var os = new ErlOutputStream(t);
                Aver.IsTrue(b.MemBufferEquals(os.GetBuffer().TakeWhile((_, i) => i < b.Length).ToArray()));
                var es = new ErlInputStream(b);
                Aver.AreEqual(t, es.Read());
            }
            {
                var b1  = new byte[] { 131, 98, 255, 255, 255, 251 };
                var t1  = new ErlLong(-5);
                var os1 = new ErlOutputStream(t1);
                Aver.IsTrue(b1.MemBufferEquals(os1.GetBuffer().TakeWhile((_, i) => i < b1.Length).ToArray()));
                var es1 = new ErlInputStream(b1);
                Aver.AreEqual(t1, es1.Read());

                var b2  = new byte[] { 131, 97, 5 };
                var t2  = new ErlLong(5);
                var os2 = new ErlOutputStream(t2);
                Aver.IsTrue(b2.MemBufferEquals(os2.GetBuffer().TakeWhile((_, i) => i < b2.Length).ToArray()));
                var es2 = new ErlInputStream(b2);
                Aver.AreEqual(t2, es2.Read());

                var b3  = new byte[] { 131, 98, 0, 16, 0, 0 };
                var t3  = new ErlLong(1024 * 1024);
                var os3 = new ErlOutputStream(t3);
                Aver.IsTrue(b3.MemBufferEquals(os3.GetBuffer().TakeWhile((_, i) => i < b3.Length).ToArray()));
                var es3 = new ErlInputStream(b3);
                Aver.AreEqual(t3, es3.Read());

                var b4  = new byte[] { 131, 110, 6, 0, 0, 0, 0, 0, 0, 4 };
                var t4  = new ErlLong(1024L * 1024 * 1024 * 1024 * 4);
                var os4 = new ErlOutputStream(t4);
                Aver.IsTrue(b4.MemBufferEquals(os4.GetBuffer().TakeWhile((_, i) => i < b4.Length).ToArray()));
                var es4 = new ErlInputStream(b4);
                Aver.AreEqual(t4, es4.Read());

                var b5  = new byte[] { 131, 110, 8, 1, 0, 0, 0, 0, 0, 0, 0, 128 };
                var t5  = new ErlLong(1L << 63);
                var os5 = new ErlOutputStream(t5);
                Aver.IsTrue(b5.MemBufferEquals(os5.GetBuffer().TakeWhile((_, i) => i < b5.Length).ToArray()));
                var es5 = new ErlInputStream(b5);
                Aver.AreEqual(t5, es5.Read());

                var b6  = new byte[] { 131, 110, 8, 1, 0, 0, 0, 0, 0, 0, 0, 128 };
                var t6  = new ErlLong(-1L << 63);
                var os6 = new ErlOutputStream(t6);
                Aver.IsTrue(b6.MemBufferEquals(os6.GetBuffer().TakeWhile((_, i) => i < b6.Length).ToArray()));
                var es6 = new ErlInputStream(b6);
                Aver.AreEqual(t6, es6.Read());

                var b7  = new byte[] { 131, 110, 8, 0, 255, 255, 255, 255, 255, 255, 255, 255 };
                var es7 = new ErlInputStream(b7);
                var t7  = new ErlLong(-1);
                Aver.AreEqual(t7, es7.Read());
                var bi7 = new byte[] { 131, 98, 255, 255, 255, 255 };
                var os7 = new ErlOutputStream(t7);
                Aver.IsTrue(bi7.MemBufferEquals(os7.GetBuffer().TakeWhile((_, i) => i < bi7.Length).ToArray()));
            }
            {
                var b  = new byte[] { 131, 103, 100, 0, 7, 98, 64, 112, 105, 112, 105, 116, 0, 0, 0, 38, 0, 0, 0, 0, 1 };
                var t  = new ErlPid("b@pipit", 38, 0, 1);
                var os = new ErlOutputStream(t);
                Aver.IsTrue(b.MemBufferEquals(os.GetBuffer().TakeWhile((_, i) => i < b.Length).ToArray()));
                var es = new ErlInputStream(b);
                Aver.AreEqual(t, es.Read());
            }
            {
                var b  = new byte[] { 131, 102, 100, 0, 7, 98, 64, 112, 105, 112, 105, 116, 0, 0, 0, 38, 1 };
                var t  = new ErlPort("b@pipit", 38, 1);
                var os = new ErlOutputStream(t);
                Aver.IsTrue(b.MemBufferEquals(os.GetBuffer().TakeWhile((_, i) => i < b.Length).ToArray()));
                var es = new ErlInputStream(b);
                Aver.AreEqual(t, es.Read());
            }
            {
                var b  = new byte[] { 131, 114, 0, 3, 100, 0, 7, 98, 64, 112, 105, 112, 105, 116, 1, 0, 0, 0, 181, 0, 0, 0, 0, 0, 0, 0, 0 };
                var t  = new ErlRef("b@pipit", 181, 0, 0, 1);
                var os = new ErlOutputStream(t);
                Aver.IsTrue(b.MemBufferEquals(os.GetBuffer().TakeWhile((_, i) => i < b.Length).ToArray()));
                var es = new ErlInputStream(b);
                Aver.AreEqual(t, es.Read());
            }
            {
                var b  = new byte[] { 131, 107, 0, 3, 115, 116, 114 };
                var t  = new ErlString("str");
                var os = new ErlOutputStream(t);
                Aver.IsTrue(b.MemBufferEquals(os.GetBuffer().TakeWhile((_, i) => i < b.Length).ToArray()));
                var es = new ErlInputStream(b);
                Aver.AreEqual(t, es.Read());
            }
            {
                var b  = new byte[] { 131, 104, 3, 97, 1, 100, 0, 1, 97, 104, 2, 97, 10, 70, 63, 241, 247, 206, 217, 22, 135, 43 };
                var t  = new ErlTuple(1, new ErlAtom("a"), new ErlTuple(10, 1.123));
                var os = new ErlOutputStream(t);
                Aver.IsTrue(b.MemBufferEquals(os.GetBuffer().TakeWhile((_, i) => i < b.Length).ToArray()));
                var es = new ErlInputStream(b);
                Aver.AreEqual(t, es.Read());
            }
            {
                var b = new byte[] { 131, 116, 0, 0, 0, 2, 100, 0, 1, 97, 97, 1, 107, 0, 3, 115, 116, 114, 70, 64, 0, 0, 0, 0, 0, 0, 0 };
                var t = new ErlMap {
                    { new ErlAtom("a"), 1.ToErlObject() },
                    { new ErlString("str"), new ErlDouble(2.0) }
                };
                var os = new ErlOutputStream(t);
                Aver.IsTrue(b.MemBufferEquals(os.GetBuffer().TakeWhile((_, i) => i < b.Length).ToArray()));
                var es = new ErlInputStream(b);
                Aver.AreEqual(t, es.Read());
            }
        }
Ejemplo n.º 29
0
        public void ErlTestPatternMatch()
        {
            {
                var        binding = new ErlVarBind();
                IErlObject obj     = ErlObject.Parse("{snapshot, x12, []}");
                IErlObject pat     = ErlObject.Parse("{snapshot, N, L}");

                Assert.IsTrue(pat.Match(obj, binding));
                ErlAtom n = binding.Cast <ErlAtom>(N);
                ErlList l = binding.Cast <ErlList>(L);
                Assert.IsNotNull(n);
                Assert.IsNotNull(l);
                Assert.IsTrue(l.Count == 0);
            }
            {
                IErlObject pat = ErlObject.Parse("{test, A, B, C}");
                IErlObject obj = ErlObject.Parse("{test, 10, a, [1,2,3]}");

                var binding = new ErlVarBind();
                Assert.IsTrue(pat.Match(obj, binding));
                Assert.AreEqual(3, binding.Count);
                Assert.AreEqual(10, binding.Cast <ErlLong>(A));
                Assert.AreEqual("a", binding.Cast <ErlAtom>(B).ValueAsString);
                Assert.AreEqual("[1,2,3]", binding["C"].ToString());
            }

            {
                var        binding = new ErlVarBind();
                IErlObject obj     = ErlObject.Parse("[1,a,$b,\"xyz\",{1,10.0},[]]");
                IErlObject pat     = ErlObject.Parse("[A,B,C,D,E,F]");

                Assert.IsTrue(pat.Match(obj, binding));
                Assert.IsNotNull(binding.Cast <ErlLong>(A));
                Assert.IsNotNull(binding.Cast <ErlAtom>(B));
                Assert.IsNotNull(binding.Cast <ErlByte>(C));
                Assert.IsNotNull(binding.Cast <ErlString>(D));
                Assert.IsNotNull(binding.Cast <ErlTuple>(E));
                Assert.IsNotNull(binding.Cast <ErlList>(F));

                Assert.IsTrue(binding.Cast <ErlTuple>(E).Count == 2);
                Assert.IsTrue(binding.Cast <ErlList>(F).Count == 0);
            }

            IErlObject pattern = ErlObject.Parse("{test, T}");
            string     exp     = "{test, ~w}";
            {
                var        binding = new ErlVarBind();
                IErlObject obj     = ErlObject.Parse(exp, (int)3);
                Assert.IsTrue(pattern.Match(obj, binding));
                Assert.AreEqual(3, binding.Cast <ErlLong>(T));
            }
            {
                var        binding = new ErlVarBind();
                IErlObject obj     = ErlObject.Parse(exp, (long)100);
                Assert.IsTrue(pattern.Match(obj, binding));
                Assert.AreEqual(100, binding.Cast <ErlLong>(T));
            }
            {
                var        binding = new ErlVarBind();
                IErlObject obj     = ErlObject.Parse(exp, 100.0);
                Assert.IsTrue(pattern.Match(obj, binding));
                Assert.AreEqual(100.0, binding.Cast <ErlDouble>(T).ValueAsDouble);
            }
            {
                var        binding = new ErlVarBind();
                IErlObject obj     = ErlObject.Parse(exp, "test");
                Assert.IsTrue(pattern.Match(obj, binding));
                Assert.AreEqual("test", binding.Cast <ErlString>(T).ValueAsString);
            }
            {
                var        binding = new ErlVarBind();
                IErlObject obj     = ErlObject.Parse(exp, true);
                Assert.IsTrue(pattern.Match(obj, binding));
                Assert.AreEqual(true, binding.Cast <ErlBoolean>(T).ValueAsBool);
            }
            {
                var        binding = new ErlVarBind();
                IErlObject obj     = ErlObject.Parse(exp, 'c');
                Assert.IsTrue(pattern.Match(obj, binding));
                Assert.AreEqual((byte)'c', binding.Cast <ErlByte>(T).ValueAsInt);
            }
            {
                var        binding = new ErlVarBind();
                var        pid     = new ErlPid("tmp", 1, 2, 3);
                IErlObject obj     = ErlObject.Parse(exp, pid as IErlObject);
                Assert.IsTrue(pattern.Match(obj, binding));
                Assert.AreEqual(pid, binding.Cast <ErlPid>(T));
                Assert.AreEqual(pid, binding.Cast <ErlPid>(T).Value);

                obj = ErlObject.Parse(exp, pid);
                Assert.IsTrue(pattern.Match(obj, binding));
                Assert.AreEqual(pid, binding.Cast <ErlPid>(T).Value);
            }
            {
                var        binding = new ErlVarBind();
                var        port    = new ErlPort("tmp", 1, 2);
                IErlObject obj     = ErlObject.Parse(exp, port);
                Assert.IsTrue(pattern.Match(obj, binding));
                Assert.AreEqual(port, binding.Cast <ErlPort>(T));
                Assert.AreEqual(port, binding.Cast <ErlPort>(T).Value);
            }
            {
                var        binding   = new ErlVarBind();
                var        reference = new ErlRef("tmp", 1, 0, 0, 2);
                IErlObject obj       = ErlObject.Parse(exp, reference);
                Assert.IsTrue(pattern.Match(obj, binding));
                Assert.AreEqual(reference, binding.Cast <ErlRef>(T));
                Assert.AreEqual(reference, binding.Cast <ErlRef>(T).Value);
            }
            {
                var     binding = new ErlVarBind();
                ErlList obj     = new ErlList(new ErlLong(10), new ErlDouble(30.0),
                                              new ErlString("abc"), new ErlAtom("a"),
                                              new ErlBinary(new byte[] { 1, 2, 3 }), false, new ErlBoolean(true));
                IErlObject pat = ErlObject.Parse("T");
                Assert.IsTrue(pat.Match(obj, binding));
                IErlObject expected = ErlObject.Parse("[10, 30.0, \"abc\", 'a', ~w, \'false\', true]",
                                                      new ErlBinary(new byte[] { 1, 2, 3 }));
                IErlObject result = binding[T];
                Assert.IsTrue(expected.Equals(result));
            }
        }
Ejemplo n.º 30
0
    /// <summary>
    /// Used to break all known links to this mbox
    /// </summary>
    internal void BreakLinks(ErlAtom fromNode, IErlObject reason)
    {
      var links = m_Links.Remove(fromNode);

      foreach (var link in links)
        if (link.HasPid)
          m_Node.Deliver(ErlMsg.Exit(m_Self, link.Pid, reason));
        else
          m_Node.Deliver(new ErlConnectionException(fromNode, reason));

      foreach (var m in m_Monitors.Where(o => o.Value.Node == fromNode)
                                  .Where(m => m_Monitors.Remove(m.Key)))
        Deliver(new ErlConnectionException(fromNode, reason));
    }
Ejemplo n.º 31
0
        private static void run(IConfigSectionNode argsConfig, bool hasConfigFile)
        {
            //try to read from  /config file
            var localNodeName  = argsConfig["local"].AttrByIndex(0).Value;
            var remoteNodeName = argsConfig["remote"].AttrByIndex(0).Value;
            var cookie         = new ErlAtom(argsConfig["cookie"].AttrByIndex(0).ValueAsString(string.Empty));
            var trace          = (ErlTraceLevel)Enum.Parse(typeof(ErlTraceLevel), argsConfig["trace"].AttrByIndex(0).ValueAsString("Off"), true);
            var timeout        = argsConfig["timeout"].AttrByIndex(0).ValueAsInt(120);

            if (!hasConfigFile && (localNodeName == null || remoteNodeName == null))
            {
                Console.WriteLine("Usage: {0} [-config ConfigFile.config] [-local NodeName -remote NodeName]\n" +
                                  "          [-cookie Cookie] [-trace Level] [-timeout Timeout]\n\n" +
                                  "     -config ConfFile    - Provide configuration file\n" +
                                  "     -trace Level        - Turn on trace for level:\n" +
                                  "                             Off (default) | Send | Ctrl | Handshake | Wire\n" +
                                  "     -timeout Timeout    - Wait for messages for this number of seconds before\n" +
                                  "                              exiting (default: 15)\n" +
                                  "Example:\n" +
                                  "========\n" +
                                  "  [Shell A] $ erl -sname a\n" +
                                  "  [Shell B] $ {0} -local b -remote a -trace Send -timeout 60\n\n" +
                                  "  In the Erlang shell send messages to the C# node:\n" +
                                  "  [Shell A] (a@localhost)1> {{test, b@localhost}} ! \"Hello World!\".\n"
                                  , MiscUtils.ExeName(false));
                Environment.Exit(1);
            }

            // Create an local Erlang node that will process all communications with other nodes

            var node = hasConfigFile ? ErlApp.Node : new ErlLocalNode(localNodeName, cookie, true);

            node.Trace += (_, t, l, m) =>
                          Console.WriteLine("[TRACE {0}]   {1} {2}", t, l == Direction.Inbound ? "<-" : "->", m);

            node.NodeStatusChange += (_, n, up, info) =>
                                     Console.WriteLine("<NodeStatus>  Node {0} {1} ({2})", n.Value, up ? "up" : "down", info);

            node.ConnectAttempt += (_, n, dir, info) =>
                                   Console.WriteLine("<ConnAttempt> Node {0}: {1} connection {2}", n, dir.ToString().ToLower(), info);

            node.EpmdFailedConnectAttempt += (_, n, info) =>
                                             Console.WriteLine("<EmpdFailure> Node {0} Epmd connectivity failure: {1}", n, info);

            node.UnhandledMsg += (_, c, msg) =>
                                 Console.WriteLine("<UnhandMsg>   Node {0} unhandled message from node {1}: {2}", c.LocalNode.NodeName, c.RemoteNode.NodeName, msg);

            node.ReadWrite += (_, c, d, n, tn, tm) =>
                              Console.WriteLine("<ReadWrite>   {0} {1} bytes (total: {2} bytes, {3} msgs)", d == Direction.Inbound ? "Read" : "Written", n, tn, tm);

            node.IoOutput += (_, _encoding, output) =>
                             Console.WriteLine("<I/O output>  ==> Received output: {0}", output);

            // Create a named mailbox "test"
            ErlMbox mbox = null;

            if (hasConfigFile)
            {
                mbox = node.CreateMbox("test");
            }
            else
            {
                node.TraceLevel = trace;
                Console.WriteLine("Node = {0}, cookie = {1}", node.NodeName, node.Cookie);

                // Start the node

                try
                {
                    node.Start();
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error: " + e.Message);
                    goto exit;
                }

                mbox = node.CreateMbox("test");

                // Connect to remote node

                var remote = node.Connection(remoteNodeName);

                Console.WriteLine("{0} to remote node {1}".Args(
                                      remote == null ? "Couldn't connect" : "Connected",
                                      remoteNodeName));

                if (remote == null)
                {
                    Console.WriteLine("Couldn't connect to {0}", remoteNodeName);
                    goto exit;
                }

                // Synchronous RPC call of erlang:now() at the remote node
                /* new ErlAtom("erlang") */
                /* new ErlList() */
                var result = mbox.RPC(remote.Name, ConstAtoms.Erlang, new ErlAtom("now"), ErlList.Empty);

                Console.WriteLine("RPC call to erlang:now() resulted in response: {0}", result.ValueAsDateTime.ToLocalTime());

                // Asynchronous RPC call of erlang:now() at the remote node

                mbox.AsyncRPC(remote.Name, ConstAtoms.Erlang, new ErlAtom("now"), ErlList.Empty);

                int i = node.WaitAny(mbox);

                if (i < 0)
                {
                    Console.WriteLine("Timeout waiting for RPC result");
                    goto exit;
                }

                result = mbox.ReceiveRPC();

                Console.WriteLine("AsyncRPC call to erlang:now() resulted in response: {0}", result.ValueAsDateTime.ToLocalTime());

                // I/O output call on the remote node of io:format(...)
                // that will return the output to this local node (because by default RPC
                // passes node.GroupLeader as the mailbox to receive the output

                var mfa = ErlObject.ParseMFA("io:format(\"output: 1, 10.0, abc\n\", [])");

                result = mbox.RPC(remote.Name, mfa.Item1, mfa.Item2, mfa.Item3);

                Console.WriteLine("io:format() -> {0}", result.ToString());

                // Poll for incoming messages destined to the 'test' mailbox
            }

            var deadline = DateTime.UtcNow.AddSeconds(timeout);

            do
            {
                var result = mbox.Receive(1000);
                if (result != null)
                {
                    Console.WriteLine("Mailbox {0} got message: {1}", mbox.Self, result);
                }
            }while (DateTime.UtcNow < deadline);

exit:
            if (System.Diagnostics.Debugger.IsAttached)
            {
                Console.WriteLine("Press any key to continue...");
                Console.ReadKey();
            }
        }
Ejemplo n.º 32
0
 internal ErlMbox(ErlLocalNode home, ErlPid self, ErlAtom name)
 {
   m_Self = self;
   m_Node = home;
   m_RegName = name;
   m_Queue = new ErlBlockingQueue<IQueable>();
   m_Links = new ErlLinks();
   m_Monitors = new ErlMonitors(this);
 }
Ejemplo n.º 33
0
 private IErlObject ioProcessPutChars(ErlAtom encoding,
     ErlAtom mod, ErlAtom fun, ErlList args, IErlObject replyAs)
 {
   string term;
   if (mod == ConstAtoms.Io_Lib && fun == ConstAtoms.Format && args.Count == 2)
     try { term = ErlObject.Format(args); }
     catch { term = "{0}:{1}({2})".Args(mod, fun, args.ToString(true)); }
   else
     term = "{0}:{1}({2})".Args(mod, fun, args.ToString(true));
   Node.OnIoOutput(encoding, new ErlString(term));
   return s_ReplyPattern.Subst(
       new ErlVarBind { { RA, replyAs }, { R, ConstAtoms.Ok } });
 }
Ejemplo n.º 34
0
 /// <summary>
 /// Create a peer node
 /// </summary>
 public ErlRemoteNode(ErlLocalNode home, ErlAtom toNode, ErlAtom?cookie = null)
     : base(toNode, cookie ?? home.Cookie, home.UseShortName)
 {
     ctor(home);
 }
Ejemplo n.º 35
0
 /// <summary>
 /// Create a peer node
 /// </summary>
 public ErlRemoteNode(ErlLocalNode home, ErlAtom toNode, ErlAtom? cookie = null)
     : base(toNode, cookie ?? home.Cookie, home.UseShortName)
 {
   ctor(home);
 }
Ejemplo n.º 36
0
        public void ErlTermSerializeTest()
        {
            {
                var b  = new byte[] { 131, 100, 0, 3, 97, 98, 99 };
                var t  = new ErlAtom("abc");
                var os = new ErlOutputStream(t);
                Assert.AreEqual(b, os.GetBuffer().TakeWhile((_, i) => i < b.Length).ToArray());
                var es = new ErlInputStream(b);
                Assert.AreEqual(t, es.Read());
            }
            {
                var b  = new byte[] { 131, 109, 0, 0, 0, 3, 1, 2, 3 };
                var t  = new ErlBinary(new byte[] { 1, 2, 3 });
                var os = new ErlOutputStream(t);
                Assert.AreEqual(b, os.GetBuffer().TakeWhile((_, i) => i < b.Length).ToArray());
                var es = new ErlInputStream(b);
                Assert.AreEqual(t, es.Read());
            }
            {
                var b1  = new byte[] { 131, 100, 0, 4, 116, 114, 117, 101 };
                var t1  = new ErlBoolean(true);
                var os1 = new ErlOutputStream(t1);
                Assert.AreEqual(b1, os1.GetBuffer().TakeWhile((_, i) => i < b1.Length).ToArray());
                var es1 = new ErlInputStream(b1);
                Assert.AreEqual(t1, es1.Read());

                var b2  = new byte[] { 131, 100, 0, 5, 102, 97, 108, 115, 101 };
                var t2  = new ErlBoolean(false);
                var os2 = new ErlOutputStream(t2);
                Assert.AreEqual(b2, os2.GetBuffer().TakeWhile((_, i) => i < b2.Length).ToArray());
                var es2 = new ErlInputStream(b2);
                Assert.AreEqual(t2, es2.Read());
            }
            {
                var b  = new byte[] { 131, 97, 127 };
                var t  = new ErlByte(127);
                var os = new ErlOutputStream(t);
                Assert.AreEqual(b, os.GetBuffer().TakeWhile((_, i) => i < b.Length).ToArray());
                var es = new ErlInputStream(b);
                Assert.AreEqual(t, es.Read());
            }
            {
                var b  = new byte[] { 131, 70, 64, 36, 62, 249, 219, 34, 208, 229 };
                var t  = new ErlDouble(10.123);
                var os = new ErlOutputStream(t);
                Assert.AreEqual(b, os.GetBuffer().TakeWhile((_, i) => i < b.Length).ToArray());
                var es = new ErlInputStream(b);
                Assert.AreEqual(t, es.Read());
            }
            {
                var b = new byte[] { 131, 108, 0, 0, 0, 3, 97, 1, 70, 64, 36, 61, 112, 163, 215, 10, 61, 108, 0, 0, 0, 2,
                                     100, 0, 4, 116, 114, 117, 101, 107, 0, 1, 97, 106, 106 };
                var t  = new ErlList(1, 10.12, new ErlList(true, "a"));
                var os = new ErlOutputStream(t);
                Assert.AreEqual(b, os.GetBuffer().TakeWhile((_, i) => i < b.Length).ToArray());
                var es = new ErlInputStream(b);
                Assert.AreEqual(t, es.Read());
            }
            {
                var b1  = new byte[] { 131, 98, 255, 255, 255, 251 };
                var t1  = new ErlLong(-5);
                var os1 = new ErlOutputStream(t1);
                Assert.AreEqual(b1, os1.GetBuffer().TakeWhile((_, i) => i < b1.Length).ToArray());
                var es1 = new ErlInputStream(b1);
                Assert.AreEqual(t1, es1.Read());

                var b2  = new byte[] { 131, 97, 5 };
                var t2  = new ErlLong(5);
                var os2 = new ErlOutputStream(t2);
                Assert.AreEqual(b2, os2.GetBuffer().TakeWhile((_, i) => i < b2.Length).ToArray());
                var es2 = new ErlInputStream(b2);
                Assert.AreEqual(t2, es2.Read());

                var b3  = new byte[] { 131, 98, 0, 16, 0, 0 };
                var t3  = new ErlLong(1024 * 1024);
                var os3 = new ErlOutputStream(t3);
                Assert.AreEqual(b3, os3.GetBuffer().TakeWhile((_, i) => i < b3.Length).ToArray());
                var es3 = new ErlInputStream(b3);
                Assert.AreEqual(t3, es3.Read());

                var b4  = new byte[] { 131, 110, 6, 0, 0, 0, 0, 0, 0, 4 };
                var t4  = new ErlLong(1024L * 1024 * 1024 * 1024 * 4);
                var os4 = new ErlOutputStream(t4);
                Assert.AreEqual(b4, os4.GetBuffer().TakeWhile((_, i) => i < b4.Length).ToArray());
                var es4 = new ErlInputStream(b4);
                Assert.AreEqual(t4, es4.Read());

                var b5  = new byte[] { 131, 110, 8, 1, 0, 0, 0, 0, 0, 0, 0, 128 };
                var t5  = new ErlLong(1L << 63);
                var os5 = new ErlOutputStream(t5);
                Assert.AreEqual(b5, os5.GetBuffer().TakeWhile((_, i) => i < b5.Length).ToArray());
                var es5 = new ErlInputStream(b5);
                Assert.AreEqual(t5, es5.Read());

                var b6  = new byte[] { 131, 110, 8, 1, 0, 0, 0, 0, 0, 0, 0, 128 };
                var t6  = new ErlLong(-1L << 63);
                var os6 = new ErlOutputStream(t6);
                Assert.AreEqual(b6, os6.GetBuffer().TakeWhile((_, i) => i < b6.Length).ToArray());
                var es6 = new ErlInputStream(b6);
                Assert.AreEqual(t6, es6.Read());

                var b7  = new byte[] { 131, 110, 8, 0, 255, 255, 255, 255, 255, 255, 255, 255 };
                var es7 = new ErlInputStream(b7);
                var t7  = new ErlLong(-1);
                Assert.AreEqual(t7, es7.Read());
                var bi7 = new byte[] { 131, 98, 255, 255, 255, 255 };
                var os7 = new ErlOutputStream(t7);
                Assert.AreEqual(bi7, os7.GetBuffer().TakeWhile((_, i) => i < bi7.Length).ToArray());
            }
            {
                var b  = new byte[] { 131, 103, 100, 0, 7, 98, 64, 112, 105, 112, 105, 116, 0, 0, 0, 38, 0, 0, 0, 0, 1 };
                var t  = new ErlPid("b@pipit", 38, 0, 1);
                var os = new ErlOutputStream(t);
                Assert.AreEqual(b, os.GetBuffer().TakeWhile((_, i) => i < b.Length).ToArray());
                var es = new ErlInputStream(b);
                Assert.AreEqual(t, es.Read());
            }
            {
                var b  = new byte[] { 131, 102, 100, 0, 7, 98, 64, 112, 105, 112, 105, 116, 0, 0, 0, 38, 1 };
                var t  = new ErlPort("b@pipit", 38, 1);
                var os = new ErlOutputStream(t);
                Assert.AreEqual(b, os.GetBuffer().TakeWhile((_, i) => i < b.Length).ToArray());
                var es = new ErlInputStream(b);
                Assert.AreEqual(t, es.Read());
            }
            {
                var b  = new byte[] { 131, 114, 0, 3, 100, 0, 7, 98, 64, 112, 105, 112, 105, 116, 1, 0, 0, 0, 181, 0, 0, 0, 0, 0, 0, 0, 0 };
                var t  = new ErlRef("b@pipit", 181, 0, 0, 1);
                var os = new ErlOutputStream(t);
                Assert.AreEqual(b, os.GetBuffer().TakeWhile((_, i) => i < b.Length).ToArray());
                var es = new ErlInputStream(b);
                Assert.AreEqual(t, es.Read());
            }
            {
                var b  = new byte[] { 131, 107, 0, 3, 115, 116, 114 };
                var t  = new ErlString("str");
                var os = new ErlOutputStream(t);
                Assert.AreEqual(b, os.GetBuffer().TakeWhile((_, i) => i < b.Length).ToArray());
                var es = new ErlInputStream(b);
                Assert.AreEqual(t, es.Read());
            }
            {
                var b  = new byte[] { 131, 104, 3, 97, 1, 100, 0, 1, 97, 104, 2, 97, 10, 70, 63, 241, 247, 206, 217, 22, 135, 43 };
                var t  = new ErlTuple(1, new ErlAtom("a"), new ErlTuple(10, 1.123));
                var os = new ErlOutputStream(t);
                Assert.AreEqual(b, os.GetBuffer().TakeWhile((_, i) => i < b.Length).ToArray());
                var es = new ErlInputStream(b);
                Assert.AreEqual(t, es.Read());
            }
        }
Ejemplo n.º 37
0
 public IErlObject RPC(ErlAtom node, ErlAtom mod, ErlAtom fun, ErlList args, int timeout, ErlAtom? remoteCookie = null)
 {
   AsyncRPC(node, mod, fun, args, remoteCookie);
   var r = m_Monitors.Add(node);
   using (Scope.OnExit(() => m_Monitors.Remove(r)))
   {
     return ReceiveRPC(timeout);
   }
 }
Ejemplo n.º 38
0
 /// <summary>
 /// Send a message to a named mailbox created from another node
 /// </summary>
 public bool Send(ErlAtom node, ErlAtom name, IErlObject msg)
 {
   return m_Node.Deliver(node, ErlMsg.RegSend(m_Self, name, msg));
 }
Ejemplo n.º 39
0
 public void AsyncRPC(ErlAtom node, ErlAtom mod, ErlAtom fun, ErlList args, ErlAtom? remoteCookie = null)
 {
   AsyncRPC(node, mod, fun, args, (IErlObject)m_Node.GroupLeader.Self, remoteCookie);
 }
Ejemplo n.º 40
0
 public IErlObject RPC(ErlAtom node, string mod, string fun, ErlList args, int timeout, ErlAtom? remoteCookie = null)
 {
   return this.RPC(node, new ErlAtom(mod), new ErlAtom(fun), args, timeout, remoteCookie);
 }
Ejemplo n.º 41
0
 public ErlRef Add(ErlAtom node)
 {
     return(Add(new ErlPid(node, 0, 0)));
 }
Ejemplo n.º 42
0
 public void AsyncRPC(ErlAtom node, string mod, string fun, ErlList args, ErlAtom? remoteCookie = null)
 {
   AsyncRPC(node, new ErlAtom(mod), new ErlAtom(fun), args, remoteCookie);
 }
Ejemplo n.º 43
0
        private byte[] genDigest(int challenge, ErlAtom cookie)
        {
            long ch2 = challenge < 0
              ? 1L << 31 | (long)(challenge & 0x7FFFFFFFL)
              : (long)challenge;

              return new MD5CryptoServiceProvider().ComputeHash(
              Encoding.UTF8.GetBytes(cookie.Value + Convert.ToString(ch2)));
        }
Ejemplo n.º 44
0
 public void AsyncRPC(ErlAtom node, string mod, string fun, ErlList args, ErlPid ioServer,
                      ErlAtom? remoteCookie = null)
 {
   AsyncRPC(node, new ErlAtom(mod), new ErlAtom(fun), args, (IErlObject)ioServer, remoteCookie);
 }
Ejemplo n.º 45
0
        static void Main(string[] args)
        {
            //here we handle password requests
            ErlTransportPasswordSource.PasswordRequired += (ps) =>
            {
                Console.Write("Username: {0}\nPassword: "******"{0} ({1}): {2}", t, d, text);

                n.Start();

                var cfg        = App.ConfigRoot.NavigateSection("/erlang");
                var remoteName = cfg.Children.Select(nd => nd.Name == "node" ? nd.Value : string.Empty)
                                 .FirstOrDefault(s => s.Contains("@"));

                Console.WriteLine("\n\nExecute the following code on remote node {0}:", remoteName);
                Console.WriteLine("1> F = fun F() -> receive {From, Msg} -> From ! Msg, F() end end.");
                Console.WriteLine("2> spawn_link(fun() -> register(me, self()), F() end).\n");
                Console.WriteLine("Press any key when ready...");

                Console.ReadKey();

                var m          = n.CreateMbox("test");
                var a          = new ErlAtom("hello");
                var msg        = new ErlTuple(m.Self, a);
                var remoteNode = new ErlAtom(remoteName);

                DateTime empty = new DateTime(2000, 1, 1, 0, 0, 0);
                DateTime start = empty;
                long     count = 0;
                long     msgs  = 30000;

                do
                {
                    var res = n.Send(m.Self, remoteNode, "me", msg);
                    if (!res)
                    {
                        Console.WriteLine("Can not send message");
                        break;
                    }

                    if (start == empty)
                    {
                        start = DateTime.UtcNow;
                    }

                    var got = m.Receive(5000);

                    if (!got.Equals((IErlObject)a))
                    {
                        Console.WriteLine("Got wrong result! Expected: {0}, Got: {1}", a, got);
                        count = -1;
                        break;
                    }

                    count++;

                    if ((count % 10000) == 0)
                    {
                        Console.WriteLine("Processed {0} messages", count);
                    }
                    //Console.ReadLine();
                } while (count < msgs);

                var end  = DateTime.UtcNow;
                var diff = (end - start);

                if (count > 0)
                {
                    Console.WriteLine("Processed {0} messages. Speed: {1:F2}msgs/s, Latency: {2}us",
                                      msgs, msgs / diff.TotalSeconds, 1000.0 * diff.TotalMilliseconds / msgs);
                }
            }

            if (Debugger.IsAttached)
            {
                Console.ReadKey();
            }
        }
Ejemplo n.º 46
0
 public void RPCcast(ErlAtom node, ErlAtom mod, ErlAtom fun, ErlList args, IErlObject ioServer)
 {
   if (node.Equals(m_Node.NodeName))
     throw new ErlException(StringConsts.ERL_CONN_CANT_RPC_TO_LOCAL_NODE_ERROR);
   else
   {
     var msg = Internal.ErlRpcServer.EncodeRPCcast(m_Self, mod, fun, args, ioServer);
     var conn = m_Node.Connection(node);
     if (conn == null)
       throw new ErlConnectionException(
           node, StringConsts.ERL_CONN_CANT_CONNECT_TO_NODE_ERROR.Args(node));
     conn.Send(m_Self, ConstAtoms.Rex, msg);
   }
 }
Ejemplo n.º 47
0
        private IErlObject rpcCall(ErlPid from, ErlRef eref,
                                   ErlAtom mod, ErlAtom fun, ErlList args, IErlObject groupLeader)
        {
            // We spawn a new task, so that RPC calls wouldn't block the RPC server thread
            Task.Factory.StartNew(() =>
            {
                var type = Type.GetType(mod);

                if (type == null)
                {
                    sendRpcReply(from, eref,
                                 ErlTuple.Create(ConstAtoms.Error, "unknown type: {0}".Args(mod)));
                    return;
                }

                // TODO: add LRU caching
                //var method = type.GetMethod(fun.Value, BindingFlags.Static | BindingFlags.Public);

                string methodName = fun.Value;

                if (args.Count == 0)
                {
                    var pi = type.GetProperty(fun, BindingFlags.Static | BindingFlags.Public);
                    if (pi != null)
                    {
                        try
                        {
                            var result = pi.GetValue(null, null);
                            sendRpcReply(from, eref,
                                         ErlTuple.Create(ConstAtoms.Ok, result.ToErlObject()));
                        }
                        catch (Exception e)
                        {
                            sendRpcReply(from, eref,
                                         ErlTuple.Create(ConstAtoms.Error, new ErlString(e.Message)));
                        };
                        return;
                    }
                }

                var mi = type.GetMethods(BindingFlags.Static | BindingFlags.Public)
                         .Where(m => m.Name == methodName && m.GetParameters().Count() == args.Count)
                         .FirstOrDefault();

                if (mi == null)
                {
                    sendRpcReply(from, eref,
                                 ErlTuple.Create(ConstAtoms.Error, "unknown method: {0}".Args(fun)));
                    return;
                }

                var pars = mi.GetParameters();

                var margs = new object[pars.Length];

                for (int i = 0; i < pars.Length; i++)
                {
                    var par  = pars[i];
                    var val  = args[i];
                    margs[i] = val.AsType(par.ParameterType);
                }

                try
                {
                    var result = mi.Invoke(type, margs);
                    sendRpcReply(from, eref, ErlTuple.Create(ConstAtoms.Ok, result.ToErlObject()));
                }
                catch (Exception e)
                {
                    sendRpcReply(from, eref, ErlTuple.Create(ConstAtoms.Error, new ErlString(e.Message)));
                }
            });
            return((IErlObject)null);
        }
Ejemplo n.º 48
0
 /// <summary>
 /// Close this mailbox
 /// </summary>
 /// <remarks>
 /// After this operation, the mailbox will no longer be able to
 /// receive messages. Any delivered but as yet unretrieved messages
 /// can still be retrieved however.
 ///
 /// If there are links from this mailbox to other <see cref="ErlPid"/>
 /// pids they will be broken when this method is
 /// called and exit signals will be sent.
 /// </remarks>
 internal void Close()
 {
   // Notify all registered monitors that this pid is closing
   foreach (var monitor in m_Monitors)
   {
     var msg = ErlMsg.MonitorPexit(m_Self, monitor.Value, monitor.Key, ErlAtom.Normal);
     m_Node.Deliver(monitor.Value.Node, msg);
   }
   m_Node.CloseMbox(this);
   m_RegName = ErlAtom.Null;
 }
Ejemplo n.º 49
0
 internal static ErlTuple EncodeRPC(
     ErlPid from, ErlAtom mod, ErlAtom fun, ErlList args, IErlObject gleader)
 {
     /*{Self, {call, Mod, Fun, Args, GroupLeader}} */
     return(new ErlTuple(from, new ErlTuple(ConstAtoms.Call, mod, fun, args, gleader)));
 }
Ejemplo n.º 50
0
 /// <summary>
 /// Used to break all known links to this mbox
 /// </summary>
 internal void BreakLinks(ErlAtom reason)
 {
   foreach (var l in m_Links.Clear())
     m_Node.Deliver(ErlMsg.Exit(m_Self, l.Pid, reason));
 }
Ejemplo n.º 51
0
    public override void read(ErlKVMessage message)
    {
        ErlAtom atom = message.getValue("msg") as ErlAtom;
        string  str  = atom != null ? atom.Value : "";

        if (str == FPortGlobal.LOGIN_LOGIN_OK)
        {
            Debug.LogWarning("LOGIN_LOGIN_OK");
            initUser();
        }
        else if (str == FPortGlobal.SYSTEM_INFO_ERROR)
        {
            Debug.LogWarning("LOGIN_INFO_ERROR");
        }
        else if (str == FPortGlobal.LOGIN_CREATE_USER_OK)
        {
            Debug.LogWarning("LOGIN_CREATE_USER_OK");
            UiManager.Instance.openWindow <TitlesWindow> ();
        }
        else if (str == FPortGlobal.LOGIN_NO_USER)
        {
            Debug.LogWarning("LOGIN_NO_USER");
        }
        else if (str == FPortGlobal.LOGIN_PASSWORD_ERROR)
        {
            Debug.LogWarning("LOGIN_PASSWORD_ERROR");
        }
        else if (str == FPortGlobal.LOGIN_NO_ROLE)
        {
            Debug.LogWarning("LOGIN_NO_ROLE");
            UiManager.Instance.openWindow <TitlesWindow> ();
        }
        else if (str == FPortGlobal.LOGIN_RELOGIN_OK)
        {
            Debug.LogWarning("LOGIN_RELOGIN_OK");
            initUser();
        }
        else if (str == FPortGlobal.LOGIN_COUNT)
        {
            Debug.LogWarning("LOGIN_COUNT");
            SystemMessageWindow.ShowAlert(LanguageConfigManager.Instance.getLanguage("serverState01"));
            ConnectManager.manager().closeConnect(ServerManagerment.Instance.lastServer.domainName, ServerManagerment.Instance.lastServer.port);
        }
        else if (str == FPortGlobal.LOGIN_CLOSE)
        {
            Debug.LogWarning("LOGIN_CLOSE");
            SystemMessageWindow.ShowAlert(LanguageConfigManager.Instance.getLanguage("serverState02"));
            ConnectManager.manager().closeConnect(ServerManagerment.Instance.lastServer.domainName, ServerManagerment.Instance.lastServer.port);
        }
        else if (str == FPortGlobal.LOGIN_TRUST)
        {
            Debug.LogWarning("LOGIN_TRUST");
            SystemMessageWindow.ShowAlert(LanguageConfigManager.Instance.getLanguage("serverState03"));
            ConnectManager.manager().closeConnect(ServerManagerment.Instance.lastServer.domainName, ServerManagerment.Instance.lastServer.port);
        }
        else if (str == FPortGlobal.LOGIN_SIGERROR)
        {
            Debug.LogWarning("LOGIN_SIGERROR");
            SystemMessageWindow.ShowAlert(LanguageConfigManager.Instance.getLanguage("serverState04"));
            ConnectManager.manager().closeConnect(ServerManagerment.Instance.lastServer.domainName, ServerManagerment.Instance.lastServer.port);
        }
        else if (str == FPortGlobal.LOGIN_LIMIT)
        {
            Debug.LogWarning("LOGIN_LIMIT");
            SystemMessageWindow.ShowAlert(LanguageConfigManager.Instance.getLanguage("serverState05"));
            ConnectManager.manager().closeConnect(ServerManagerment.Instance.lastServer.domainName, ServerManagerment.Instance.lastServer.port);
        }
        else if (str == FPortGlobal.LOGIN_CREATE)
        {
            Debug.LogWarning("LOGIN_CREATE");
            SystemMessageWindow.ShowAlert(LanguageConfigManager.Instance.getLanguage("serverState06"));
            ConnectManager.manager().closeConnect(ServerManagerment.Instance.lastServer.domainName, ServerManagerment.Instance.lastServer.port);
        }
        else if (str == FPortGlobal.LOGIN_USER_DISABLE)
        {
            Debug.LogWarning("LOGIN_USER_DISABLE");
            SystemMessageWindow.ShowAlert(LanguageConfigManager.Instance.getLanguage("serverState07"));
            ConnectManager.manager().closeConnect(ServerManagerment.Instance.lastServer.domainName, ServerManagerment.Instance.lastServer.port);
        }
        else
        {
            Debug.LogWarning("LOGIN_OTHER");
            //其他报错默认提示
            SystemMessageWindow.ShowAlert(LanguageConfigManager.Instance.getLanguage("serverState02"));
            ConnectManager.manager().closeConnect(ServerManagerment.Instance.lastServer.domainName, ServerManagerment.Instance.lastServer.port);
        }
    }
Ejemplo n.º 52
0
 internal static ErlMsg RegSendTT(ErlPid from, ErlAtom dest, IErlObject msg,
                                  ErlTrace trace, ErlAtom?cookie = null)
 {
     return(new ErlMsg(Tag.RegSend, from, dest, payload: msg, cookie: cookie));
 }
Ejemplo n.º 53
0
    /// <summary>
    /// Send an auth error to peer because he sent a bad cookie
    /// The auth error uses his cookie (not revealing ours).
    /// This is just like send_reg otherwise
    /// </summary>
    private void cookieError(ErlLocalNode local, ErlAtom cookie)
    {
      var header = new ErlOutputStream(writeVersion: false, capacity: HEADER_LEN);

      // preamble: 4 byte length + "PASS_THROUGH" tag + version
      header.Write4BE(0); // reserve space for length
      header.Write1(PASS_THROUGH);
      header.Write1((byte)ErlExternalTag.Version);

      header.WriteTupleHead(4);
      header.WriteLong((long)ErlMsg.Tag.RegSend);
      header.WritePid(local.CreatePid()); // disposable pid
      header.WriteAtom(cookie); // important: his cookie, not mine...
      header.WriteAtom("auth");

      // version for payload written later by the payload stream
      //header.Write1((byte)ErlExternalTag.Version);

      // the payload

      // the no_auth message (copied from Erlang) Don't change this (Erlang will crash)
      // {$gen_cast, {print, "~n** Unauthorized cookie ~w **~n", [foo@aule]}}

      var msg = ErlObject.Parse(
          "{'$gen_cast', {print, \"\n** Unauthorized cookie ~w **\n\", [" + local.NodeName.Value + "]}}");

      var payload = new ErlOutputStream(msg, writeVersion: true);

      // fix up length in preamble
      header.Poke4BE(0, (int)(header.Length + payload.Length - 4));

      try
      {
        DoSend(header, payload);
      }
      catch (Exception e)
      {
        Close();
        throw new ErlException(StringConsts.ERL_CONN_UNAUTH_COOKIE_ERROR.Args(cookie.Value), e);
      }
    }
Ejemplo n.º 54
0
 internal static ErlTuple EncodeRPCcast(
     ErlPid from, ErlAtom mod, ErlAtom fun, ErlList args, IErlObject gleader)
 {
   /*{'$gen_cast', { cast, Mod, Fun, Args, GroupLeader}} */
   return new ErlTuple(
           ConstAtoms.GenCast,
           new ErlTuple(ConstAtoms.Cast, mod, fun, args, gleader));
 }
Ejemplo n.º 55
0
        protected internal IErlObject ExecuteRPC(ErlAtom module, ErlAtom func, ErlList args, ErlMbox mbox = null)
        {
            var map = Map;

            return(executeRPC(module, func, args, mbox));
        }
Ejemplo n.º 56
0
        /// <summary>
        /// Intiate and open a connection to a remote node
        /// </summary>
        protected ErlAbstractConnection(ErlLocalNode self, ErlRemoteNode other, ErlAtom? cookie = null, bool connect = true)
            : this(self, other, null, cookie)
        {
            // now find highest common dist value
              if ((m_Peer.Proto != self.Proto) || (self.DistHigh < m_Peer.DistLow) || (self.DistLow > m_Peer.DistHigh))
            throw new ErlException(StringConsts.ERL_CONN_NO_COMMON_PROTO_ERROR);

              // highest common version: min(m_Peer.distHigh, self.distHigh)
              m_Peer.DistChoose = Math.Min(m_Peer.DistHigh, self.DistHigh);

              m_Connected = false;

              if (connect)
            Connect();
        }
Ejemplo n.º 57
0
    private IErlObject rpcCall(ErlPid from, ErlRef eref,
        ErlAtom mod, ErlAtom fun, ErlList args, IErlObject groupLeader)
    {
      // We spawn a new task, so that RPC calls wouldn't block the RPC server thread
      Task.Factory.StartNew(() =>
      {
        var type = Type.GetType(mod);

        if (type == null)
        {
          sendRpcReply(from, eref,
              ErlTuple.Create(ConstAtoms.Error, "unknown type: {0}".Args(mod)));
          return;
        }

        // TODO: add LRU caching
        //var method = type.GetMethod(fun.Value, BindingFlags.Static | BindingFlags.Public);

        string methodName = fun.Value;

        if (args.Count == 0)
        {
          var pi = type.GetProperty(fun, BindingFlags.Static | BindingFlags.Public);
          if (pi != null)
          {
            try
            {
              var result = pi.GetValue(null, null);
              sendRpcReply(from, eref,
                  ErlTuple.Create(ConstAtoms.Ok, result.ToErlObject()));
            }
            catch (Exception e)
            {
              sendRpcReply(from, eref,
                  ErlTuple.Create(ConstAtoms.Error, new ErlString(e.Message)));
            };
            return;
          }
        }

        var mi = type.GetMethods(BindingFlags.Static | BindingFlags.Public)
                     .Where(m => m.Name == methodName && m.GetParameters().Count() == args.Count)
                     .FirstOrDefault();

        if (mi == null)
        {
          sendRpcReply(from, eref,
              ErlTuple.Create(ConstAtoms.Error, "unknown method: {0}".Args(fun)));
          return;
        }

        var pars = mi.GetParameters();

        var margs = new object[pars.Length];

        for (int i = 0; i < pars.Length; i++)
        {
          var par = pars[i];
          var val = args[i];
          margs[i] = val.AsType(par.ParameterType);
        }

        try
        {
          var result = mi.Invoke(type, margs);
          sendRpcReply(from, eref, ErlTuple.Create(ConstAtoms.Ok, result.ToErlObject()));
        }
        catch (Exception e)
        {
          sendRpcReply(from, eref, ErlTuple.Create(ConstAtoms.Error, new ErlString(e.Message)));
        }
      });
      return (IErlObject)null;
    }
Ejemplo n.º 58
0
 /// <summary>
 /// Write atom to the stream
 /// </summary>
 public void WriteAtom(ErlAtom atom, Encoding encoding = null)
 {
   WriteAtom(atom.Value, encoding);
 }
Ejemplo n.º 59
0
 internal static ErlTuple EncodeRPC(
     ErlPid from, ErlAtom mod, ErlAtom fun, ErlList args, IErlObject gleader)
 {
   /*{Self, {call, Mod, Fun, Args, GroupLeader}} */
   return new ErlTuple(from, new ErlTuple(ConstAtoms.Call, mod, fun, args, gleader));
 }