有没有办法让在Windows文件描述符非阻塞? [英] Is there way to make file descriptor non blocking in windows?

查看:494
本文介绍了有没有办法让在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时有一个选项,使处理无阻塞。 (请参阅MSDN )。另见同步和重叠I MSDN文章/ Ø。顺便说一句,你可以直接使用在Windows上编译符合POSIX标准,code MinGW的或的 Cygwin的,从而避免移植的头痛。

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文件描述符非阻塞?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆