From a42310b6316f0c313d0108ae5025ea1384bb0a18 Mon Sep 17 00:00:00 2001 From: Sajid Anwar Date: Fri, 15 Jun 2018 19:13:26 -0700 Subject: [PATCH] Implement Read, Write methods --- Ryujinx.HLE/OsHle/Services/Bsd/IClient.cs | 69 +++++++++++++++++++++-- 1 file changed, 63 insertions(+), 6 deletions(-) diff --git a/Ryujinx.HLE/OsHle/Services/Bsd/IClient.cs b/Ryujinx.HLE/OsHle/Services/Bsd/IClient.cs index f007331b3f..54f979e318 100644 --- a/Ryujinx.HLE/OsHle/Services/Bsd/IClient.cs +++ b/Ryujinx.HLE/OsHle/Services/Bsd/IClient.cs @@ -32,6 +32,8 @@ namespace Ryujinx.HLE.OsHle.Services.Bsd { 14, Connect }, { 18, Listen }, { 21, SetSockOpt }, + { 24, Write }, + { 25, Read }, { 26, Close } }; } @@ -122,7 +124,8 @@ namespace Ryujinx.HLE.OsHle.Services.Bsd int SocketId = Context.RequestData.ReadInt32(); int SocketFlags = Context.RequestData.ReadInt32(); - byte[] ReceivedBuffer = new byte[Context.Request.ReceiveBuff[0].Size]; + (long ReceivePosition, long ReceiveLength) = Context.Request.GetBufferType0x22(); + byte[] ReceivedBuffer = new byte[ReceiveLength]; try { @@ -130,7 +133,7 @@ namespace Ryujinx.HLE.OsHle.Services.Bsd //Logging.Debug("Received Buffer:" + Environment.NewLine + Logging.HexDump(ReceivedBuffer)); - Context.Memory.WriteBytes(Context.Request.ReceiveBuff[0].Position, ReceivedBuffer); + Context.Memory.WriteBytes(ReceivePosition, ReceivedBuffer); Context.ResponseData.Write(BytesRead); Context.ResponseData.Write(0); @@ -150,8 +153,8 @@ namespace Ryujinx.HLE.OsHle.Services.Bsd int SocketId = Context.RequestData.ReadInt32(); int SocketFlags = Context.RequestData.ReadInt32(); - byte[] SentBuffer = Context.Memory.ReadBytes(Context.Request.SendBuff[0].Position, - Context.Request.SendBuff[0].Size); + (long SentPosition, long SentSize) = Context.Request.GetBufferType0x21(); + byte[] SentBuffer = Context.Memory.ReadBytes(SentPosition, SentSize); try { @@ -221,7 +224,7 @@ namespace Ryujinx.HLE.OsHle.Services.Bsd { int SocketId = Context.RequestData.ReadInt32(); - long AddrBufferPtr = Context.Request.ReceiveBuff[0].Position; + (long AddrBufferPosition, long AddrBuffSize) = Context.Request.GetBufferType0x22(); Socket HandleAccept = null; @@ -265,7 +268,7 @@ namespace Ryujinx.HLE.OsHle.Services.Bsd Writer.Write(IpAddress); - Context.Memory.WriteBytes(AddrBufferPtr, MS.ToArray()); + Context.Memory.WriteBytes(AddrBufferPosition, MS.ToArray()); Context.ResponseData.Write(Sockets.Count - 1); Context.ResponseData.Write(0); @@ -383,6 +386,60 @@ namespace Ryujinx.HLE.OsHle.Services.Bsd return 0; } + //(u32 socket, buffer message) -> (i32 ret, u32 bsd_errno) + public long Write(ServiceCtx Context) + { + int SocketId = Context.RequestData.ReadInt32(); + + (long SentPosition, long SentSize) = Context.Request.GetBufferType0x21(); + byte[] SentBuffer = Context.Memory.ReadBytes(SentPosition, SentSize); + + try + { + //Logging.Debug("Wrote Buffer:" + Environment.NewLine + Logging.HexDump(SentBuffer)); + + int BytesSent = Sockets[SocketId].Handle.Send(SentBuffer); + + Context.ResponseData.Write(BytesSent); + Context.ResponseData.Write(0); + } + catch (SocketException Ex) + { + Context.ResponseData.Write(-1); + Context.ResponseData.Write(Ex.ErrorCode - 10000); + } + + return 0; + } + + //(u32 socket) -> (i32 ret, u32 bsd_errno, buffer message) + public long Read(ServiceCtx Context) + { + int SocketId = Context.RequestData.ReadInt32(); + + (long ReceivePosition, long ReceiveLength) = Context.Request.GetBufferType0x22(); + byte[] ReceivedBuffer = new byte[ReceiveLength]; + + try + { + int BytesRead = Sockets[SocketId].Handle.Receive(ReceivedBuffer); + + //Logging.Debug("Received Buffer:" + Environment.NewLine + Logging.HexDump(ReceivedBuffer)); + + Context.Memory.WriteBytes(ReceivePosition, ReceivedBuffer); + + Context.ResponseData.Write(BytesRead); + Context.ResponseData.Write(0); + } + catch (SocketException Ex) + { + Context.ResponseData.Write(-1); + Context.ResponseData.Write(Ex.ErrorCode - 10000); + } + + return 0; + } + //(u32 socket) -> (i32 ret, u32 bsd_errno) public long Close(ServiceCtx Context) {