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

📄 sv_tcp.c

📁 站长96年写的一个Internet上用的股票行情、分析、交易、资讯程序源码
💻 C
📖 第 1 页 / 共 5 页
字号:
	if(fFirstTime)	{		if(UDP_Server_Send_Hq00(sd, jys, lpdest)<0)			return 0;	}	fRefresh =*lpTmp++;	fSel =*lpTmp++;	recCount =*(short *)lpTmp;	if(recCount <=0 || recCount >MAX_PARA_COUNT) 		return -1;	lpTmp +=2;		SendBuff =GlobalAllocPtr(GHND,strlen(HQ01_HEAD)+7+		(2+sizeof(HQ_PRE_DATA)+sizeof(HQ_REF_DATA))*recCount);	if(SendBuff ==NULL)		return -1;	strcpy(SendBuff, HQ01_HEAD); 	len =strlen(HQ01_HEAD)+sizeof(short);	//2	SendBuff[len++] =(BYTE)jys;				//1	SendBuff[len++] =(BYTE)fRefresh;		//1	SendBuff[len++] =(BYTE)fSel;			//1	len1 =len;	*(short *)&SendBuff[len] =0;	len +=sizeof(short);					//2		memset(recList, 0, sizeof(short)*MAX_PARA_COUNT);	recList[0] =recCount;	if(!fSel)	{		recNum =*(short *)lpTmp;		if(recNum >=HqData[jys].recCount)		{			ErrMsg(ghWndMain,"来自Send_Hq01:记录编号大于行情总数");			goto exit_send;		}		if(recNum <0)		{			ErrMsg(ghWndMain,"来自Send_Hq01:记录编号小于零");			goto exit_send;		}		lpTmp+=2;		//最大编号错		if(recNum +recCount-1 >=HqData[jys].recCount)		{			recCount =HqData[jys].recCount -recNum;			recList[0] =recCount;		}		for(i =0; i<recCount; i++)			recList[i+1] =recNum+i;	}	else            	{		memcpy(&recList[1], lpTmp, sizeof(short)*recCount);		lpTmp +=sizeof(short)*recCount;	}		sendCount1 =0;	sendCount =recCount;	recNum =0;	for(j =0; j<sendCount; j++)	{		sendNum =recList[1+j];		if(sendNum <0 || sendNum >=HqData[jys].recCount)		{			ErrMsg(ghWndMain,"来自Send_Hq01:列表参数错");			goto exit_send;		}		if(!fRefresh)		{			*(short *)&SendBuff[len] =sendNum;			len+=2;			memcpy(&SendBuff[len], &HqData[jys].lpPreData[sendNum],				sizeof(HQ_PRE_DATA));			len +=sizeof(HQ_PRE_DATA);			memcpy(&SendBuff[len], &HqData[jys].lpRefData[sendNum],				sizeof(HQ_REF_DATA));			len +=sizeof(HQ_REF_DATA);			sendCount1++;		}		else		{			if(HqData[jys].lpRefData[sendNum].cjss !=*(int *)lpTmp)			{				*(short *)&SendBuff[len] =sendNum;				len+=2;				memcpy(&SendBuff[len], &HqData[jys].lpRefData[sendNum],					sizeof(HQ_REF_DATA));				len +=sizeof(HQ_REF_DATA);				sendCount1++;			}		}	}	if(sendCount1>0)	{		*(short *)&SendBuff[len1] =sendCount1;		*(short *)&SendBuff[strlen(HQ01_HEAD)] =len;		if(SendMemData(sd,SendBuff,len)<0)			goto exit_send;	}	CheckDest(sd, lpdest, jys, REQ_HQ10, recList, (short)(recCount+1),client_version);			if(fFirstTime)		UDP_Server_Send_Dp(sd, lpdest, TRUE, NULL);exit_send:	GlobalFreePtr(SendBuff);	return j;}int Send_Hq10(LPDEST_INFO lpDest){	char * SendBuff;	short recFirst =0, recCount =0,sendNum,sendCount1;	int j, len =0, len1;	int jys =lpDest->curJys;	if(lpDest->paramsCount <=1)	{		UnlockDest(lpDest);		return -1;	}	if(lpDest->params[0]+lpDest->params[1]-1>=HqData[lpDest->curJys].recCount)	{		UnlockDest(lpDest);		return 0;	}	if(lpDest->params[0]==0) 	{		UnlockDest(lpDest);		return 0;	}	recCount =lpDest->params[0];	SendBuff =GlobalAllocPtr(GHND,		strlen(HQ10_HEAD)+5+(2+sizeof(HQ_REF_DATA))*recCount);	strcpy(SendBuff, HQ10_HEAD);	len =strlen(HQ10_HEAD)+sizeof(short);	//2	SendBuff[len++] =(char)lpDest->curJys;	//1	*(short *)&SendBuff[len] =0;	len1 =len;	len +=sizeof(short);					//2	sendCount1 =0;	for(j =0; j<recCount; j++)	{		sendNum =lpDest->params[1+j];		if(HqData[jys].lpRefData[sendNum].cjss				!=lpDest->lpCjss[j])		{			*(short *)&SendBuff[len] =sendNum;			len+=2;									//2			memcpy(&SendBuff[len], &HqData[jys].lpRefData[sendNum],				sizeof(HQ_REF_DATA));			len +=sizeof(HQ_REF_DATA);				//sizeof(HQ_REF_DATA)			lpDest->lpCjss[j] =HqData[jys].lpRefData[sendNum].cjss;			sendCount1++;		}	}	UnlockDest(lpDest);	if(sendCount1)	{		*(short *)&SendBuff[len1] =sendCount1;		*(short *)&SendBuff[strlen(HQ10_HEAD)] =len;		SendMemData(lpDest->sd, SendBuff, len);	}	GlobalFreePtr(SendBuff);	return 0;}int UDP_Server_Send_Hq10(LPDEST_INFO lpDest){	BYTE SendBuff[MAX_SEND_BUF_SIZE+1];	short recFirst =0, recCount =0, recNum, sendNum, sendCount, sendCount1;	int i, j, len =0, len1;	int jys =lpDest->curJys;	memset(&SendBuff[0],0, sizeof(SendBuff));	if(lpDest->paramsCount <=1) return -1;	recCount =lpDest->params[0];	if(lpDest->params[0]+lpDest->params[1]-1>=HqData[lpDest->curJys].recCount)		return  0;	strcpy(SendBuff, HQ10_HEAD);	len =strlen(HQ10_HEAD)+sizeof(short);	SendBuff[len++] =(char)lpDest->curJys;	*(short *)&SendBuff[len] =0;	len1 =len;	len +=sizeof(short);	sendCount =MAX_HQ_SEND_COUNT;	sendCount1 =0;	if(recCount==0) return 0;	if(recCount<MAX_HQ_SEND_COUNT)	{		for(i=0;i<recCount;i++)		{			sendNum=lpDest->params[1+i];			if(sendNum<0||sendNum>=HqData[lpDest->curJys].recCount)			{				ErrMsg(ghWndMain,"来自Send_Hq10:列表参数错");				return 0;			}			if(recCount>MAX_PARA_COUNT)			{				ErrMsg(ghWndMain,"来自Send_Hq10:发送记录数错");				return 0;			}			if(HqData[jys].lpRefData[sendNum].cjss					!=lpDest->lpCjss[i])			{				*(short *)&SendBuff[len] =sendNum;				len+=2;				memcpy(&SendBuff[len], &HqData[jys].lpRefData[sendNum],					sizeof(HQ_REF_DATA));				len +=sizeof(HQ_REF_DATA);				lpDest->lpCjss[i] =HqData[jys].lpRefData[sendNum].cjss;				sendCount1++;			}		}		if(sendCount1>0)		{			*(short *)&SendBuff[len1] =sendCount1;			*(short *)&SendBuff[strlen(HQ10_HEAD)] =len;			if(LOW_UDP_SendBuff("行情10", lpDest->sd, SendBuff, len,NULL,NULL)<0)			{				return -1;			}		}		return 0;	}	sendCount =MAX_HQ_SEND_COUNT;	sendCount1 =0;	for(i =0; i<recCount/MAX_HQ_SEND_COUNT ; i++)	{		recNum =i*MAX_HQ_SEND_COUNT;		if(recNum+sendCount >recCount)			sendCount =recCount-recNum;		for(j =0; j<sendCount; j++)		{			sendNum =lpDest->params[1+recNum+j];			if(HqData[jys].lpRefData[sendNum].cjss					!=lpDest->lpCjss[recNum+j])			{				*(short *)&SendBuff[len] =sendNum;				len+=2;				memcpy(&SendBuff[len], &HqData[jys].lpRefData[sendNum],					sizeof(HQ_REF_DATA));				len +=sizeof(HQ_REF_DATA);				lpDest->lpCjss[recNum+j] =HqData[jys].lpRefData[sendNum].cjss;				sendCount1++;			}			if(sendCount1 >=MAX_HQ_SEND_COUNT)			{				*(short *)&SendBuff[len1] =sendCount1;				*(short *)&SendBuff[strlen(HQ10_HEAD)] =len;				if(LOW_UDP_SendBuff("行情10", lpDest->sd, SendBuff, len, NULL, lpDest)<0)				{					return -1;				}				sendCount1 =0;				len =len1+sizeof(short);			}		}		if(sendCount1)		{			*(short *)&SendBuff[len1] =sendCount1;			*(short *)&SendBuff[strlen(HQ10_HEAD)] =len;			if(LOW_UDP_SendBuff("行情10", lpDest->sd, SendBuff, len, NULL, lpDest)<0)			{				return -1;			}			sendCount1 =0;			len =len1+sizeof(short);			break;		}		else		{			if(recCount<MAX_HQ_SEND_COUNT)				break;		}	}		return 0;}int UDP_Server_Send_LitHq(int sd, int jys, short rec_num, int cjss, struct sockaddr *lpdest, BOOL fThrd, LPDEST_INFO lpDestInfo){	char SendBuff[200];	int len;	memset(&SendBuff[0],0, sizeof(SendBuff));	strcpy(SendBuff, HQ10_HEAD);	len =strlen(HQ10_HEAD)+sizeof(short);	SendBuff[len ++] =jys;	*(short *)&SendBuff[len] =1;	len +=sizeof(short);	*(short *)&SendBuff[len] =rec_num;	len +=sizeof(short);	memcpy(&SendBuff[len], &HqData[jys].lpRefData[rec_num],			sizeof(HQ_REF_DATA));	len +=sizeof(HQ_REF_DATA);	*(short *)&SendBuff[strlen(HQ10_HEAD)] =len;	if(UDP_SendBuff("行情成交明细", sd, SendBuff, len, lpDestInfo)<0)			return -1;	return 0;}int UDP_Server_Send_Gra00(int sd, int jys, short gp_rec_num,GRA_HEAD *GraHead){                                                     	BYTE SendBuff[MAX_SEND_BUF_SIZE+1];	int len;		memset(&SendBuff[0],0, sizeof(SendBuff));	strcpy(SendBuff, GRA00_HEAD);	len =strlen(GRA00_HEAD)+sizeof(short);	SendBuff[len++] =(BYTE)jys;	memcpy(&SendBuff[len] ,GraHead, sizeof(GRA_HEAD));	len +=sizeof(GRA_HEAD);	*(short *)&SendBuff[strlen(GRA00_HEAD)] =len;	return UDP_SendBuff("分时图00", sd, SendBuff, len, NULL);}typedef struct tag_INIT_TEMP_INFO{ 	char head[7];	unsigned short id;		//数据对象的名称	unsigned short total;	//数据对象的总长	unsigned short expand;	//解压后的数据长度}INIT_TEMP_INFO,MEM_HEAD_INFO;int SendMemData(int sd,char *mem,int memlen){	int j =0,	//一次发送的结果		e,      //SOCKET 错误码		x=0,    //已发送数据包长		k,		complen, //压缩后的包总长		sended, //已传字节数 		len,    //从lpBuf分断后的数据长		tlen;   //发送数据包打包后总长	char SendBuf[1+sizeof(short)+sizeof(INIT_TEMP_INFO)+MAX_SEND_BUF_SIZE];	char *lpBuf;	INIT_TEMP_INFO InitTempInfo;	static unsigned short id=1;		lpBuf =GlobalAllocPtr(GHND,memlen);	if(lpBuf ==NULL) return -1;	if(memlen>512)	{		complen =memlen;		e=compress(lpBuf,&complen,mem,memlen);		if(e!=Z_OK)		{			memcpy(lpBuf,mem,memlen);			complen =memlen;		}	}	else	{		memcpy(lpBuf,mem,memlen);		complen =memlen;	}	strncpy(InitTempInfo.head,"MOVEMEM",7);	InitTempInfo.id =id++; if(id>=65534) id=1;	InitTempInfo.total =complen;	InitTempInfo.expand =memlen;	for(sended =0;sended<complen;)	{		if(complen-sended>MAX_SEND_BUF_SIZE)			len =MAX_SEND_BUF_SIZE;		else			len =complen-sended;		memset(SendBuf,0,1+sizeof(short)+sizeof(INIT_TEMP_INFO)+MAX_SEND_BUF_SIZE);		SendBuf[0]=START_SIGN;				*(short *)&SendBuf[1]=(short )len+sizeof(INIT_TEMP_INFO);		memcpy(&SendBuf[1+sizeof(short)],&InitTempInfo,sizeof(INIT_TEMP_INFO));		memcpy(&SendBuf[1+sizeof(short)+sizeof(INIT_TEMP_INFO)],&lpBuf[sended],len);		sended +=len;		tlen = len+1+sizeof(short)+sizeof(INIT_TEMP_INFO);		for(k=0,x=0;k<400;)		{			j =send(sd, &SendBuf[x], tlen -x, 0);			if (j == SOCKET_ERROR)			{				e =WSAGetLastError();				switch(e)				{					case WSANOTINITIALISED : 					//A successful WSAStartup must occur 					//before using this function. 						ErrMsg(ghWndMain,"WSANOTINITIALISED");						goto exit_send;					break;					case WSAENETDOWN :					//The network subsystem has failed. 						ErrMsg(ghWndMain,"WSAENETDOWN");						goto exit_send;					break;					case WSAEACCES:					//The requested address is a broadcast					//address, but the appropriate flag was not set. 						ErrMsg(ghWndMain,"WSAEACCES");						goto exit_send;					break;					case WSAEINTR:					//The (blocking) call was canceled through 					//WSACancelBlockingCall. 						goto exit_send;					break;					case WSAEINPROGRESS:					//A blocking Windows Sockets 1.1 call is					//in progress, or the service provider is still 					//processing a callback function. 						ShoutBlockingHook();						Sleep(10);					break;					case WSAEFAULT:					//The buf parameter is not totally contained in					//a valid part of the user address space.						goto exit_send;					break;					case WSAENETRESET:					//The connection has been broken due to the 					//remote host resetting. 						HqDestStopBySd(sd);						goto exit_send;					break;						case WSAENOBUFS:					//No buffer space is available. 						goto exit_send;					break;					case WSAENOTCONN:					//The socket is not connected.						HqDestStopBySd(sd);						goto exit_send;					break;					case WSAENOTSOCK:					//The descriptor is not a socket. 						goto exit_send;					break;					case WSAEOPNOTSUPP:					//MSG_OOB was specified, but the socket					//is not stream style such as type SOCK_STREAM, out-of-band data is not supported in the communication domain associated with this socket, or the socket is unidirectional and supports only receive operations. 						goto exit_send;					break;					case WSAESHUTDOWN:					//The socket has been shut down; it is not 					//possible to send on a socket after 					//shutdown has been invoked with how set 					//to SD_SEND or SD_BOTH. 						goto exit_send;					break;					case WSAEWOULDBLOCK:					//The socket is marked as nonblocking and 					//the requested operation would block. 						ShoutBlockingHook();						Sleep(10);					break;					case WSAEMSGSIZE:					//The socket is message oriented, and the 					//message is larger than the 					//maximum supported by the underlying transport. 						goto exit_send;					break;					case WSAEHOSTUNREACH:										//The remote host cannot be reached from this 					//host at this time. 						goto exit_send;					break;					case WSAEINVAL:					//The socket has not been bound with bind, or 					//an unknown flag was specified,						goto exit_send;					break;					case WSAECONNABORTED:					//The virtual circuit was terminated due to a 					//time-out or other failure. The application 					//should close the socket as it is no longer usable. 						HqDestStopBySd(sd);						goto exit_send;					break;					case WSAECONNRESET:					//The virtual circuit was reset by the remote 					//side executing a "hard" or "abortive" close. For 					//UPD sockets, the remote host was unable to deliver					//a previously sent UDP datagram and responded with 					//a "Port Unreachable" ICMP packet. The application 					//should close the socket as it is no longer usable. 						HqDestStopBySd(sd);						goto exit_send;					break;					case WSAETIMEDOUT:					//The connection has been dropped, because of a network					//failure or because the system on the other end went down 					//without notice. 						HqDestStopBySd(sd);						goto exit_send;					break;					default:						goto exit_send;				}			}			else			{				if(x+j !=tlen)				{					ShoutBlockingHook();					x+=j;				}				else					break;			}		}	}exit_send:	GlobalFreePtr(lpBuf);	return sended;}int Send_Gra01(int sd, LPSTR lpTmp,struct sockaddr *lpdest){	int jys,len;	char fileName[128];	HANDLE hd;	char *lpGraData =NULL;	HFILE hFile;	OFSTRUCT os;

⌨️ 快捷键说明

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