#include#include#include#include#include#include#defineERR_EXIT(m)\do{\perror(m);\exit(EXIT_FAILURE);\}while(0)voidactivate_nonblock(intfd);voiddeact" />

日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

用fcntl()設置堵塞函數的堵塞性質

系統 2183 0
      #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

#define ERR_EXIT(m) \
    do { \
        perror(m);\
        exit(EXIT_FAILURE);\
    }while(0)

void activate_nonblock(int fd);
void deactivate_nonblock(int fd);

int main(int argc, const char *argv[])
{
    activate_nonblock(STDIN_FILENO);
    char buffer[1024] = {0};
    int ret = read(STDIN_FILENO, buffer, 1024);
    if(ret == -1)
        printf("read");
    return 0;
}

void activate_nonblock(int fd)
{
    int ret;
    int flags = fcntl(fd, F_GETFL);
    if(flags == -1)
        ERR_EXIT("fcntl");
    flags |= O_NONBLOCK;
    ret = fcntl(fd, F_SETFL, flags);
    if(ret == -1)
        ERR_EXIT("fcntl");
}

void deactivate_nonblock(int fd)
{
    int ret;
    int flags = fcntl(fd, F_GETFL);
    if(flags == -1)
        ERR_EXIT("fcntl");
    flags &=~O_NONBLOCK;
    ret = fcntl(fd, F_SETFL, flags);
    if(ret == -1)
        ERR_EXIT("fcntl");
}
    

用fcntl()設置堵塞函數的堵塞性質


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 中超| 东丰县| 会泽县| 柯坪县| 辽中县| 宜黄县| 乐业县| 麻栗坡县| 徐州市| 长白| 达日县| 富顺县| 安宁市| 厦门市| 乳山市| 五家渠市| 长顺县| 民和| 剑河县| 宝清县| 蓬安县| 彰化县| 休宁县| 焦作市| 集贤县| 霍林郭勒市| 灵石县| 郓城县| 十堰市| 新田县| 洛川县| 广河县| 阿图什市| 镇安县| 乐亭县| 沙湾县| 鄂温| 万盛区| 沂南县| 临夏县| 诏安县|