changeset 56:dc3f59937772

remote dynamic
author riono <e165729@ie.u-ryukyu.ac.jp>
date Tue, 25 Jan 2022 16:46:26 +0900
parents b768fffe118c
children 3d46515f3887
files codegear/CodeGear.cs daemon/AcceptThread.cs daemon/IncomingTcpConnection.cs datagear/command/PutCommand.cs datagear/dg/MessagePackDataGear.cs
diffstat 5 files changed, 31 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/codegear/CodeGear.cs	Tue Jan 18 21:16:37 2022 +0900
+++ b/codegear/CodeGear.cs	Tue Jan 25 16:46:26 2022 +0900
@@ -45,7 +45,7 @@
         idg.FinishInput(cgm, commandList);
     }
 
-    public void SetCommand(CommandType type, string toDgmName, string key, DataGear<Object> dg) {
+    public void SetCommand(CommandType type, string toDgmName, string key, DataGear<object> dg) {
         Command command = new CommandBuilder().Init(type).Cg(this)
             .CgmID(cgm.cgmID)
             .ToDgmName(toDgmName)
--- a/daemon/AcceptThread.cs	Tue Jan 18 21:16:37 2022 +0900
+++ b/daemon/AcceptThread.cs	Tue Jan 25 16:46:26 2022 +0900
@@ -16,36 +16,34 @@
     }
 
     public void Run() {
-        while (true) {
-            try {
-                TcpClient client = null;
-                client = listener.AcceptTcpClient();
-                client.NoDelay = true;
+        try {
+            TcpClient client = null;
+            client = listener.AcceptTcpClient();
+            client.NoDelay = true;
+
+            IPEndPoint endPoint = (IPEndPoint) client.Client.RemoteEndPoint;
+            IPAddress ipAddress = endPoint.Address;
+            IPHostEntry hostEntry = Dns.GetHostEntry(ipAddress);
+            Console.WriteLine("Accept " + hostEntry.HostName + ":" + endPoint.Port);
+
+            Connection connection = new Connection(client.Client, cgm);
+            Console.WriteLine("connection:" + connection.GetInfoString());
+            string key = "accept" + counter;
 
-                IPEndPoint endPoint = (IPEndPoint) client.Client.RemoteEndPoint;
-                IPAddress ipAddress = endPoint.Address;
-                IPHostEntry hostEntry = Dns.GetHostEntry(ipAddress);
-                Console.WriteLine("Accept " + hostEntry.HostName + ":" + endPoint.Port);
-                
-                Connection connection = new Connection(client.Client, cgm);
-                Console.WriteLine("connection:" + connection.GetInfoString());
-                string key = "accept" + counter;
-                
-                IncomingTcpConnection incoming = new IncomingTcpConnection(connection);
-                Thread incomingThread = new Thread(incoming.Run);
-                incomingThread.Name = connection.GetInfoString() + "-IncomingTcp";
-                incomingThread.Start();
-                
-                cgm.SetAccept(key, incoming);
-                
-                OutboundTcpConnection outbound = new OutboundTcpConnection(connection);
-                Thread outboundThread = new Thread(outbound.Run);
-                outboundThread.Name = connection.GetInfoString() + "-OutboundTcp";
-                outboundThread.Start();
-                counter++;
-            } catch (Exception e) {
-                Console.WriteLine(e.StackTrace);
-            }
+            IncomingTcpConnection incoming = new IncomingTcpConnection(connection);
+            Thread incomingThread = new Thread(incoming.Run);
+            incomingThread.Name = connection.GetInfoString() + "-IncomingTcp";
+            incomingThread.Start();
+
+            cgm.SetAccept(key, incoming);
+
+            OutboundTcpConnection outbound = new OutboundTcpConnection(connection);
+            Thread outboundThread = new Thread(outbound.Run);
+            outboundThread.Name = connection.GetInfoString() + "-OutboundTcp";
+            outboundThread.Start();
+            counter++;
+        } catch (Exception e) {
+            Console.WriteLine(e.StackTrace);
         }
     }
 }
--- a/daemon/IncomingTcpConnection.cs	Tue Jan 18 21:16:37 2022 +0900
+++ b/daemon/IncomingTcpConnection.cs	Tue Jan 25 16:46:26 2022 +0900
@@ -25,12 +25,10 @@
 
     public void Run() {
         while (true) {
-            //TODO: Data長がわからないので1024で仮置き → ぴったしで読み込む必要がある
             // データはRemotemessage length, Remotemessage(Command), data length, dataの順で入っている
-            //byte[] packetSizeArray = new byte[4];
             byte[] remoteMessageSizeArray = new byte[1];
             byte[] remoteMessage;
-            byte[] dataSizeArray = new byte[4];
+            byte[] dataSizeArray = new byte[1];
             byte[] data;
 
             int dataLen;
--- a/datagear/command/PutCommand.cs	Tue Jan 18 21:16:37 2022 +0900
+++ b/datagear/command/PutCommand.cs	Tue Jan 25 16:46:26 2022 +0900
@@ -20,7 +20,7 @@
         try {
             byte[] command = MessagePackSerializer.Serialize(CreateRemoteMessage());
             byte[] commandsize = MessagePackSerializer.Serialize(command.Length);
-            byte[] data = new MessagePackDataGear<dynamic>(dg.GetData()).GetMessagePack();
+            byte[] data = new MessagePackDataGear<object>(dg.GetData()).GetMessagePack();
             byte[] datasize = MessagePackSerializer.Serialize(data.Length);
             
             // Debug
--- a/datagear/dg/MessagePackDataGear.cs	Tue Jan 18 21:16:37 2022 +0900
+++ b/datagear/dg/MessagePackDataGear.cs	Tue Jan 25 16:46:26 2022 +0900
@@ -59,14 +59,11 @@
     // If deserialize data is not primitive type, it is dictionary 
     public T MessagePackDataFormed(dynamic deserializedData) {
         var type = deserializedData.GetType();
-        //Console.WriteLine(type);
         T instance;
+        
         if (type.IsPrimitive || type == typeof(string) || type == typeof(decimal)) {
-            //instance = Activator.CreateInstance(clazz, deserializedData);
-            // var typeInference = deserializedData;
             instance = Convert.ChangeType(deserializedData, clazz);
         } else {
-            //Dictionary<dynamic, dynamic> dataDictionary = (Dictionary<dynamic, dynamic>) deserializedData;
             List<object> valueArray = new List<object>();
             foreach (var VARIABLE in (dynamic) deserializedData) {
                 Console.WriteLine("val:" + VARIABLE);