mirror of
https://github.com/danbulant/Cosmos
synced 2026-06-10 02:02:30 +00:00
This commit is contained in:
parent
e2c018fa0d
commit
272c4f3410
3 changed files with 48 additions and 31 deletions
|
|
@ -9,41 +9,13 @@ using System.Windows.Forms;
|
|||
namespace Cosmos.Debug.VSDebugEngine {
|
||||
|
||||
static public class DebugWindows {
|
||||
static private NamedPipeClientStream mPipe;
|
||||
static private StreamWriter mWriter;
|
||||
static Cosmos.Compiler.Debug.PipeClient mPipe;
|
||||
|
||||
static public void SendCommand(byte aCmd, byte[] aData) {
|
||||
if (mPipe == null) {
|
||||
// User might run mult instances of VS, so we need to make sure the pipe name
|
||||
// is unique but also predictable since the pipe is the only way to talk
|
||||
// between the debugger and ToolWindows project.
|
||||
int xPID = System.Diagnostics.Process.GetCurrentProcess().Id;
|
||||
mPipe = new NamedPipeClientStream(".", Cosmos.Compiler.Debug.Pipes.DownName, PipeDirection.Out);
|
||||
try {
|
||||
// For now we assume its there or not from the first call.
|
||||
// If we don't find the server, we disable it to avoid causing lag.
|
||||
// TODO: In future - try this instead:
|
||||
// String[] listOfPipes = System.IO.Directory.GetFiles(@"\.\pipe\");
|
||||
|
||||
mPipe.Connect(500);
|
||||
} catch (TimeoutException ex) {
|
||||
mPipe.Close();
|
||||
mPipe = null;
|
||||
return;
|
||||
}
|
||||
mWriter = new StreamWriter(mPipe);
|
||||
mPipe = new Cosmos.Compiler.Debug.PipeClient(Cosmos.Compiler.Debug.Pipes.DownName);
|
||||
}
|
||||
|
||||
mPipe.WriteByte(aCmd);
|
||||
|
||||
int xLength = Math.Min(aData.Length, 32000);
|
||||
mPipe.WriteByte((byte)(xLength >> 8));
|
||||
mPipe.WriteByte((byte)(xLength & 0xFF));
|
||||
if (xLength > 0) {
|
||||
mPipe.Write(aData, 0, xLength);
|
||||
}
|
||||
|
||||
mPipe.Flush();
|
||||
mPipe.SendCommand(aCmd, aData);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,6 +59,9 @@ namespace Cosmos.Compiler.Debug {
|
|||
public static readonly string UpName;
|
||||
|
||||
static Pipes() {
|
||||
// User might run mult instances of VS, so we need to make sure the pipe name
|
||||
// is unique but also predictable since the pipe is the only way to talk
|
||||
// between the debugger and ToolWindows project.
|
||||
int xPID = System.Diagnostics.Process.GetCurrentProcess().Id;
|
||||
DownName = @"Cosmos\DebugDown-" + xPID;
|
||||
UpName = @"Cosmos\DebugUp-" + xPID;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,51 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Pipes;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Cosmos.Compiler.Debug {
|
||||
public class PipeClient {
|
||||
private string mPipeName;
|
||||
private NamedPipeClientStream mPipe;
|
||||
private StreamWriter mWriter;
|
||||
|
||||
public PipeClient(string aPipeName) {
|
||||
mPipeName = aPipeName;
|
||||
}
|
||||
|
||||
public void SendCommand(byte aCmd, byte[] aData) {
|
||||
// We need to delay creation and connect until its used, so we guarantee
|
||||
// that the server side is active and ready.
|
||||
if (mPipe == null) {
|
||||
mPipe = new NamedPipeClientStream(".", Cosmos.Compiler.Debug.Pipes.DownName, PipeDirection.Out);
|
||||
try {
|
||||
// For now we assume its there or not from the first call.
|
||||
// If we don't find the server, we disable it to avoid causing lag.
|
||||
// TODO: In future - try this instead:
|
||||
// String[] listOfPipes = System.IO.Directory.GetFiles(@"\.\pipe\");
|
||||
|
||||
mPipe.Connect(500);
|
||||
} catch (TimeoutException ex) {
|
||||
mPipe.Close();
|
||||
mPipe = null;
|
||||
return;
|
||||
}
|
||||
mWriter = new StreamWriter(mPipe);
|
||||
}
|
||||
|
||||
mPipe.WriteByte(aCmd);
|
||||
|
||||
int xLength = Math.Min(aData.Length, 32000);
|
||||
mPipe.WriteByte((byte)(xLength >> 8));
|
||||
mPipe.WriteByte((byte)(xLength & 0xFF));
|
||||
if (xLength > 0) {
|
||||
mPipe.Write(aData, 0, xLength);
|
||||
}
|
||||
|
||||
mPipe.Flush();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue