本文介绍了有没有办法让在Windows文件描述符非阻塞?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想端口从Linux我的code到Windows。它是这样的:

I want to port my code from linux to windows. It is something like this:

void SetNonBlocking( int filehandle )
{
    int fhFlags;

    fhFlags = fcntl(filehandle,F_GETFL);
    if (fhFlags < 0)
    {
        perror("fcntl(F_GETFL)");
        exit(1);
    }

    fhFlags |= O_NONBLOCK;
    if (fcntl(filehandle,F_SETFL,fhFlags) < 0)
    {
        perror("fcntl(F_SETFL)");
        exit(1);
    }

    return;
}

现在我想在窗口一样。有任何想法吗? Actualy我的文件句柄被读取,则通过创建WINAPI管侧 CreatePipe 方法。

Now I want have same in windows. Any ideas? Actualy my filehandle is read side of pipe which is created via WinApi CreatePipe method.

推荐答案

Windows API函数 CreateNamedPipe时有一个选项,使处理无阻塞。 ()。另见。顺便说一句,你可以直接使用在Windows上编译符合POSIX标准,code 或的,从而避免移植的头痛。

The Windows API function CreateNamedPipe has an option to make the handle non-blocking. (See MSDN). Also see the MSDN article on Synchronous and Overlapped I/O. BTW, you can directly compile POSIX compliant code on Windows using MinGW or Cygwin and thus avoid the headache of porting.

这篇关于有没有办法让在Windows文件描述符非阻塞?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 18:57