Implement Read, Write methods

This commit is contained in:
Sajid Anwar 2018-06-15 19:13:26 -07:00
parent cf07af6eae
commit a42310b631

View file

@ -32,6 +32,8 @@ namespace Ryujinx.HLE.OsHle.Services.Bsd
{ 14, Connect }, { 14, Connect },
{ 18, Listen }, { 18, Listen },
{ 21, SetSockOpt }, { 21, SetSockOpt },
{ 24, Write },
{ 25, Read },
{ 26, Close } { 26, Close }
}; };
} }
@ -122,7 +124,8 @@ namespace Ryujinx.HLE.OsHle.Services.Bsd
int SocketId = Context.RequestData.ReadInt32(); int SocketId = Context.RequestData.ReadInt32();
int SocketFlags = 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 try
{ {
@ -130,7 +133,7 @@ namespace Ryujinx.HLE.OsHle.Services.Bsd
//Logging.Debug("Received Buffer:" + Environment.NewLine + Logging.HexDump(ReceivedBuffer)); //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(BytesRead);
Context.ResponseData.Write(0); Context.ResponseData.Write(0);
@ -150,8 +153,8 @@ namespace Ryujinx.HLE.OsHle.Services.Bsd
int SocketId = Context.RequestData.ReadInt32(); int SocketId = Context.RequestData.ReadInt32();
int SocketFlags = Context.RequestData.ReadInt32(); int SocketFlags = Context.RequestData.ReadInt32();
byte[] SentBuffer = Context.Memory.ReadBytes(Context.Request.SendBuff[0].Position, (long SentPosition, long SentSize) = Context.Request.GetBufferType0x21();
Context.Request.SendBuff[0].Size); byte[] SentBuffer = Context.Memory.ReadBytes(SentPosition, SentSize);
try try
{ {
@ -221,7 +224,7 @@ namespace Ryujinx.HLE.OsHle.Services.Bsd
{ {
int SocketId = Context.RequestData.ReadInt32(); int SocketId = Context.RequestData.ReadInt32();
long AddrBufferPtr = Context.Request.ReceiveBuff[0].Position; (long AddrBufferPosition, long AddrBuffSize) = Context.Request.GetBufferType0x22();
Socket HandleAccept = null; Socket HandleAccept = null;
@ -265,7 +268,7 @@ namespace Ryujinx.HLE.OsHle.Services.Bsd
Writer.Write(IpAddress); Writer.Write(IpAddress);
Context.Memory.WriteBytes(AddrBufferPtr, MS.ToArray()); Context.Memory.WriteBytes(AddrBufferPosition, MS.ToArray());
Context.ResponseData.Write(Sockets.Count - 1); Context.ResponseData.Write(Sockets.Count - 1);
Context.ResponseData.Write(0); Context.ResponseData.Write(0);
@ -383,6 +386,60 @@ namespace Ryujinx.HLE.OsHle.Services.Bsd
return 0; return 0;
} }
//(u32 socket, buffer<i8, 0x21, 0> 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<i8, 0x22, 0> 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) //(u32 socket) -> (i32 ret, u32 bsd_errno)
public long Close(ServiceCtx Context) public long Close(ServiceCtx Context)
{ {