亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? sock.c

?? 開發(fā)板bios源碼 開發(fā)板bios源碼
?? C
?? 第 1 頁 / 共 2 頁
字號:
/*
 * sock.c -- Posix Socket upper layer support module for general posix use
 *
 * Copyright (c) GoAhead Software Inc., 1995-2000. All Rights Reserved.
 *
 * $Id: sock.c,v 1.2 2001/12/06 16:28:24 bporter Exp $
 */

/******************************** Description *********************************/

/*
 *	Posix Socket Module.  This supports blocking and non-blocking buffered 
 *	socket I/O.
 */

/********************************** Includes **********************************/

#include	<string.h>
#include	<stdlib.h>

#ifdef UEMF
	#include	"uemf.h"
#else
	#include	<socket.h>
	#include	<types.h>
	#include	<unistd.h>
	#include	"emfInternal.h"
#endif

/************************************ Locals **********************************/

socket_t	**socketList;			/* List of open sockets */
int			socketMax;				/* Maximum size of socket */
int			socketHighestFd = -1;	/* Highest socket fd opened */

/***************************** Forward Declarations ***************************/

static int	socketDoOutput(socket_t *sp, char *buf, int toWrite, int *errCode);
static int	tryAlternateSendTo(int sock, char *buf, int toWrite, int i,
			struct sockaddr *server);

/*********************************** Code *************************************/
/*
 *	Write to a socket. Absorb as much data as the socket can buffer. Block if 
 *	the socket is in blocking mode. Returns -1 on error, otherwise the number 
 *	of bytes written.
 */

int	socketWrite(int sid, char *buf, int bufsize)
{
	socket_t	*sp;
	ringq_t		*rq;
	int			len, bytesWritten, room;

	a_assert(buf);
	a_assert(bufsize >= 0);

	if ((sp = socketPtr(sid)) == NULL) {
		return -1;
	}

/*
 *	Loop adding as much data to the output ringq as we can absorb. Initiate a 
 *	flush when the ringq is too full and continue. Block in socketFlush if the
 *	socket is in blocking mode.
 */
	rq = &sp->outBuf;
	for (bytesWritten = 0; bufsize > 0; ) {
		if ((room = ringqPutBlkMax(rq)) == 0) {
			if (socketFlush(sid) < 0) {
				return -1;
			}
			if ((room = ringqPutBlkMax(rq)) == 0) {
				if (sp->flags & SOCKET_BLOCK) {
#if (defined (WIN) || defined (CE))
					int		errCode;
					if (! socketWaitForEvent(sp,  FD_WRITE | SOCKET_WRITABLE,
						&errCode)) {
						return -1;
					}
#endif
					continue;
				}
				break;
			}
			continue;
		}
		len = min(room, bufsize);
		ringqPutBlk(rq, (unsigned char *) buf, len);
		bytesWritten += len;
		bufsize -= len;
		buf += len;
	}
	return bytesWritten;
}

/******************************************************************************/
/*
 *	Write a string to a socket
 */

int	socketWriteString(int sid, char_t *buf)
{
 #ifdef UNICODE
 	char	*byteBuf;
 	int		r, len;
 
 	len = gstrlen(buf);
 	byteBuf = ballocUniToAsc(buf, len);
 	r = socketWrite(sid, byteBuf, len);
 	bfreeSafe(B_L, byteBuf);
 	return r;
 #else
 	return socketWrite(sid, buf, strlen(buf));
 #endif /* UNICODE */
}

/******************************************************************************/
/*
 *	Read from a socket. Return the number of bytes read if successful. This
 *	may be less than the requested "bufsize" and may be zero. Return -1 for
 *	errors. Return 0 for EOF. Otherwise return the number of bytes read. 
 *	If this routine returns zero it indicates an EOF condition.
 *  which can be verified with socketEof()
 
 *	Note: this ignores the line buffer, so a previous socketGets
 *	which read a partial line may cause a subsequent socketRead to miss some 
 *	data. This routine may block if the socket is in blocking mode.
 *
 */

int	socketRead(int sid, char *buf, int bufsize)
{
	socket_t	*sp;
	ringq_t		*rq;
	int			len, room, errCode, bytesRead;

	a_assert(buf);
	a_assert(bufsize > 0);

	if ((sp = socketPtr(sid)) == NULL) {
		return -1;
	}

	if (sp->flags & SOCKET_EOF) {
		return 0;
	}

	rq = &sp->inBuf;
	for (bytesRead = 0; bufsize > 0; ) {
		len = min(ringqLen(rq), bufsize);
		if (len <= 0) {
/*
 *			if blocking mode and already have data, exit now or it may block
 *			forever.
 */
			if ((sp->flags & SOCKET_BLOCK) &&
				(bytesRead > 0)) {
				break;
			}
/*
 *			This flush is critical for readers of datagram packets. If the
 *			buffer is not big enough to read the whole datagram in one hit,
 *			the recvfrom call will fail. 
 */
			ringqFlush(rq);
			room = ringqPutBlkMax(rq);
			len = socketGetInput(sid, (char *) rq->endp, room, &errCode);
			if (len < 0) {
				if (errCode == EWOULDBLOCK) {
					if ((sp->flags & SOCKET_BLOCK) &&
						(bytesRead ==  0)) {
						continue;
					}
					if (bytesRead >= 0) {
						return bytesRead;
					}
				}
				return -1;

			} else if (len == 0) {
/*
 *				If bytesRead is 0, this is EOF since socketRead should never
 *				be called unless there is data yet to be read.  Set the flag.  
 *				Then pass back the number of bytes read.
 */
				if (bytesRead == 0) {
					sp->flags |= SOCKET_EOF;
				}
				return bytesRead;
			}
			ringqPutBlkAdj(rq, len);
			len = min(len, bufsize);
		}
		memcpy(&buf[bytesRead], rq->servp, len);
		ringqGetBlkAdj(rq, len);
		bufsize -= len;
		bytesRead += len;
	}
	return bytesRead;
}

/******************************************************************************/
/*
 *	Get a string from a socket. This returns data in *buf in a malloced string
 *	after trimming the '\n'. If there is zero bytes returned, *buf will be set
 *	to NULL. If doing non-blocking I/O, it returns -1 for error, EOF or when 
 *	no complete line yet read. If doing blocking I/O, it will block until an
 *	entire line is read. If a partial line is read socketInputBuffered or 
 *	socketEof can be used to distinguish between EOF and partial line still 
 *	buffered. This routine eats and ignores carriage returns.
 */

int	socketGets(int sid, char_t **buf)
{
	socket_t	*sp;
	ringq_t		*lq;
	char		c;
	int			rc, len;

	a_assert(buf);
	*buf = NULL;

	if ((sp = socketPtr(sid)) == NULL) {
		return -1;
	}
	lq = &sp->lineBuf;

	while (1) {

		if ((rc = socketRead(sid, &c, 1)) < 0) {
			return rc;
		}
		
		if (rc == 0) {
/*
 *			If there is a partial line and we are at EOF, pretend we saw a '\n'
 */
			if (ringqLen(lq) > 0 && (sp->flags & SOCKET_EOF)) {
				c = '\n';
			} else {
				return -1;
			}
		}
/*
 *		If a newline is seen, return the data excluding the new line to the
 *		caller. If carriage return is seen, just eat it.
 */
		if (c == '\n') {
			len = ringqLen(lq);
			if (len > 0) {
				*buf = ballocAscToUni((char *)lq->servp, len);
			} else {
				*buf = NULL;
			}
			ringqFlush(lq);
			return len;

		} else if (c == '\r') {
			continue;
		}
		ringqPutcA(lq, c);
	}
	return 0;
}

/******************************************************************************/
/*
 *	Flush the socket. Block if the socket is in blocking mode.
 *	This will return -1 on errors and 0 if successful.
 */

int socketFlush(int sid)
{
	socket_t	*sp;
	ringq_t		*rq;
	int			len, bytesWritten, errCode;

	if ((sp = socketPtr(sid)) == NULL) {
		return -1;
	}
	rq = &sp->outBuf;

/*
 *	Set the background flushing flag which socketEventProc will check to
 *	continue the flush.
 */
	if (! (sp->flags & SOCKET_BLOCK)) {
		sp->flags |= SOCKET_FLUSHING;
	}

/*
 *	Break from loop if not blocking after initiating output. If we are blocking
 *	we wait for a write event.
 */
	while (ringqLen(rq) > 0) {
		len = ringqGetBlkMax(&sp->outBuf);
		bytesWritten = socketDoOutput(sp, (char*) rq->servp, len, &errCode);
		if (bytesWritten < 0) {
			if (errCode == EINTR) {
				continue;
			} else if (errCode == EWOULDBLOCK || errCode == EAGAIN) {
#if (defined (WIN) || defined (CE))
				if (sp->flags & SOCKET_BLOCK) {
					int		errCode;
					if (! socketWaitForEvent(sp,  FD_WRITE | SOCKET_WRITABLE,
						&errCode)) {
						return -1;
					}
					continue;
				} 
#endif
/*
 *				Ensure we get a FD_WRITE message when the socket can absorb
 *				more data (non-blocking only.) Store the user's mask if we
 *				haven't done it already.
 */
				if (sp->saveMask < 0 ) {
					sp->saveMask = sp->handlerMask;
					socketRegisterInterest(sp, 
					sp->handlerMask | SOCKET_WRITABLE);
				}
				return 0;
			}
			return -1;
		}
		ringqGetBlkAdj(rq, bytesWritten);
	}
/*
 *	If the buffer is empty, reset the ringq pointers to point to the start
 *	of the buffer. This is essential to ensure that datagrams get written
 *	in one single I/O operation.
 */
	if (ringqLen(rq) == 0) {
		ringqFlush(rq);
	}
/*
 *	Restore the users mask if it was saved by the non-blocking code above.
 *	Note: saveMask = -1 if empty. socketRegisterInterest will set handlerMask
 */
	if (sp->saveMask >= 0) {
		socketRegisterInterest(sp, sp->saveMask);
		sp->saveMask = -1;
	}
	sp->flags &= ~SOCKET_FLUSHING;
	return 0;
}

/******************************************************************************/
/*
 *	Return the count of input characters buffered. We look at both the line
 *	buffer and the input (raw) buffer. Return -1 on error or EOF.
 */

int socketInputBuffered(int sid)
{
	socket_t	*sp;

	if ((sp = socketPtr(sid)) == NULL) {
		return -1;
	}
	if (socketEof(sid)) {
		return -1;
	}
	return ringqLen(&sp->lineBuf) + ringqLen(&sp->inBuf);
}

/******************************************************************************/
/*
 *	Return true if EOF
 */

int socketEof(int sid)
{
	socket_t	*sp;

	if ((sp = socketPtr(sid)) == NULL) {
		return -1;
	}
	return sp->flags & SOCKET_EOF;
}

/******************************************************************************/
/*
 *	Return the number of bytes the socket can absorb without blocking
 */

int socketCanWrite(int sid)
{
	socket_t	*sp;

	if ((sp = socketPtr(sid)) == NULL) {
		return -1;
	}
	return sp->outBuf.buflen - ringqLen(&sp->outBuf) - 1;
}

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产精品久久免费看| 日韩亚洲欧美高清| 亚洲色图色小说| 波多野结衣欧美| 亚洲乱码中文字幕| 在线看国产日韩| 亚洲午夜久久久久久久久电影院 | 在线影视一区二区三区| 一区二区三区在线视频播放| 欧美麻豆精品久久久久久| 日本不卡免费在线视频| 久久久久久久久一| 91免费观看在线| 日韩电影免费在线| 国产欧美一区二区三区在线看蜜臀 | 日韩精品专区在线影院重磅| 国产不卡视频在线观看| 亚洲女人小视频在线观看| 欧美日本一区二区在线观看| 国产精品资源在线看| 亚洲精品日日夜夜| 精品91自产拍在线观看一区| a亚洲天堂av| 日韩电影免费在线看| 国产精品网站在线观看| 欧美特级限制片免费在线观看| 久久国产精品露脸对白| 国产精品久久久久aaaa樱花 | 精品播放一区二区| 日本韩国一区二区三区视频| 麻豆精品在线视频| 亚洲视频一区在线| 欧美成人猛片aaaaaaa| 色一区在线观看| 国内精品免费在线观看| 一区二区三区欧美亚洲| 久久久久久久精| 欧美日韩和欧美的一区二区| 国产伦精品一区二区三区视频青涩 | 精品国内二区三区| 日本韩国视频一区二区| 国模无码大尺度一区二区三区| 精品在线观看视频| 亚洲一区二区在线播放相泽| 久久精品视频免费| 91精品免费在线| 色综合天天视频在线观看| 国产伦理精品不卡| 美女一区二区视频| 亚洲综合图片区| 国产精品成人免费| 久久精品亚洲一区二区三区浴池| 欧美二区在线观看| 欧美亚洲动漫制服丝袜| 不卡一区二区中文字幕| 国产九九视频一区二区三区| 日日夜夜精品视频天天综合网| 亚洲另类在线制服丝袜| 国产精品欧美久久久久一区二区| 2021久久国产精品不只是精品| 欧美精品一卡两卡| 欧美日韩久久一区二区| 色婷婷av一区二区三区软件 | 免费国产亚洲视频| 亚洲一区二区三区国产| 亚洲视频一区二区在线| 中文字幕精品—区二区四季| 久久久综合九色合综国产精品| 欧美一区二区高清| 欧美日韩国产精选| 欧美日韩免费不卡视频一区二区三区| 91麻豆免费观看| 91在线国内视频| av电影在线观看完整版一区二区| 国产成人在线视频播放| 国产综合久久久久久鬼色| 久久69国产一区二区蜜臀| 麻豆精品一区二区三区| 视频一区免费在线观看| 亚洲成人一区在线| 午夜a成v人精品| 日日欢夜夜爽一区| 秋霞电影网一区二区| 久久99国产精品免费| 国产一区二区成人久久免费影院| 国产美女视频一区| 粉嫩蜜臀av国产精品网站| 成人国产亚洲欧美成人综合网| 99综合电影在线视频| 色婷婷av一区二区三区大白胸| 91成人看片片| 欧美一区二区美女| 精品国产91九色蝌蚪| 欧美国产日韩精品免费观看| 国产精品国产三级国产专播品爱网 | 亚洲欧美国产77777| 亚洲一区二区av在线| 日韩国产成人精品| 国产一区二区伦理片| 成人动漫中文字幕| 欧美午夜精品久久久| 欧美一区二区三区视频在线观看| 欧美大黄免费观看| 欧美国产丝袜视频| 亚洲精品自拍动漫在线| 日韩激情一区二区| 国产一区二区网址| 成人av资源在线观看| 欧美日韩黄色一区二区| 2024国产精品视频| 亚洲日本va午夜在线电影| 午夜一区二区三区在线观看| 国产一区二区三区在线观看精品| 99久久久久久99| 欧美一区二区三区婷婷月色| 中文字幕二三区不卡| 午夜精品福利一区二区三区av| 精品在线播放免费| 在线观看日产精品| 久久久亚洲午夜电影| 亚洲国产日韩一级| 国产91综合一区在线观看| 欧美人妇做爰xxxⅹ性高电影| 国产亚洲精品aa午夜观看| 一区二区三区日韩精品视频| 国产九九视频一区二区三区| 欧美在线免费播放| 国产人伦精品一区二区| 首页国产欧美久久| 99精品视频一区二区三区| 日韩精品一区二区三区视频在线观看| 亚洲婷婷综合久久一本伊一区| 久久精品国产亚洲高清剧情介绍| 色美美综合视频| 久久精品亚洲乱码伦伦中文 | 91麻豆精品国产91久久久久久| 国产精品毛片大码女人| 久久99精品一区二区三区| 欧美亚洲丝袜传媒另类| 国产精品国产三级国产有无不卡| 久久精品二区亚洲w码| 在线亚洲一区观看| 中文字幕精品—区二区四季| 久久超碰97中文字幕| 欧美精品一二三| 一区二区三区 在线观看视频| 粉嫩av一区二区三区| 欧美一区二区在线免费观看| 亚洲在线一区二区三区| 99久久精品国产一区| 久久精品视频免费| 黄色精品一二区| 欧美zozo另类异族| 老司机精品视频导航| 日韩一区二区在线看片| 午夜在线成人av| 欧美日韩国产不卡| 亚洲一区二区美女| 欧美中文字幕亚洲一区二区va在线| 中文字幕在线视频一区| 成人动漫一区二区三区| 亚洲国产精品av| 白白色 亚洲乱淫| 国产精品久久久久久久久久久免费看 | 亚洲欧洲精品一区二区三区| 国产91精品一区二区麻豆亚洲| 精品国产免费人成在线观看| 久久超碰97人人做人人爱| 精品日产卡一卡二卡麻豆| 另类欧美日韩国产在线| 精品国产乱码久久久久久蜜臀 | 国产精品99久久久久久有的能看| 精品福利一二区| 国产精品1024久久| 国产情人综合久久777777| 成人性生交大片免费看中文| 国产精品乱码人人做人人爱| 91首页免费视频| 亚洲福利一区二区| 91精品国产色综合久久ai换脸 | 制服丝袜在线91| 久久机这里只有精品| www国产成人| eeuss鲁片一区二区三区 | 日韩va欧美va亚洲va久久| 日韩一区二区精品在线观看| 黄色成人免费在线| 日本一区二区不卡视频| 色天天综合色天天久久| 日日摸夜夜添夜夜添国产精品| 精品国产乱码久久久久久浪潮| 国产一区999| 一区二区三区资源| 91精品国产色综合久久不卡蜜臀| 国产精品一区免费在线观看| 亚洲日本电影在线| 制服丝袜亚洲网站| 成人午夜激情影院| 亚洲成国产人片在线观看| 精品国产乱码久久久久久1区2区|