本文整理汇总了C#中Pipe.Resume方法的典型用法代码示例。如果您正苦于以下问题:C# Pipe.Resume方法的具体用法?C# Pipe.Resume怎么用?C# Pipe.Resume使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pipe
的用法示例。
在下文中一共展示了Pipe.Resume方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OneSideClose
public void OneSideClose(string name)
{
int close_cb_called = 0;
int cl_send_cb_called = 0;
int cl_recv_cb_called = 0;
int sv_send_cb_called = 0;
int sv_recv_cb_called = 0;
var server = new PipeListener();
server.Bind(name);
server.Connection += () => {
var pipe = server.Accept();
pipe.Resume();
pipe.Read(Encoding.ASCII, (str) => {
sv_recv_cb_called++;
Assert.AreEqual("PING", str);
pipe.Write(Encoding.ASCII, "PONG", (s) => { sv_send_cb_called++; });
pipe.Close(() => { close_cb_called++; });
server.Close(() => { close_cb_called++; });
});
};
server.Listen();
Pipe client = new Pipe();
client.Connect(name, (_) => {
client.Read(Encoding.ASCII, (str) => {
cl_recv_cb_called++;
Assert.AreEqual("PONG", str);
});
client.Complete += () => {
close_cb_called++;
};
client.Resume();
client.Write(Encoding.ASCII, "PING", (s) => { cl_send_cb_called++; });
});
Assert.AreEqual(0, close_cb_called);
Assert.AreEqual(0, cl_send_cb_called);
Assert.AreEqual(0, cl_recv_cb_called);
Assert.AreEqual(0, sv_send_cb_called);
Assert.AreEqual(0, sv_recv_cb_called);
Loop.Default.Run();
Assert.AreEqual(3, close_cb_called);
Assert.AreEqual(1, cl_send_cb_called);
Assert.AreEqual(1, cl_recv_cb_called);
Assert.AreEqual(1, sv_send_cb_called);
Assert.AreEqual(1, sv_recv_cb_called);
#if DEBUG
Assert.AreEqual(1, UV.PointerCount);
#endif
}
示例2: ProcessSpawn
public void ProcessSpawn()
{
string file = Default.TestExecutable;
using (var stdout = new Pipe() { Writeable = true })
using (var process = Process.Spawn(new ProcessOptions() {
File = Default.TestArguments[0],
Arguments = Default.TestArguments,
Streams = new UVStream [] { null, stdout }
})) {
//for some reason this ain't working
//stdout.Read(Encoding.ASCII, (result) => Assert.Equal("Hello World!", result));
stdout.Resume();
Loop.Default.Run();
Assert.Equal(0, process.ExitCode);
}
Loop.Default.Run();
}
示例3: ProcessSpawn
Process ProcessSpawn(string command, Action<string> callback)
{
var stdout = new Pipe() { Writeable = true };
var streams = new UVStream[] {
null,
stdout,
};
string text = null;
var args = command.Split(new char[] { ' ' });
var p = Process.Spawn(new ProcessOptions() {
File = args[0],
Arguments = args,
Streams = streams
}, (process) => {
callback(text);
});
stdout.Read(Encoding.ASCII, (t) => text = t);
stdout.Resume();
return p;
}
示例4: Stress
public void Stress(string name)
{
for (int j = 0; j < 10; j++) {
int times = 10;
int close_cb_called = 0;
int cl_send_cb_called = 0;
int cl_recv_cb_called = 0;
int sv_send_cb_called = 0;
int sv_recv_cb_called = 0;
var server = new PipeListener();
server.Bind(name);
server.Connection += () => {
var pipe = server.Accept();
pipe.Resume();
pipe.Read(Encoding.ASCII, (str) => {
sv_recv_cb_called++;
Assert.AreEqual(Times("PING", times), str);
for (int i = 0; i < times; i++) {
pipe.Write(Encoding.ASCII, "PONG", (s) => { sv_send_cb_called++; });
}
pipe.Close(() => { close_cb_called++; });
server.Close(() => { close_cb_called++; });
});
};
server.Listen();
Pipe client = new Pipe();
client.Connect(name, (_) => {
client.Resume();
for (int i = 0; i < times; i++) {
client.Write(Encoding.ASCII, "PING", (s) => { cl_send_cb_called++; });
}
client.Read(Encoding.ASCII, (str) => {
cl_recv_cb_called++;
Assert.AreEqual(Times("PONG", times), str);
client.Close(() => { close_cb_called++; });
});
});
Assert.AreEqual(0, close_cb_called);
Assert.AreEqual(0, cl_send_cb_called);
Assert.AreEqual(0, cl_recv_cb_called);
Assert.AreEqual(0, sv_send_cb_called);
Assert.AreEqual(0, sv_recv_cb_called);
Loop.Default.Run();
Assert.AreEqual(3, close_cb_called);
Assert.AreEqual(times, cl_send_cb_called);
Assert.AreEqual(1, cl_recv_cb_called);
Assert.AreEqual(times, sv_send_cb_called);
Assert.AreEqual(1, sv_recv_cb_called);
#if DEBUG
Assert.AreEqual(1, UV.PointerCount);
#endif
}
}