示例#1
0
int InitSocketStruct(struct tmsxx_app **pss, int fd)
{

	*pss = (struct tmsxx_app *)malloc( sizeof(struct tmsxx_app));
	if (*pss == 0) {
		perror("malloc struct tmsxx_app");
		// exit(1);
		return -1;
	}
	bzero(*pss, sizeof(struct tmsxx_app));

	// ((struct tmsxx_app*)pnode->ptr)->context.fd = pnode->sockfd;
	(**pss).context.fd = fd;
	(**pss).context.ptcb = &tcb;


	bipbuffer_Init(&(*pss)->bb);
	//bipbuffer_AllocateBuffer(&(*pss)->bb,1024*2);
	bipbuffer_AllocateBuffer(&(*pss)->bb, BIPBUFFER_LEN);
	(*pss)->morebyte = 400;

#ifdef CONFIG_TEST_NET_STRONG
	(**pss).context.net_pack_id = 10;
#endif
	return 0;
}
示例#2
0
int InitSocketStruct(struct tmsxx_app **pss, int fd)
{

	*pss = (struct tmsxx_app*)malloc( sizeof(struct tmsxx_app));
	if (*pss == 0) {
		perror("malloc struct tmsxx_app");
		// exit(1);
		return -1;
	}
	memset(*pss, 0, sizeof(struct tmsxx_app));

	// ((struct tmsxx_app*)pnode->ptr)->context.fd = pnode->sockfd;
	(**pss).context.fd = fd;
	(**pss).context.ptcb = &tcb;


	bipbuffer_Init(&(*pss)->bb);
	//bipbuffer_AllocateBuffer(&(*pss)->bb,1024*2);
	bipbuffer_AllocateBuffer(&(*pss)->bb,BIPBUFFER_LEN);
	(*pss)->morebyte = 400;
	
}
示例#3
0
int epFUI_OnRecv(struct ep_t *pep, struct ep_con_t *pnode)
{
	// static int rtimes = 0;
	// printf("\r--------!!!!!! OnRecv !!!!! --------%8.8x\r",rtimes++);
	int ret;
	char rbuf[100];
	struct tmsxx_app *pss;


	

	int32_t retRecv,retFramelen,recvTotal;
	int32_t reserved;
	char *pdata;

	
	if (pnode->ptr == NULL) {
		printf("wait \n");
		sleep(1);
		return 1;
	}
	pss = (struct tmsxx_app *)pnode->ptr;
	//pss->morebyte = 100;
	if (pss->enable_lbb == 0) {
		pdata = bipbuffer_Reserve(&pss->bb,pss->morebyte,&reserved);	
	}
	else {
		printf("bipbuffer_Reserve lbb  ");
		pdata = bipbuffer_Reserve(&pss->lbb,pss->lbyte,&reserved);
		int size;
		bipbuffer_GetContiguousBlock(&pss->lbb,&size);
		printf("size %d\n",size);
	}


	// sleep(1);
	if (pdata == NULL) {
		retRecv = 1;//无用,必须大于0
	}
	// 固定环形缓存
	else if (pss->enable_lbb == 0) {
		// printf("want to recv %d\n",reserved);
		retRecv = recv(pnode->sockfd, pdata, reserved, 0);	
		// printf("this times recv %d\n",retRecv);
		bipbuffer_Commit(&pss->bb,retRecv);
	}
	// 大型环形缓存,只够存储一帧数据,填满缓存前不找合法帧,
	// 填满后无论是否找到合法帧均释放
	else {
		retRecv = recv(pnode->sockfd, pdata, reserved, 0);	
		bipbuffer_Commit(&pss->lbb,retRecv);
		pss->lbyte -= retRecv;


		if (pss->enable_lbb == 1 && pss->lbyte > 0) {
			return retRecv;
		}
		else {
			struct bipbuffer tbb;
			tbb      = pss->lbb;
			pss->lbb = pss->bb;
			pss->bb  = tbb;
		}
	}
	//bipbuffer_PrintMemory(&pss->bb);

_Again:;
	pdata = bipbuffer_GetContiguousBlock(&pss->bb, &recvTotal);
	if (bipbuffer_GetUsedSize(&pss->bb) >= 40 && recvTotal < 40) {
		int unuse;
		bipbuffer_GetUnContiguousBlock(&pss->bb, &unuse);
	}
	if (recvTotal >= 40) {
		ret = glink_FindFrame((int8_t*)pdata, &recvTotal, &retFramelen);	
	}
	else {
		ret = -6;
		retFramelen = 0;
	}
	
	// printf("ret %d retRecv %d %recvTotal %d retFramelen %d\n",
	// 	ret,retRecv,recvTotal,retFramelen);
	if (ret == 0) {
		
		bipbuffer_DecommitBlock(&pss->bb, retFramelen);
		
		// tms_Analyse(pnode->sockfd, (int8_t*)pdata, retFramelen);
		tms_Analyse(    &(((struct tmsxx_app*)(pnode->ptr))->context), 
						(int8_t*)pdata, 
						retFramelen);

		pss->morebyte = 40;
		if (pss->enable_lbb == 0) {
			goto _Again;
		}
		//if (reserved > 0) {
			
		//}
	}
	else if (ret == -2) {
		// printf("frame err Decommit %d %d\n",retFramelen,reserved);
		bipbuffer_DecommitBlock(&pss->bb, retFramelen);
		

		pss->morebyte = 40;
		//if (reserved > 0) {
			goto _Again;
		//}
	}
	else if (ret == -3) {
		// printf("recvTotal %d retFramelen %d used %d\n",recvTotal,retFramelen,bipbuffer_GetUsedSize(&pss->bb));
		if (recvTotal + retFramelen <= bipbuffer_GetUsedSize(&pss->bb)) {
			int unuse;
			bipbuffer_GetUnContiguousBlock(&pss->bb, &unuse);
		}
		pss->morebyte = 40;//retFramelen;
		bipbuffer_GetContiguousBlock(&pss->bb, &reserved);
		// printf("after copy recvTotal %d reserved %d retFramelen %d\n",
		// 	recvTotal,reserved,retFramelen);
		bipbuffer_PrintMemory(&pss->bb);
		if (reserved >=  recvTotal + retFramelen) {
			goto _Again;
		}

		if (retFramelen + recvTotal > BIPBUFFER_LEN) {
			// 初始化大块临时缓存
			printf("large bipbuffer\n");
			char *pbb_buf,*plbb_buf;
			int pbb_len,plbb_unuselen;

			pss->lbyte = recvTotal + retFramelen;
			bipbuffer_Init(&pss->lbb);
			bipbuffer_AllocateBuffer(&pss->lbb,pss->lbyte);


			pbb_buf = bipbuffer_GetContiguousBlock(&pss->bb, &pbb_len);
			//plbb_buf = bipbuffer_GetContiguousBlock(&pss->lbb, &plbb_unuselen);
			plbb_buf = bipbuffer_Reserve(&pss->lbb, pbb_len, &plbb_unuselen);
			memcpy(plbb_buf, pbb_buf, pbb_len);

			bipbuffer_Commit(&pss->lbb, pbb_len);
			bipbuffer_DecommitBlock(&pss->bb, pbb_len);
			pss->lbyte -= pbb_len;
			pss->enable_lbb = 1;
		}
	

	}
	

	if (pss->enable_lbb == 1 && pss->lbyte <= 0) {
		printf("free....\n");
		struct bipbuffer tbb;

		pss->enable_lbb = 0;
		tbb      = pss->lbb;
		pss->lbb = pss->bb;
		pss->bb  = tbb;

		bipbuffer_FreeBuffer(&pss->lbb);
		
	}
	return retRecv;


	// ret = recv(pnode->sockfd, rbuf, sizeof(rbuf), 0);
	// // printf("recv data %s",rbuf);
	// // 返回值必须是recv函数的返回值
	// return ret;
}