zjnig711的信息仓库

程序的天空

code to solve "SOCK_NONBLOCK" and "O_NONBLOCK" undefined problem in linux

#if defined(SOCK_NONBLOCK)
        return ::socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, IPPROTO_TCP);

        /* If they have O_NONBLOCK, use the Posix way to do it */
#elif defined(O_NONBLOCK)
        /* Fixme: O_NONBLOCK is defined but broken on SunOS 4.1.x and AIX 3.2.5. */
        int sock = socket(PF_INET, SOCK_STREAM, 0);
        int flags;

        if (-1 == (flags = fcntl(sock, F_GETFL, 0)))
                flags = 0;

        fcntl(sock, F_SETFL, flags | O_NONBLOCK);

        return sock;

#else
        int sock = socket(PF_INET, SOCK_STREAM, 0);
        /* Otherwise, use the old way of doing it */
        int flags = 1;
        ioctl(sock, FIOBIO, &flags);

        return sock;

#endif

阅读更多
个人分类: Lunix 编程 C/C++
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭