#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;
// 检测是否可读
if ( true == bWhichSet )
{
// 清除其所有位
FD_ZERO( &rset );
// 设置关心的描述符
FD_SET( sockfd, &rset );
// 大于零(0) - 有套接字可读,零(0) - 没有,负数 - 出错
if ( 0 < select( sockfd + 1, // 从描述符零(0)开始搜索,故此要对套接字描述符加壹(1)
&rset, // 可读描述符集
NULL, // 可写描述符集
NULL, // 异常描述符集
&tv ) ) // 等待时间
{
// 可读描述符是我们的套接字
if ( FD_ISSET( sockfd, &rset ) )
{
iReturnValue = 0;
break;
}
}
}
// 检测是否可写
else
{
// 清除其所有位
FD_ZERO( &wset );
// 设置关心的描述符
FD_SET( sockfd, &wset );
// 大于零(0) - 有套接字可读,零(0) - 没有,负数 - 出错
if ( 0 < select( sockfd + 1, // 从描述符零(0)开始搜索,故此要对套接字描述符加壹(1)
NULL, // 可读描述符集
&wset, // 可写描述符集
NULL, // 异常描述符集
&tv ) ) // 等待时间
{
// 可读描述符是我们的套接字
if ( FD_ISSET( sockfd,
&wset ) )

