readline.c

来自「一个很好的unix网络编程框架」· C语言 代码 · 共 41 行

C
41
字号
#include "../etcp.h"/* readline - read a newline terminated record */int readline( SOCKET fd, char *bufptr, size_t len ){	char *bufx = bufptr;	static char *bp;	static int cnt = 0;	static char b[ 1500 ];	char c;	while ( --len > 0 )	{		if ( --cnt <= 0 )		{			cnt = recv( fd, b, sizeof( b ), 0 );			if ( cnt < 0 )			{				if ( errno == EINTR )				{					len++;		/* the while will decrement */					continue;				}				return -1;			}			if ( cnt == 0 )				return 0;			bp = b;		}		c = *bp++;		*bufptr++ = c;		if ( c == '\n' )		{			*bufptr = '\0';			return bufptr - bufx;		}	}	set_errno( EMSGSIZE );	return -1;}

⌨️ 快捷键说明

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