关闭

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

标签: streamsocketaixlinuxtcp
2005人阅读 评论(0) 收藏 举报
分类:

#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

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:246735次
    • 积分:2952
    • 等级:
    • 排名:第11897名
    • 原创:33篇
    • 转载:157篇
    • 译文:0篇
    • 评论:24条
    最新评论
    个人主页