国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PowerShell > 正文

linux下非阻塞模式網絡通訊模型示例分享

2020-05-30 20:10:39
字體:
來源:轉載
供稿:網友

代碼如下:
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <sysexits.h>
#include <time.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <net/if.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#ifdef __ENABLED_DEBUG_INFO_OUTPUT__
    #define DEBUG_OUTPUT(format) printf( "/nFile: %s : Line: %d ->Function: %s/n"format"/n", __BASE_FILE__, __LINE__, __FUNCTION__ )
    #define DEBUG_OUTPUT_PARA(format,...) printf( "/nFile: %s : Line: %d ->Function: %s/n"format"/n", __BASE_FILE__, __LINE__, __FUNCTION__, __VA_ARGS__ )
#else
    #define DEBUG_OUTPUT(format)
    #define DEBUG_OUTPUT_PARA(format,...)
#endif

// @brief 非阻塞等待套接字是否可讀/寫
// @param[in] sockfd 套接字描述符
// @param[in] bWhichSet true - 可讀集; false - 可寫集;
// @param[in] uiTimeOutMS 超時時長(單位:微秒);
// @pre scokfd 有效套接字描述符,即大于等于零(>=0)
// @return 此函數執行結果
// @return  0 - 可以讀/寫;
//         -1 - 參數不合法;
//         -2 - 檢測已超時;
// @note uiTimeOutMS 超時時長,設為零(0),則不等待超時
static inline int
wait_rw_able( int          sockfd,
              bool         bWhichSet,
              unsigned int uiTimeOutMS )
{
    // 默認為檢測已超時
    int iReturnValue = -2;

    // 可讀描述符集
    fd_set rset;
    // 可寫描述符集
    fd_set wset;

    // select 將等待的時間
    timeval tv;

    do // 非循環,只是為了保證函數只有一個返回點
    {
        // 參數不合法
        if ( 0 > sockfd )
        {
            iReturnValue = -1;
            break;
        }

        // 注:每次調用 select 之前都要重設一次!
        tv.tv_sec  = 0;
        tv.tv_usec = uiTimeOutMS;

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 黔西| 依兰县| 潞城市| 武夷山市| 高台县| 杨浦区| 舒兰市| 镇康县| 平陆县| 西和县| 中西区| 河间市| 仪陇县| 略阳县| 齐齐哈尔市| 博客| 治多县| 隆安县| 名山县| 政和县| 临沧市| 邵武市| 旅游| 华安县| 新泰市| 龙门县| 河东区| 江门市| 乐清市| 天全县| 郴州市| 綦江县| 习水县| 新乡县| 四平市| 荥阳市| 芦山县| 离岛区| 呼图壁县| 红河县| 六枝特区|