⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 swait.c

📁 项目描述: slsnif is a serial port logging utility. It listens to the specified serial port and logs all
💻 C
字号:
/* Swait.c: this file contains code which allows one to wait until data *  is present at the Socket (this will block) * *  Returns: number of bytes of data awaiting perusal *	         or EOF if unable to "select" the socket */#include <stdio.h>#define SSLNEEDTIME#include "sockets.h"/* --------------------------------------------------------------------- * Source Code: */#ifdef __PROTOTYPE__int Swait(Socket *skt)#elseint Swait(skt)Socket *skt;#endif{static char buf[PM_BIGBUF];short       result;int         ret;fd_set      emask;fd_set      rmask;fd_set      wmask;/* sanity check */if(!skt) {	return -1;	}FD_ZERO(&rmask);FD_SET(skt->skt,&rmask);FD_ZERO(&wmask);FD_ZERO(&emask);/* test if something is available for reading on the socket.  This form * will block (sleep) until something arrives */#ifdef SSLNOPEEKresult = select(skt->skt+1,rmask.fds_bits,wmask.fds_bits,emask.fds_bits,         (struct timeval *) NULL);#elseresult = select(skt->skt+1, &rmask,&wmask,&emask, (struct timeval *) NULL);#endifif(result < 0) {	return EOF;	}/* server sockets return the select result */if(skt->type == PM_SERVER) {	return result;	}#ifdef SSLNOPEEKreturn 1;#else /* #ifdef SSLNOPEEK ... #else ... #endif *//* wait if message available from socket, return qty bytes avail */if(FD_ISSET(skt->skt,&rmask)) {	ret= recv(skt->skt,buf,PM_BIGBUF-1,MSG_PEEK);	if(result == 1 && ret == 0) ret= EOF;	return ret;	}/* socket is empty */return 0;#endif /* #ifdef SSLNOPEEK ... #else ... #endif */}/* --------------------------------------------------------------------- * vim: ts=4 */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -