mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-16 12:01:13 +00:00
* feat(serial): support local Windows named pipe consoles * test(serial): synchronize pipe acceptance and cover saved-host form * fix(serial): preserve named-pipe paths with spaces when editing hosts * test(serial): verify Windows pipes through native Electron IPC * test(serial): keep Electron listener callbacks in renderer context * test(serial): cover busy pipe cancellation and bounded slow-reader writes * test(serial): construct single-instance fixture pipe path correctly
34 lines
1.3 KiB
C#
34 lines
1.3 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.IO.Pipes;
|
|
|
|
// A VM-like server with exactly one client slot. Keep the same server handle
|
|
// alive between clients so reconnect tests do not race pipe creation/removal.
|
|
class SingleInstancePipe {
|
|
static void Main(string[] args) {
|
|
using (var pipe = new NamedPipeServerStream(args[0], PipeDirection.InOut, 1,
|
|
PipeTransmissionMode.Byte, PipeOptions.Asynchronous)) {
|
|
Console.WriteLine("READY");
|
|
Console.Out.Flush();
|
|
var buffer = new byte[8192];
|
|
while (true) {
|
|
try {
|
|
pipe.WaitForConnection();
|
|
int count;
|
|
while ((count = pipe.Read(buffer, 0, buffer.Length)) > 0) {
|
|
pipe.Write(buffer, 0, count);
|
|
pipe.Flush();
|
|
}
|
|
} catch (IOException error) {
|
|
// Accept can also see an already-closed late client (ERROR_NO_DATA).
|
|
int code = error.HResult & 0xffff;
|
|
if (code != 109 && code != 232 && code != 233) throw;
|
|
} finally {
|
|
try { pipe.Disconnect(); }
|
|
catch (InvalidOperationException) { /* Accept failed before connection. */ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|