如何跨平台端口unix管道?

时间:2023-01-26 12:27:02

I have a code that looks like this:

我有一个代码如下:

uses this library

使用这个库

#include <unistd.h>

#define READ_FD 0
#define WRITE_FD 1

int m_pipe[2]; 

if(pipe(m_pipe) != -1) {
   unsigned long Id = gdk_input_add(m_pipe[READ_FD], GDK_INPUT_READ, Callback, (gpointer)this);
}

and it surprisingly builds on both linux(all major flavors: AS3, AS5, solaris) and windows. However, it doesn't really work on windows at all.

它令人惊讶地建立在Linux(所有主要风格:AS3,AS5,solaris)和Windows上。但是,它根本不适用于Windows。

How should a code using pipes be implemented so it works on both windows and linux?

应该如何实现使用管道的代码,以便它可以在Windows和Linux上运行?

1 个解决方案

#1


I would expose the upper functionality and not pipes themselves. On unix the lower level library code would use pipes but on some other machine it could use a different mechanism.

我会公开上层功能而不是管道本身。在unix上,较低级别的库代码将使用管道,但在其他一些机器上,它可以使用不同的机制。

#1


I would expose the upper functionality and not pipes themselves. On unix the lower level library code would use pipes but on some other machine it could use a different mechanism.

我会公开上层功能而不是管道本身。在unix上,较低级别的库代码将使用管道,但在其他一些机器上,它可以使用不同的机制。