日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

网络编程之select

發(fā)布時(shí)間:2025/10/17 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 网络编程之select 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

網(wǎng)絡(luò)編程學(xué)習(xí)模式,有select、poll、epoll等方式,測(cè)試使用三種方式來(lái)測(cè)試網(wǎng)絡(luò)連接。

/*
*?
*?
*/


#ifndef _CCNET_H
#define _CCNET_H

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <unistd.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>


//@file
//@brief 網(wǎng)絡(luò)處理函數(shù)封裝

/**
* @brief 帶超時(shí)(微秒級(jí))的tcp連接函數(shù)
* @param host : 連接主機(jī)名,不能為NULL
* @param port : 連接主機(jī)監(jiān)聽(tīng)端口
* @param timeout : 最大超時(shí)時(shí)間(微妙)的指針,不能為NULL,連接成功timeout將被設(shè)置為剩余的時(shí)間
* @param name : 連接模塊名
* @return -1 連接失敗或超時(shí)
* @return socket 連接成功的socket
*/
int CCConnectO(const char *host, int port, int *timeout, const char *name);

/**
* @brief 帶超時(shí)(微秒級(jí))的socket讀操作
* @param sock : 已連接的socket
* @param buf : 讀入的空間
* @param len : 讀入的最大長(zhǎng)度
* @param timeout : 最大超時(shí)時(shí)間(微妙)的指針,不能為NULL,函數(shù)返回后timeout將被設(shè)置為剩余的時(shí)間
* @param name : 連接模塊名
* @return -1 讀失敗
* @return 實(shí)際讀到的字符數(shù)
*/
int CCReadO(int sock, void *buf, ssize_t len, int *timeout, const char *name);

/**
* @brief 帶超時(shí)(微秒級(jí))的socket讀操作,直到讀到的內(nèi)容中出現(xiàn)了stop串,或者讀到len長(zhǎng)度,或超時(shí)。
* @param sock : 已連接的socket
* @param buf : 讀入的空間
* @param len : 讀入的最大長(zhǎng)度
* @param timeout : 最大超時(shí)時(shí)間(微妙)的指針,不能為NULL,函數(shù)返回后timeout將被設(shè)置為剩余的時(shí)間
* @param name : 連接模塊名
* @param stop : 當(dāng)讀到內(nèi)容中出現(xiàn)stop字串時(shí),停止讀
* @return -1 讀失敗
* @return 實(shí)際讀到的字符數(shù)
*/
int CCReadOS(int sock, void *buf, ssize_t len, int *timeout, const char *name,
const char *stop);

/**
* @brief 帶超時(shí)(微秒級(jí))的socket寫(xiě)操作
* @param sock : 已連接的socket
* @param buf : 要寫(xiě)出的空間
* @param len : 要寫(xiě)出的最大長(zhǎng)度
* @param timeout : 最大超時(shí)時(shí)間(微妙)的指針,不能為NULL,函數(shù)返回后timeout將被設(shè)置為剩余的時(shí)間
* @param name : 連接模塊名
* @return -1 讀失敗
* @return 實(shí)際寫(xiě)出的字符數(shù)
*/
int CCWriteO(int sock, void *buf, ssize_t len, int *timeout,
const char *name);

/**
* @brief 關(guān)閉socket
* @param fd : 已連接的socket
* @return -1 關(guān)閉失敗
* @return 0 成功關(guān)閉
*/
int CCClose(int fd);

/**
* @brief 開(kāi)啟tcp監(jiān)聽(tīng)端口
* @param port : 端口
* @param queue : listen等待隊(duì)列長(zhǎng)度
* @return -1 失敗
* @return 成功返回開(kāi)啟監(jiān)聽(tīng)的fd
*/
int CCTcpListen(const char *host, int port, int queue);

#endif // _CCNET_H
/* vim: create noet: */

轉(zhuǎn)載于:https://www.cnblogs.com/cyblogs/p/11295568.html

總結(jié)

以上是生活随笔為你收集整理的网络编程之select的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。