关于 Windows 中的管道行为

发布于 2024-09-18 13:12:27 字数 760 浏览 3 评论 0原文

    hPipe = CreateNamedPipe( 
          lpszPipename,             // pipe name 
          PIPE_ACCESS_DUPLEX,       // read/write access 
          PIPE_TYPE_MESSAGE |       // message type pipe 
          PIPE_READMODE_MESSAGE |   // message-read mode 
          PIPE_WAIT,                // blocking mode 
          PIPE_UNLIMITED_INSTANCES, // max. instances  
          BUFSIZE,                  // output buffer size 
          BUFSIZE,                  // input buffer size 
          0,       

我对此有两个问题:

  1. 如果上面的代码运行两次,将创建多少个管道,12
  2. 如果2,假设其中一个管道由A连接,则B尝试连接lpszPipename,是吗保证B会连接到没有人连接过的那个?
    hPipe = CreateNamedPipe( 
          lpszPipename,             // pipe name 
          PIPE_ACCESS_DUPLEX,       // read/write access 
          PIPE_TYPE_MESSAGE |       // message type pipe 
          PIPE_READMODE_MESSAGE |   // message-read mode 
          PIPE_WAIT,                // blocking mode 
          PIPE_UNLIMITED_INSTANCES, // max. instances  
          BUFSIZE,                  // output buffer size 
          BUFSIZE,                  // input buffer size 
          0,       

I have two questions about this:

  1. what if the above code is run twice,how many pipes will get created,1 or 2?
  2. if 2,suppose one of the pipe get connected by A,then B tries to connect lpszPipename, is it guaranteed that B will connect to the one that no one has connected?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一身骄傲 2024-09-25 13:12:27

如果使用 FILE_FLAG_FIRST_PIPE_INSTANCE 标志,则第二次调用同名的 CreateNamedPipe 将失败;如果未使用此标志,则连接到同一管道。如果第二个 CreateNamedPipe 调用成功,它将返回同一内核对象的另一个句柄。

The second call to CreateNamedPipe with the same name fails, if FILE_FLAG_FIRST_PIPE_INSTANCE flag is used, or connects to the same pipe, if this flag is not used. In the case the second CreateNamedPipe call succeeds, it returns another handle to the same kernel object.

忆离笙 2024-09-25 13:12:27

CreateNamedPipe 函数的第四个参数中,您可以限制可以创建的命名管道实例的数量。如果将其设置为 PIPE_UNLIMITED_INSTANCE (如示例所示)并调用 CreateNamedPipe 函数使用相同的参数两次,将创建两个实例(它们将共享相同的管道名称),并且两个客户端将能够连接到您的命名管道服务器(每个客户端都连接到一个命名管道实例) )。

有关详细信息,请参阅 http://msdn .microsoft.com/en-us/library/aa365594%28v=VS.85%29.aspx

In the fourth parameter of CreateNamedPipe function you can limit how many named pipe instances can be created. If you set it to PIPE_UNLIMITED_INSTANCE as in your example and call the CreateNamedPipe function twice with the same parameters, two instances will be created (they'll share the same pipe name) and two clients will be able to connect to your named pipe server (each of them to one named pipe instance).

For more information look at http://msdn.microsoft.com/en-us/library/aa365594%28v=VS.85%29.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文