Mercurial > hg > Database > Christie-sharp
comparison daemon/IncomingTcpConnection.cs @ 23:46cfeb0609c5
Add TcpConnections
author | riono <e165729@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 15 Dec 2020 22:11:40 +0900 |
parents | |
children | 58858657a0e0 |
comparison
equal
deleted
inserted
replaced
22:970c7f587126 | 23:46cfeb0609c5 |
---|---|
1 using System; | |
2 using System.Data; | |
3 using System.IO; | |
4 using Christie_net.codegear; | |
5 using Christie_net.datagear; | |
6 using Christie_net.datagear.command; | |
7 using Christie_net.datagear.dg; | |
8 using MessagePack; | |
9 using CommandType = Christie_net.datagear.command.CommandType; | |
10 | |
11 | |
12 namespace Christie_net.daemon { | |
13 public class IncomingTcpConnection { | |
14 private RemoteDataGearManager manager; | |
15 private CodeGearManager cgm; | |
16 private Connection connection; | |
17 | |
18 public IncomingTcpConnection(Connection connection) { | |
19 this.connection = connection; | |
20 this.cgm = connection.cgm; | |
21 } | |
22 | |
23 public void SetManager(RemoteDataGearManager manager) { | |
24 this.manager = manager; | |
25 } | |
26 | |
27 public void Run() { | |
28 byte[] deserializeData = null; | |
29 | |
30 | |
31 while (true) { | |
32 try { | |
33 // データはType, length, dataの順で入っているっぽい | |
34 connection.socket.Receive(deserializeData); | |
35 RemoteMessage msg = MessagePackSerializer.Deserialize<RemoteMessage>(deserializeData); | |
36 CommandType type = CommandTypeExt.GetCommandTypeFormId(msg.type); | |
37 byte[] data; | |
38 | |
39 switch (type) { | |
40 case CommandType.PUT: | |
41 data = new byte[MessagePackSerializer.Deserialize<int>(deserializeData)]; | |
42 connection.socket.Receive(data); | |
43 | |
44 try { | |
45 MessagePackDataGear<object> dg = | |
46 new MessagePackDataGear<object>(data, Type.GetType(msg.clazz)); | |
47 } catch (TypeLoadException e) { | |
48 Console.WriteLine(e.StackTrace); | |
49 } | |
50 | |
51 break; | |
52 case CommandType.REMOTEPEEK: | |
53 case CommandType.REMOTETAKE: | |
54 try { | |
55 Command cm = new CommandBuilder().Init(type).FromDgmName(msg.fromDmgName) | |
56 .Key(msg.key) | |
57 .Clazz(Type.GetType(msg.clazz)) | |
58 .Connection(connection).Build(); | |
59 //cgm.GetLocalDGM().RunCommand(cm); | |
60 } catch (TypeLoadException e) { | |
61 Console.WriteLine(e.StackTrace); | |
62 } | |
63 | |
64 break; | |
65 case CommandType.REPLY: // 待っていたwaitlistに渡してcsにセット | |
66 data = new byte[MessagePackSerializer.Deserialize<int>(deserializeData)]; | |
67 connection.socket.Receive(data); | |
68 | |
69 try { | |
70 MessagePackDataGear<object> dg = | |
71 new MessagePackDataGear<object>(data, Type.GetType(msg.clazz)); | |
72 // cgm.GetDGM(msg.fromDgmName).ResolveWaitCommand(msg.key, dg); | |
73 } catch (TypeLoadException e) { | |
74 Console.WriteLine(e.StackTrace); | |
75 } | |
76 | |
77 break; | |
78 default: | |
79 break; | |
80 } | |
81 } catch (IOException e) { | |
82 Console.WriteLine(e.StackTrace); | |
83 } | |
84 } | |
85 } | |
86 } | |
87 } |