Mercurial > hg > Database > Christie-sharp
changeset 69:959096e8786b
fix send data
author | riono <e165729@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 02 Feb 2022 16:39:38 +0900 |
parents | 976d43003487 |
children | 0f4fa15e5bcb |
files | daemon/IncomingTcpConnection.cs datagear/command/PutCommand.cs |
diffstat | 2 files changed, 18 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/daemon/IncomingTcpConnection.cs Sun Jan 30 18:02:09 2022 +0900 +++ b/daemon/IncomingTcpConnection.cs Wed Feb 02 16:39:38 2022 +0900 @@ -26,16 +26,16 @@ public void Run() { while (true) { // データはRemotemessage length, Remotemessage(Command), data length, dataの順で入っている - byte[] remoteMessageSizeArray = new byte[1]; + byte[] remoteMessageSizeArray = new byte[5]; byte[] remoteMessage; - byte[] dataSizeArray = new byte[1]; + byte[] dataSizeArray = new byte[5]; byte[] data; int dataLen; int length = 0; try { // get RemoteMessage.class size - connection.stream.Read(remoteMessageSizeArray, 0, 1); + connection.stream.Read(remoteMessageSizeArray, 0, 5); int remoteMsglen = MessagePackSerializer.Deserialize<int>(remoteMessageSizeArray); remoteMessage = new byte[remoteMsglen]; @@ -55,7 +55,7 @@ switch (type) { case CommandType.PUT: // get data size - connection.stream.Read(dataSizeArray, 0, 1); + connection.stream.Read(dataSizeArray, 0, 5); dataLen = MessagePackSerializer.Deserialize<int>(dataSizeArray); data = new byte[dataLen]; @@ -92,7 +92,7 @@ case CommandType.REPLY: // 待っていたwaitlistに渡してcsにセット // get data size - connection.stream.Read(dataSizeArray, 0, 1); + connection.stream.Read(dataSizeArray, 0, 5); dataLen = MessagePackSerializer.Deserialize<int>(dataSizeArray); data = new byte[dataLen];
--- a/datagear/command/PutCommand.cs Sun Jan 30 18:02:09 2022 +0900 +++ b/datagear/command/PutCommand.cs Wed Feb 02 16:39:38 2022 +0900 @@ -20,9 +20,22 @@ try { byte[] command = MessagePackSerializer.Serialize(CreateRemoteMessage()); byte[] commandsize = MessagePackSerializer.Serialize(command.Length); + + if (commandsize.Length < 5) { + byte[] newCommandsize = new byte[5]; + Array.Copy(commandsize, newCommandsize, commandsize.Length); + commandsize = newCommandsize; + } + byte[] data = new MessagePackDataGear<object>(dg.GetData()).GetMessagePack(); byte[] datasize = MessagePackSerializer.Serialize(data.Length); + if (datasize.Length < 5) { + byte[] newDatasize = new byte[5]; + Array.Copy(datasize, newDatasize, datasize.Length); + datasize = newDatasize; + } + // Debug // RemoteMessage msg = MessagePackSerializer.Deserialize<RemoteMessage>(command); // Console.WriteLine("serialize msg:" + msg);