reactosdbg/RosDBG/socketpipe.cs
Art Yerkes 6030ecd415 A debugging shell for use with KDBG. Not perfect yet but it can display the
locals and stack trace at the place where reactos is stopped.

svn path=/trunk/tools/reactosdbg/; revision=759
2008-07-31 07:00:10 +00:00

46 lines
1.3 KiB
C#

using System;
using System.Text;
using System.Net.Sockets;
namespace Gdb
{
public class SocketPipe : Pipe
{
Socket mSocket;
byte []mBuf = new byte[4096];
IAsyncResult mResult;
public event PipeReceiveEventHandler PipeReceiveEvent;
public bool Write(string output)
{
byte []outbuf = UTF8Encoding.UTF8.GetBytes(output);
int off = 0, res;
do
{
res = mSocket.Send(outbuf, off, outbuf.Length - off, SocketFlags.None);
if (res > 0)
off += res;
}
while (off < outbuf.Length && res != -1);
return off == outbuf.Length;
}
public void TriggerReadable(IAsyncResult result)
{
int bytes = mSocket.EndReceive(mResult);
string datastr = UTF8Encoding.UTF8.GetString(mBuf, 0, bytes);
if (PipeReceiveEvent != null)
PipeReceiveEvent(this, new PipeReceiveEventArgs(datastr));
mResult = mSocket.BeginReceive
(mBuf, 0, mBuf.Length, SocketFlags.None, TriggerReadable, this);
}
public SocketPipe(Socket socket)
{
mSocket = socket;
mResult = mSocket.BeginReceive
(mBuf, 0, mBuf.Length, SocketFlags.None, TriggerReadable, this);
}
}
}