Mercurial > hg > Database > Christie-sharp
annotate daemon/IncomingTcpConnection.cs @ 51:486683ead53f
bug survey
author | riono <e165729@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 11 Jan 2022 20:02:18 +0900 |
parents | 476b6efeca5b |
children | ef3fd58af531 |
rev | line source |
---|---|
23 | 1 using System; |
2 using System.IO; | |
3 using Christie_net.codegear; | |
4 using Christie_net.datagear; | |
5 using Christie_net.datagear.command; | |
6 using Christie_net.datagear.dg; | |
7 using MessagePack; | |
8 using CommandType = Christie_net.datagear.command.CommandType; | |
9 | |
10 | |
11 namespace Christie_net.daemon { | |
12 public class IncomingTcpConnection { | |
13 private RemoteDataGearManager manager; | |
14 private CodeGearManager cgm; | |
15 private Connection connection; | |
16 | |
17 public IncomingTcpConnection(Connection connection) { | |
18 this.connection = connection; | |
19 this.cgm = connection.cgm; | |
20 } | |
21 | |
22 public void SetManager(RemoteDataGearManager manager) { | |
23 this.manager = manager; | |
24 } | |
25 | |
26 public void Run() { | |
27 while (true) { | |
48 | 28 //TODO: Data長がわからないので1024で仮置き → ぴったしで読み込む必要がある |
51 | 29 byte[] streamData = new byte[1000000]; |
30 | |
31 | |
50 | 32 int length = 0; |
23 | 33 try { |
50 | 34 length = connection.stream.Read(streamData); |
51 | 35 //Console.WriteLine("call:" + connection.stream.Position); |
39 | 36 |
50 | 37 } catch (Exception e) { |
38 Console.WriteLine(e.StackTrace); | |
39 } | |
40 | |
41 // データはRemotemessage(Command), length, dataの順で入っている | |
42 //int dataLength = connection.socket.Receive(deserializeCommand); | |
47 | 43 |
50 | 44 // Debug |
51 | 45 //Console.WriteLine("length:" + length); |
46 | |
50 | 47 RemoteMessage msg = MessagePackSerializer.Deserialize<RemoteMessage>(streamData); |
48 CommandType type = CommandTypeExt.GetCommandTypeFormId(msg.type); | |
49 | |
50 try { | |
39 | 51 byte[] data; |
47 | 52 |
23 | 53 switch (type) { |
54 case CommandType.PUT: | |
40 | 55 data = msg.data; |
23 | 56 |
57 try { | |
45 | 58 MessagePackDataGear<object> dg = |
59 new MessagePackDataGear<object>(data, Type.GetType(msg.clazz)); | |
50 | 60 |
29
0cd2684e401b
update InputDataGear and more
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
24
diff
changeset
|
61 cgm.GetLocalDGM().Put(msg.key, dg); |
23 | 62 } catch (TypeLoadException e) { |
63 Console.WriteLine(e.StackTrace); | |
64 } | |
65 break; | |
50 | 66 |
23 | 67 case CommandType.REMOTEPEEK: |
68 case CommandType.REMOTETAKE: | |
69 try { | |
70 Command cm = new CommandBuilder().Init(type).FromDgmName(msg.fromDmgName) | |
71 .Key(msg.key) | |
72 .Clazz(Type.GetType(msg.clazz)) | |
73 .Connection(connection).Build(); | |
29
0cd2684e401b
update InputDataGear and more
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
24
diff
changeset
|
74 cgm.GetLocalDGM().RunCommand(cm); |
23 | 75 } catch (TypeLoadException e) { |
76 Console.WriteLine(e.StackTrace); | |
50 | 77 } catch (Exception e) { |
78 Console.WriteLine(e); | |
23 | 79 } |
80 break; | |
50 | 81 |
23 | 82 case CommandType.REPLY: // 待っていたwaitlistに渡してcsにセット |
40 | 83 data = msg.data; |
47 | 84 |
39 | 85 // data = new byte[MessagePackSerializer.Deserialize<int>(streamData)]; |
86 // connection.socket.Receive(data); | |
23 | 87 |
88 try { | |
89 MessagePackDataGear<object> dg = | |
90 new MessagePackDataGear<object>(data, Type.GetType(msg.clazz)); | |
29
0cd2684e401b
update InputDataGear and more
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
24
diff
changeset
|
91 cgm.GetDGM(msg.fromDmgName).ResolveWaitCommand(msg.key, dg); |
23 | 92 } catch (TypeLoadException e) { |
93 Console.WriteLine(e.StackTrace); | |
94 } | |
95 break; | |
50 | 96 |
23 | 97 default: |
98 break; | |
99 } | |
50 | 100 } catch (Exception e) { |
101 Console.WriteLine("call: " + e.StackTrace); | |
102 } | |
23 | 103 } |
104 } | |
105 } | |
106 } |