Author: gedmurphy
Date: Wed Jun 3 01:04:18 2009
New Revision: 41262
URL:
http://svn.reactos.org/svn/reactos?rev=41262&view=rev
Log:
- Run pipe server waiting off on a different thread.
- Raise an event when a client connects and set up the connection as before.
- rosdbg now correctly waits for a connection and auto-connects when it finds one
Modified:
trunk/tools/reactosdbg/DebugProtocol/DebugConnection.cs
trunk/tools/reactosdbg/Pipe/namedpipe.cs
trunk/tools/reactosdbg/Pipe/pipe.cs
trunk/tools/reactosdbg/RosDBG/Properties/AssemblyInfo.cs
Modified: trunk/tools/reactosdbg/DebugProtocol/DebugConnection.cs
URL:
http://svn.reactos.org/svn/reactos/trunk/tools/reactosdbg/DebugProtocol/Deb…
==============================================================================
--- trunk/tools/reactosdbg/DebugProtocol/DebugConnection.cs [iso-8859-1] (original)
+++ trunk/tools/reactosdbg/DebugProtocol/DebugConnection.cs [iso-8859-1] Wed Jun 3
01:04:18 2009
@@ -223,6 +223,31 @@
mKdb.ThreadListEvent += ThreadListEvent;
}
+ void NamedPipe_ClientConnectedEvent(object sender, EventArgs e)
+ {
+ mKdb = new KDBG(mNamedPipe);
+ Running = true;
+ ConnectEventHandlers();
+ /* retrieve input seperate thread */
+ ReadThread = new Thread(mNamedPipe.ReadLoop);
+ ReadThread.Start();
+ WriteThread = new Thread(mNamedPipe.WriteLoop);
+ WriteThread.Start();
+ }
+
+ public void StartPipe(string pipeName, ConnectionMode mode)
+ {
+ Close();
+ ConnectionMode = Mode.PipeMode;
+
+ mNamedPipe = new NamedPipe();
+ mNamedPipe.ClientConnectedEvent += new
EventHandler(NamedPipe_ClientConnectedEvent);
+ mNamedPipe.PipeReceiveEvent +=new PipeReceiveEventHandler(PipeReceiveEvent);
+ mNamedPipe.PipeErrorEvent +=new PipeErrorEventHandler(MediumErrorEvent);
+
+ mNamedPipe.CreatePipe(pipeName, mode);
+ }
+
public void StartTCP(string host, int port)
{
Close();
@@ -236,30 +261,6 @@
mDnsAsyncResult = Dns.BeginGetHostEntry(host, mDnsLookup, this);
}
- public void StartPipe(string pipeName, ConnectionMode mode)
- {
- Close();
- ConnectionMode = Mode.PipeMode;
- mNamedPipe = new NamedPipe();
- if (mNamedPipe.CreatePipe(pipeName, mode))
- {
- mKdb = new KDBG(mNamedPipe);
- mNamedPipe.PipeReceiveEvent += PipeReceiveEvent;
- mNamedPipe.PipeErrorEvent += MediumError;
- Running = true;
- ConnectEventHandlers();
- /* retrieve input seperate thread */
- ReadThread = new Thread(mNamedPipe.ReadLoop);
- ReadThread.Start();
- WriteThread = new Thread(mNamedPipe.WriteLoop);
- WriteThread.Start();
- }
- else
- {
- ConnectionMode = Mode.ClosedMode;
- }
- }
-
public void StartSerial(string port, int baudrate)
{
Close();
@@ -273,7 +274,7 @@
//create pipe and kdb instances, connect internal receive pipe
mMedium = new SerialPipe(mSerialPort);
mMedium.PipeReceiveEvent += PipeReceiveEvent;
- mMedium.PipeErrorEvent += MediumError;
+ mMedium.PipeErrorEvent += MediumErrorEvent;
mKdb = new KDBG(mMedium);
ConnectEventHandlers();
Running = true;
@@ -351,8 +352,10 @@
mNamedPipe = null;
}
Running = false;
- ReadThread.Abort();
- WriteThread.Abort();
+ if (ReadThread != null)
+ ReadThread.Abort();
+ if (WriteThread != null)
+ WriteThread.Abort();
break;
}
@@ -363,7 +366,7 @@
ConnectionMode = Mode.ClosedMode;
}
- void MediumError(object sender, PipeErrorEventArgs args)
+ void MediumErrorEvent(object sender, PipeErrorEventArgs args)
{
Close();
}
@@ -373,7 +376,7 @@
if (mAsyncConnect.SocketError == SocketError.Success)
{
mMedium = new SocketPipe(mSocket);
- mMedium.PipeErrorEvent += MediumError;
+ mMedium.PipeErrorEvent += MediumErrorEvent;
mMedium.PipeReceiveEvent += PipeReceiveEvent;
mKdb = new KDBG(mMedium);
ConnectEventHandlers();
Modified: trunk/tools/reactosdbg/Pipe/namedpipe.cs
URL:
http://svn.reactos.org/svn/reactos/trunk/tools/reactosdbg/Pipe/namedpipe.cs…
==============================================================================
--- trunk/tools/reactosdbg/Pipe/namedpipe.cs [iso-8859-1] (original)
+++ trunk/tools/reactosdbg/Pipe/namedpipe.cs [iso-8859-1] Wed Jun 3 01:04:18 2009
@@ -16,40 +16,58 @@
MODE_AUTO = 0x00000002
}
- public class NamedPipe : Pipe
+ public class NamedPipe : Pipe, NPipe
{
public const int PIPE_SIZE = 1024;
private PipeStream ioStream; /* stream for io operations */
private String wCommand; /* buffer of a single command line */
private List<String> cmdList; /*list of commands pending to be written */
-
+ private bool bClientConn;
+ private Thread waitThread;
+
+ public event EventHandler ClientConnectedEvent;
public event PipeReceiveEventHandler PipeReceiveEvent;
public event PipeErrorEventHandler PipeErrorEvent;
private static ManualResetEvent newWriteData = new ManualResetEvent(false);
+ public bool IsClientConnected
+ {
+ get { return bClientConn; }
+ }
+
public NamedPipe()
{
cmdList = new List<string>();
}
- public bool CreateServerPipe(string name)
+ private void WaitForConnection(object data)
+ {
+ NamedPipeServerStream pipeStream = (NamedPipeServerStream)data;
+
+ pipeStream.WaitForConnection();
+
+ if (pipeStream.IsConnected)
+ {
+ ioStream = pipeStream;
+ bClientConn = true;
+
+ if (ClientConnectedEvent != null)
+ {
+ ClientConnectedEvent(this, EventArgs.Empty);
+ }
+ }
+ }
+
+ public void CreateServerPipe(string name)
{
/* create a pipe and wait for a client */
NamedPipeServerStream sStream = new NamedPipeServerStream(name,
PipeDirection.InOut, 1,
PipeTransmissionMode.Byte, PipeOptions.Asynchronous, PIPE_SIZE,
PIPE_SIZE);
- sStream.WaitForConnection();
-
- if (sStream.IsConnected)
- {
- ioStream = sStream;
- return true;
- }
- else
- {
- return false;
- }
+
+ waitThread = new Thread(WaitForConnection);
+ waitThread.Start(sStream);
}
public bool CreateClientPipe(string name)
@@ -88,33 +106,20 @@
case ConnectionMode.MODE_AUTO:
//check if pipe exists, if not create server pipe, wait certain time,
check if pipe...
//TODO: server-client lookup should time out
- while (true)
- {
- if (CreateClientPipe(name))
- {
- break;
- }
- if (CreateServerPipe(name))
- {
- break;
- }
- }
+ CreateClientPipe(name);
+ CreateServerPipe(name);
+
return true;
case ConnectionMode.MODE_CLIENT:
- while (!CreateClientPipe(name)) ;
+ CreateClientPipe(name);
/* pipe open, everything fine */
return true;
case ConnectionMode.MODE_SERVER:
- if (CreateServerPipe(name))
- {
- /* wait for a client*/
-
+ CreateServerPipe(name);
return true;
- }
- break;
}
return false;
}
@@ -123,38 +128,48 @@
{
if (ioStream != null)
ioStream.Close();
+
+ if (waitThread != null)
+ waitThread.Abort();
}
public void WriteLoop()
{
- try
- {
- while (true)
- {
- if (cmdList.Count > 0)
+ if (!bClientConn)
+ {
+ if (PipeErrorEvent != null)
+ PipeErrorEvent.Invoke(this, new PipeErrorEventArgs("Client not
connected"));
+ }
+ else
+ {
+ try
+ {
+ while (true)
{
- byte[] wBuf = new byte[cmdList[0].Length];
- UTF8Encoding.UTF8.GetBytes(cmdList[0], 0, cmdList[0].Length,
wBuf, 0);
-
- ioStream.Write(wBuf, 0, cmdList[0].Length);
-
- /* remove written data from commandlist */
- cmdList.RemoveAt(0);
+ if (cmdList.Count > 0)
+ {
+ byte[] wBuf = new byte[cmdList[0].Length];
+ UTF8Encoding.UTF8.GetBytes(cmdList[0], 0, cmdList[0].Length,
wBuf, 0);
+
+ ioStream.Write(wBuf, 0, cmdList[0].Length);
+
+ /* remove written data from commandlist */
+ cmdList.RemoveAt(0);
+ }
+ else if (cmdList.Count == 0)
+ {
+ /* wait until new data is signaled */
+ newWriteData.Reset();
+ newWriteData.WaitOne();
+ }
}
- else if (cmdList.Count == 0)
- {
- /* wait until new data is signaled */
- newWriteData.Reset();
- newWriteData.WaitOne();
- }
- }
- }
- catch (Exception e)
- {
- if (PipeErrorEvent != null)
- PipeErrorEvent.Invoke(this, new PipeErrorEventArgs(e.Message));
- }
-
+ }
+ catch (Exception e)
+ {
+ if (PipeErrorEvent != null)
+ PipeErrorEvent.Invoke(this, new PipeErrorEventArgs(e.Message));
+ }
+ }
}
public void ReadLoop()
@@ -162,27 +177,35 @@
byte[] buf = new byte[PIPE_SIZE];
int read = 0;
- try
- {
- while(true)
- {
- read = ioStream.Read(buf, 0, PIPE_SIZE);
- if (read > 0)
+ if (!bClientConn)
+ {
+ if (PipeErrorEvent != null)
+ PipeErrorEvent.Invoke(this, new PipeErrorEventArgs("Client not
connected"));
+ }
+ else
+ {
+ try
+ {
+ while (true)
{
- if (PipeReceiveEvent != null)
- PipeReceiveEvent.Invoke(this, new
PipeReceiveEventArgs(UTF8Encoding.UTF8.GetString(buf, 0, read)));
+ read = ioStream.Read(buf, 0, PIPE_SIZE);
+ if (read > 0)
+ {
+ if (PipeReceiveEvent != null)
+ PipeReceiveEvent.Invoke(this, new
PipeReceiveEventArgs(UTF8Encoding.UTF8.GetString(buf, 0, read)));
+ }
+ else
+ {
+ /* connecion closed */
+ break;
+ }
}
- else
- {
- /* connecion closed */
- break;
- }
- }
- }
- catch (Exception e)
- {
- if (PipeErrorEvent != null)
- PipeErrorEvent.Invoke(this, new PipeErrorEventArgs(e.Message));
+ }
+ catch (Exception e)
+ {
+ if (PipeErrorEvent != null)
+ PipeErrorEvent.Invoke(this, new PipeErrorEventArgs(e.Message));
+ }
}
}
Modified: trunk/tools/reactosdbg/Pipe/pipe.cs
URL:
http://svn.reactos.org/svn/reactos/trunk/tools/reactosdbg/Pipe/pipe.cs?rev=…
==============================================================================
--- trunk/tools/reactosdbg/Pipe/pipe.cs [iso-8859-1] (original)
+++ trunk/tools/reactosdbg/Pipe/pipe.cs [iso-8859-1] Wed Jun 3 01:04:18 2009
@@ -31,4 +31,9 @@
event PipeErrorEventHandler PipeErrorEvent;
bool Write(string output);
}
+
+ public interface NPipe
+ {
+ event EventHandler ClientConnectedEvent;
+ }
}
Modified: trunk/tools/reactosdbg/RosDBG/Properties/AssemblyInfo.cs
URL:
http://svn.reactos.org/svn/reactos/trunk/tools/reactosdbg/RosDBG/Properties…
==============================================================================
--- trunk/tools/reactosdbg/RosDBG/Properties/AssemblyInfo.cs [iso-8859-1] (original)
+++ trunk/tools/reactosdbg/RosDBG/Properties/AssemblyInfo.cs [iso-8859-1] Wed Jun 3
01:04:18 2009
@@ -39,5 +39,5 @@
// will be increased as well. MSI installers must not be generated with the same Build
Number
// otherwise they won't upgrade the old installation!
-[assembly: AssemblyVersion("1.0.2.24")]
-[assembly: AssemblyFileVersion("1.0.2.24")]
+[assembly: AssemblyVersion("1.0.2.40")]
+[assembly: AssemblyFileVersion("1.0.2.40")]