本文整理汇总了C#中NamedPipeServerStream类的典型用法代码示例。如果您正苦于以下问题:C# NamedPipeServerStream类的具体用法?C# NamedPipeServerStream怎么用?C# NamedPipeServerStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NamedPipeServerStream类属于命名空间,在下文中一共展示了NamedPipeServerStream类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: PingPong_Async
public async Task PingPong_Async()
{
// Create names for two pipes
string outName = Path.GetRandomFileName();
string inName = Path.GetRandomFileName();
// Create the two named pipes, one for each direction, then create
// another process with which to communicate
using (var outbound = new NamedPipeServerStream(outName, PipeDirection.Out))
using (var inbound = new NamedPipeClientStream(".", inName, PipeDirection.In))
using (RemoteInvoke(PingPong_OtherProcess, outName, inName))
{
// Wait for both pipes to be connected
await Task.WhenAll(outbound.WaitForConnectionAsync(), inbound.ConnectAsync());
// Repeatedly write then read a byte to and from the other process
var data = new byte[1];
for (byte i = 0; i < 10; i++)
{
data[0] = i;
await outbound.WriteAsync(data, 0, data.Length);
data[0] = 0;
int received = await inbound.ReadAsync(data, 0, data.Length);
Assert.Equal(1, received);
Assert.Equal(i, data[0]);
}
}
}
开发者ID:ChuangYang,项目名称:corefx,代码行数:28,代码来源:NamedPipeTest.CrossProcess.cs
示例2: CreateWithNegativeOneServerInstances_DefaultsToMaxServerInstances
public static void CreateWithNegativeOneServerInstances_DefaultsToMaxServerInstances()
{
// When passed -1 as the maxnumberofserverisntances, the NamedPipeServerStream.Windows class
// will translate that to the platform specific maximum number (255)
using (var server = new NamedPipeServerStream(GetUniquePipeName(), PipeDirection.InOut, -1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous))
using (var server2 = new NamedPipeServerStream(PipeDirection.InOut, false, true, server.SafePipeHandle))
using (var server3 = new NamedPipeServerStream(PipeDirection.InOut, false, true, server.SafePipeHandle))
{
}
}
开发者ID:noahfalk,项目名称:corefx,代码行数:10,代码来源:NamedPipeTest.CreateServer.cs
示例3: GetAccessControl_NamedPipe_BeforeWaitingToConnect
public void GetAccessControl_NamedPipe_BeforeWaitingToConnect()
{
string pipeName = GetUniquePipeName();
var server = new NamedPipeServerStream(pipeName, PipeDirection.Out, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);
var client = new NamedPipeClientStream(".", pipeName, PipeDirection.In, PipeOptions.Asynchronous);
Assert.NotNull(server.GetAccessControl());
server.SetAccessControl(new PipeSecurity());
Assert.Throws<InvalidOperationException>(() => client.GetAccessControl());
Assert.Throws<InvalidOperationException>(() => client.SetAccessControl(new PipeSecurity()));
}
开发者ID:ChuangYang,项目名称:corefx,代码行数:11,代码来源:NamedPipeTest.AclExtensions.cs
示例4: CreateServerClientPair
protected override ServerClientPair CreateServerClientPair()
{
ServerClientPair ret = new ServerClientPair();
string pipeName = GetUniquePipeName();
var readablePipe = new NamedPipeServerStream(pipeName, PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);
var writeablePipe = new NamedPipeClientStream(".", pipeName, PipeDirection.InOut, PipeOptions.Asynchronous);
Task serverConnect = Task.Factory.FromAsync(readablePipe.BeginWaitForConnection, readablePipe.EndWaitForConnection, null);
writeablePipe.Connect();
serverConnect.Wait();
ret.readablePipe = readablePipe;
ret.writeablePipe = writeablePipe;
return ret;
}
开发者ID:dotnet,项目名称:corefx,代码行数:15,代码来源:NamedPipeTest.Read.netstandard17.cs
示例5: CreateServerClientPair
protected override ServerClientPair CreateServerClientPair()
{
ServerClientPair ret = new ServerClientPair();
string pipeName = GetUniquePipeName();
var writeablePipe = new NamedPipeServerStream(pipeName, PipeDirection.Out, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);
var readablePipe = new NamedPipeClientStream(".", pipeName, PipeDirection.In, PipeOptions.Asynchronous);
Task clientConnect = readablePipe.ConnectAsync();
writeablePipe.WaitForConnection();
clientConnect.Wait();
ret.readablePipe = readablePipe;
ret.writeablePipe = writeablePipe;
return ret;
}
开发者ID:ChuangYang,项目名称:corefx,代码行数:15,代码来源:NamedPipeTest.AclExtensions.cs
示例6: RunAsClient_Windows
public async Task RunAsClient_Windows()
{
string pipeName = Path.GetRandomFileName();
using (var server = new NamedPipeServerStream(pipeName))
using (var client = new NamedPipeClientStream(".", pipeName, PipeDirection.InOut, PipeOptions.None, TokenImpersonationLevel.Impersonation))
{
Task serverTask = server.WaitForConnectionAsync();
client.Connect();
await serverTask;
bool ran = false;
server.RunAsClient(() => ran = true);
Assert.True(ran, "Expected delegate to have been invoked");
}
}
开发者ID:dotnet,项目名称:corefx,代码行数:16,代码来源:NamedPipeTest.RunAsClient.cs
示例7: ConnectWithConflictingDirections_Throws_UnauthorizedAccessException
[PlatformSpecific(PlatformID.Windows)] // Unix implementation uses bidirectional sockets
public void ConnectWithConflictingDirections_Throws_UnauthorizedAccessException()
{
string serverName1 = GetUniquePipeName();
using (NamedPipeServerStream server = new NamedPipeServerStream(serverName1, PipeDirection.Out))
using (NamedPipeClientStream client = new NamedPipeClientStream(".", serverName1, PipeDirection.Out))
{
Assert.Throws<UnauthorizedAccessException>(() => client.Connect());
Assert.False(client.IsConnected);
}
string serverName2 = GetUniquePipeName();
using (NamedPipeServerStream server = new NamedPipeServerStream(serverName2, PipeDirection.In))
using (NamedPipeClientStream client = new NamedPipeClientStream(".", serverName2, PipeDirection.In))
{
Assert.Throws<UnauthorizedAccessException>(() => client.Connect());
Assert.False(client.IsConnected);
}
}
开发者ID:ESgarbi,项目名称:corefx,代码行数:19,代码来源:NamedPipeTest.Specific.cs
示例8: PingPong_OtherProcess
private static int PingPong_OtherProcess(string inName, string outName)
{
// Create pipes with the supplied names
using (var inbound = new NamedPipeClientStream(".", inName, PipeDirection.In))
using (var outbound = new NamedPipeServerStream(outName, PipeDirection.Out))
{
// Wait for the connections to be established
Task.WaitAll(inbound.ConnectAsync(), outbound.WaitForConnectionAsync());
// Repeatedly read then write bytes from and to the other process
for (int i = 0; i < 10; i++)
{
int b = inbound.ReadByte();
outbound.WriteByte((byte)b);
}
}
return SuccessExitCode;
}
开发者ID:ChuangYang,项目名称:corefx,代码行数:18,代码来源:NamedPipeTest.CrossProcess.cs
示例9: GetAccessControl_NamedPipeServerStream_Broken
public void GetAccessControl_NamedPipeServerStream_Broken()
{
string pipeName = GetUniquePipeName();
var server = new NamedPipeServerStream(pipeName, PipeDirection.Out, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);
var client = new NamedPipeClientStream(".", pipeName, PipeDirection.In, PipeOptions.Asynchronous);
Task clientConnect = client.ConnectAsync();
server.WaitForConnection();
clientConnect.Wait();
Assert.NotNull(server.GetAccessControl());
server.SetAccessControl(new PipeSecurity());
Assert.NotNull(client.GetAccessControl());
client.SetAccessControl(new PipeSecurity());
client.Dispose();
Assert.Throws<IOException>(() => server.Write(new byte[] { 0 }, 0, 1)); // Sets the servers PipeState to Broken
server.SetAccessControl(new PipeSecurity());
}
开发者ID:ChuangYang,项目名称:corefx,代码行数:19,代码来源:NamedPipeTest.AclExtensions.cs
示例10: ServerConnectAsId
private static int ServerConnectAsId(string pipeName, string pairIDString)
{
uint pairID = uint.Parse(pairIDString);
Assert.NotEqual(-1, seteuid(pairID));
using (var outbound = new NamedPipeServerStream(pipeName, PipeDirection.Out))
using (var handle = RemoteInvoke(ClientConnectAsID, pipeName, pairIDString))
{
// Connect as the unpriveleged user, but RunAsClient as the superuser
outbound.WaitForConnection();
Assert.NotEqual(-1, seteuid(0));
bool ran = false;
uint ranAs = 0;
outbound.RunAsClient(() => {
ran = true;
ranAs = geteuid();
});
Assert.True(ran, "Expected delegate to have been invoked");
Assert.Equal(pairID, ranAs);
}
return SuccessExitCode;
}
开发者ID:dotnet,项目名称:corefx,代码行数:22,代码来源:NamedPipeTest.RunAsClient.cs
示例11: PingPong_Sync
public void PingPong_Sync()
{
// Create names for two pipes
string outName = Path.GetRandomFileName();
string inName = Path.GetRandomFileName();
// Create the two named pipes, one for each direction, then create
// another process with which to communicate
using (var outbound = new NamedPipeServerStream(outName, PipeDirection.Out))
using (var inbound = new NamedPipeClientStream(".", inName, PipeDirection.In))
using (RemoteInvoke(PingPong_OtherProcess, outName, inName))
{
// Wait for both pipes to be connected
Task.WaitAll(outbound.WaitForConnectionAsync(), inbound.ConnectAsync());
// Repeatedly write then read a byte to and from the other process
for (byte i = 0; i < 10; i++)
{
outbound.WriteByte(i);
int received = inbound.ReadByte();
Assert.Equal(i, received);
}
}
}
开发者ID:ChuangYang,项目名称:corefx,代码行数:24,代码来源:NamedPipeTest.CrossProcess.cs
示例12: OSX_BufferSizeNotSupported
public static void OSX_BufferSizeNotSupported()
{
int desiredBufferSize = 10;
string pipeName = GetUniquePipeName();
using (var server = new NamedPipeServerStream(pipeName, PipeDirection.In, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous, desiredBufferSize, desiredBufferSize))
using (var client = new NamedPipeClientStream(".", pipeName, PipeDirection.Out))
{
Task clientConnect = client.ConnectAsync();
server.WaitForConnection();
clientConnect.Wait();
Assert.Throws<PlatformNotSupportedException>(() => server.InBufferSize);
Assert.Throws<PlatformNotSupportedException>(() => client.OutBufferSize);
}
}
开发者ID:noahfalk,项目名称:corefx,代码行数:15,代码来源:NamedPipeTest.Specific.cs
示例13: MountAllDevices
//.........这里部分代码省略.........
// create new process
Process tcLauncher = new Process();
// set exec name
tcLauncher.StartInfo.FileName = Configuration.LauncherLocation;
// set arguments
tcLauncher.StartInfo.Arguments = '"' + config.TrueCrypt.ExecutablePath +
"\" " + tcArgsReady;
// use CreateProcess()
tcLauncher.StartInfo.UseShellExecute = false;
#if DEBUG
LogAppend(null, "StartInfo.Arguments: {0}", tcLauncher.StartInfo.Arguments);
#endif
// arr, fire the canon! - well, try it...
try
{
LogAppend("StartProcess");
tcLauncher.Start();
}
catch (Win32Exception ex)
{
// dammit, dammit, dammit! something went wrong at the very end...
LogAppend("ErrGeneral", ex.Message);
buttonStartWorker.Enabled = false;
buttonStopWorker.Enabled = false;
LogAppend("CheckTCConf");
return mountSuccess;
}
LogAppend("ProcessStarted");
// Status
LogAppend("WaitDevLaunch");
Cursor.Current = Cursors.WaitCursor;
// Wait for incoming message
using (NamedPipeServerStream npServer = new NamedPipeServerStream("TrueCryptMessage"))
{
npServer.WaitForConnection();
using (StreamReader sReader = new StreamReader(npServer, Encoding.Unicode))
{
String input = sReader.ReadToEnd();
#if DEBUG
LogAppend(null, "Pipe: {0}", input);
#endif
if (input != "OK")
{
LogAppend("ErrTrueCryptMsg", input);
if (config.TrueCrypt.ShowErrors)
{
#if DEBUG
MessageBox.Show(string.Format(langRes.GetString("MsgTDiskTimeout"), encMedia, input),
langRes.GetString("MsgHDiskTimeout"), MessageBoxButtons.OK, MessageBoxIcon.Warning);
#endif
notifyIconSysTray.BalloonTipTitle = langRes.GetString("MsgHDiskTimeout");
notifyIconSysTray.BalloonTipIcon = ToolTipIcon.Warning;
notifyIconSysTray.BalloonTipText = string.Format(langRes.GetString("MsgTDiskTimeout"), encMedia, input);
notifyIconSysTray.ShowBalloonTip(config.BalloonTimePeriod);
}
LogAppend("MountCanceled", encMedia.ToString());
Cursor.Current = Cursors.Default;
return mountSuccess;
}
else
LogAppend("InfoLauncherOk");
}
}
Cursor.Current = Cursors.Default;
LogAppend("LogicalDiskOnline", encMedia.DriveLetterCurrent);
// mount was successful
mountSuccess = true;
// display balloon tip on successful mount
MountBalloonTip(encMedia);
// if set, open device content in windows explorer
if (encMedia.OpenExplorer)
{
LogAppend("OpenExplorer", encMedia.DriveLetterCurrent);
try
{
Process.Start("explorer.exe", encMedia.DriveLetterCurrent + @":\");
}
catch (Exception eex)
{
// error in windows explorer (what a surprise)
LogAppend("ErrGeneral", eex.Message);
LogAppend("ErrExplorerOpen");
}
}
// add the current mounted media to the dismount sys tray list
AddMountedMedia(encMedia);
return mountSuccess;
}
开发者ID:nefarius,项目名称:TrueMount-3,代码行数:101,代码来源:MountManager.cs
示例14: ServerCountOverMaxServerInstances_Throws_IOException
[PlatformSpecific(PlatformID.Windows)] // NumberOfServerInstances > 1 isn't supported and has undefined behavior on Unix
public static void ServerCountOverMaxServerInstances_Throws_IOException()
{
string uniqueServerName = GetUniquePipeName();
using (NamedPipeServerStream server = new NamedPipeServerStream(uniqueServerName, PipeDirection.Out, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous))
{
Assert.Throws<IOException>(() => new NamedPipeServerStream(uniqueServerName));
}
}
开发者ID:noahfalk,项目名称:corefx,代码行数:9,代码来源:NamedPipeTest.CreateServer.cs
示例15: Windows_ServerCloneWithDifferentDirection_Throws_UnauthorizedAccessException
[PlatformSpecific(PlatformID.Windows)] // NumberOfServerInstances > 1 isn't supported and has undefined behavior on Unix
public static void Windows_ServerCloneWithDifferentDirection_Throws_UnauthorizedAccessException()
{
string uniqueServerName = GetUniquePipeName();
using (NamedPipeServerStream server = new NamedPipeServerStream(uniqueServerName, PipeDirection.In, 2, PipeTransmissionMode.Byte, PipeOptions.Asynchronous))
{
Assert.Throws<UnauthorizedAccessException>(() => new NamedPipeServerStream(uniqueServerName, PipeDirection.Out));
}
}
开发者ID:noahfalk,项目名称:corefx,代码行数:9,代码来源:NamedPipeTest.CreateServer.cs
示例16: Unix_GetHandleOfNewServerStream_Throws_InvalidOperationException
public static void Unix_GetHandleOfNewServerStream_Throws_InvalidOperationException()
{
var pipe = new NamedPipeServerStream(GetUniquePipeName(), PipeDirection.Out, 1, PipeTransmissionMode.Byte);
Assert.Throws<InvalidOperationException>(() => pipe.SafePipeHandle);
}
开发者ID:noahfalk,项目名称:corefx,代码行数:5,代码来源:NamedPipeTest.CreateServer.cs
示例17: Windows_CreateFromAlreadyBoundHandle_Throws_ArgumentException
public static void Windows_CreateFromAlreadyBoundHandle_Throws_ArgumentException(PipeDirection direction)
{
// The pipe is already bound
var pipe = new NamedPipeServerStream(GetUniquePipeName(), direction, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);
Assert.Throws<ArgumentException>(() => new NamedPipeServerStream(direction, true, true, pipe.SafePipeHandle));
pipe.Dispose();
}
开发者ID:noahfalk,项目名称:corefx,代码行数:7,代码来源:NamedPipeTest.CreateServer.cs
示例18: Windows_MessagePipeTransissionMode
[PlatformSpecific(PlatformID.Windows)] // Unix currently doesn't support message mode
public async Task Windows_MessagePipeTransissionMode(PipeOptions serverOptions)
{
byte[] msg1 = new byte[] { 5, 7, 9, 10 };
byte[] msg2 = new byte[] { 2, 4 };
byte[] received1 = new byte[] { 0, 0, 0, 0 };
byte[] received2 = new byte[] { 0, 0 };
byte[] received3 = new byte[] { 0, 0, 0, 0 };
byte[] received4 = new byte[] { 0, 0, 0, 0 };
byte[] received5 = new byte[] { 0, 0 };
byte[] received6 = new byte[] { 0, 0, 0, 0 };
string pipeName = GetUniquePipeName();
using (var server = new NamedPipeServerStream(pipeName, PipeDirection.InOut, 1, PipeTransmissionMode.Message, serverOptions))
{
using (var client = new NamedPipeClientStream(".", pipeName, PipeDirection.InOut, PipeOptions.None, TokenImpersonationLevel.Impersonation))
{
server.ReadMode = PipeTransmissionMode.Message;
Assert.Equal(PipeTransmissionMode.Message, server.ReadMode);
Task clientTask = Task.Run(() =>
{
client.Connect();
client.Write(msg1, 0, msg1.Length);
client.Write(msg2, 0, msg2.Length);
client.Write(msg1, 0, msg1.Length);
client.Write(msg1, 0, msg1.Length);
client.Write(msg2, 0, msg2.Length);
client.Write(msg1, 0, msg1.Length);
int serverCount = client.NumberOfServerInstances;
Assert.Equal(1, serverCount);
});
server.WaitForConnection();
int len1 = server.Read(received1, 0, msg1.Length);
Assert.True(server.IsMessageComplete);
Assert.Equal(msg1.Length, len1);
Assert.Equal(msg1, received1);
int len2 = server.Read(received2, 0, msg2.Length);
Assert.True(server.IsMessageComplete);
Assert.Equal(msg2.Length, len2);
Assert.Equal(msg2, received2);
int expectedRead = msg1.Length - 1;
int len3 = server.Read(received3, 0, expectedRead); // read one less than message
Assert.False(server.IsMessageComplete);
Assert.Equal(expectedRead, len3);
for (int i = 0; i < expectedRead; ++i)
{
Assert.Equal(msg1[i], received3[i]);
}
expectedRead = msg1.Length - expectedRead;
Assert.Equal(expectedRead, server.Read(received3, len3, expectedRead));
Assert.True(server.IsMessageComplete);
Assert.Equal(msg1, received3);
Assert.Equal(msg1.Length, await server.ReadAsync(received4, 0, msg1.Length));
Assert.True(server.IsMessageComplete);
Assert.Equal(msg1, received4);
Assert.Equal(msg2.Length, await server.ReadAsync(received5, 0, msg2.Length));
Assert.True(server.IsMessageComplete);
Assert.Equal(msg2, received5);
expectedRead = msg1.Length - 1;
Assert.Equal(expectedRead, await server.ReadAsync(received6, 0, expectedRead)); // read one less than message
Assert.False(server.IsMessageComplete);
for (int i = 0; i < expectedRead; ++i)
{
Assert.Equal(msg1[i], received6[i]);
}
expectedRead = msg1.Length - expectedRead;
Assert.Equal(expectedRead, await server.ReadAsync(received6, msg1.Length - expectedRead, expectedRead));
Assert.True(server.IsMessageComplete);
Assert.Equal(msg1, received6);
await clientTask;
}
}
}
开发者ID:ESgarbi,项目名称:corefx,代码行数:87,代码来源:NamedPipeTest.Specific.cs
示例19: Windows_CreateFromDisposedServerHandle_Throws_ObjectDisposedException
public static void Windows_CreateFromDisposedServerHandle_Throws_ObjectDisposedException(PipeDirection direction)
{
// The pipe is closed when we try to make a new Stream with it
var pipe = new NamedPipeServerStream(GetUniquePipeName(), direction, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);
SafePipeHandle handle = pipe.SafePipeHandle;
pipe.Dispose();
Assert.Throws<ObjectDisposedException>(() => new NamedPipeServerStream(direction, true, true, pipe.SafePipeHandle).Dispose());
}
开发者ID:noahfalk,项目名称:corefx,代码行数:8,代码来源:NamedPipeTest.CreateServer.cs
示例20: ClientConnectWrongConflictingDirection
public static void ClientConnectWrongConflictingDirection()
{
const string serverName1 = "testServer4";
using (NamedPipeServerStream server = new NamedPipeServerStream(serverName1, PipeDirection.Out))
using (NamedPipeClientStream client = new NamedPipeClientStream(".", serverName1, PipeDirection.Out))
{
Assert.Throws<UnauthorizedAccessException>(() => client.Connect());
Assert.False(client.IsConnected);
}
const string serverName2 = "testServer5";
using (NamedPipeServerStream server = new NamedPipeServerStream(serverName2, PipeDirection.In))
using (NamedPipeClientStream client = new NamedPipeClientStream(".", serverName2, PipeDirection.In))
{
Assert.Throws<UnauthorizedAccessException>(() => client.Connect());
Assert.False(client.IsConnected);
}
}
开发者ID:nuskarthik,项目名称:corefx,代码行数:22,代码来源:NamedPipesThrowsTests.cs
注:本文中的NamedPipeServerStream类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论