📄 sv_tcp.c
字号:
len +=sizeof(short); memcpy(&SendBuff[len], &lpGraData[0], gra_rec_count*sizeof(GRA_DATA)); len +=gra_rec_count*sizeof(GRA_DATA); if(LOW_UDP_SendBuff("分时图10", lpDest->sd, SendBuff, len,NULL,lpDest)<0) { if(lpGraData!=NULL) { GlobalUnlock(hd); GlobalFree(hd); } return -1; } else { if(lpGraData!=NULL) { GlobalUnlock(hd); GlobalFree(hd); } //lpDest->params[1] +=gra_rec_count; lpDest->graEnd+=gra_rec_count; return 0; } } sendCount =MAX_GRA_SEND_COUNT; for(i =0; i<gra_rec_count/MAX_GRA_SEND_COUNT; i++) { sendNum =i*MAX_GRA_SEND_COUNT; if(sendCount+sendNum >gra_rec_count) sendCount =gra_rec_count-sendNum; strcpy(SendBuff, GRA10_HEAD); len =strlen(GRA01_HEAD)+sizeof(short); SendBuff[len++] =(char)jys; *((short *)&SendBuff[len]) =gp_rec_num; len +=sizeof(short); *((short *)&SendBuff[len]) =sendCount; len +=sizeof(short); *((short *)&SendBuff[len]) =sendNum+gra_rec_end; len +=sizeof(short); memcpy(&SendBuff[len], &lpGraData[sendNum], sendCount*sizeof(GRA_DATA)); len +=sendCount*sizeof(GRA_DATA); if(sendCount) { *(short *)&SendBuff[strlen(GRA10_HEAD)] =len; if(LOW_UDP_SendBuff("分时图10", lpDest->sd, SendBuff, len, NULL,lpDest)<0) { if(lpGraData!=NULL) { GlobalUnlock(hd); GlobalFree(hd); } return -1; } } } if(lpGraData!=NULL) { GlobalUnlock(hd); GlobalFree(hd); } //lpDest->params[1] +=gra_rec_count; lpDest->graEnd+=gra_rec_count; return 0;}int UDP_Server_Send_Dp(int sd, struct sockaddr *lpdest, BOOL fThrd, LPDEST_INFO lpDest){ BYTE SendBuff[MAX_SEND_BUF_SIZE+1]; int len; memset(&SendBuff[0],0, sizeof(SendBuff)); strcpy(SendBuff, DP_HEAD); len =strlen(DP_HEAD)+sizeof(short); memcpy(&SendBuff[len], &DpData, sizeof(DpData)); len +=sizeof(DpData); *(short *)&SendBuff[strlen(DP_HEAD)] =len; return UDP_SendBuff("大盘数据", sd, SendBuff, len,lpDest);}int UDP_Server_Send_Mmp(int sd, int jys, short rec_num, struct sockaddr *lpdest, BOOL fThrd, LPDEST_INFO lpDestInfo){ BYTE SendBuff[MAX_SEND_BUF_SIZE+1]; int len; memset(&SendBuff[0],0, sizeof(SendBuff)); strcpy(SendBuff, MMP_HEAD); len =strlen(MMP_HEAD)+sizeof(short); SendBuff[len++] =jys; *((short *)&SendBuff[len]) =rec_num; len +=sizeof(short); memcpy(&SendBuff[len], &MmpData[jys].lpMmp[rec_num], sizeof(MMP)); len +=sizeof(MMP); *(short *)&SendBuff[strlen(MMP_HEAD)] =len; return UDP_SendBuff("买卖盘数据", sd, SendBuff, len,lpDestInfo);}int UDP_Server_Send_MaxMin10(int sd, int jys, int maxmin, struct sockaddr *lpdest, BOOL fThrd, LPDEST_INFO lpDestInfo){ BYTE SendBuff[MAX_SEND_BUF_SIZE+1]; int len; if(jys > 1 || maxmin >1) return -1; memset(&SendBuff[0],0, sizeof(SendBuff)); MaxMinFillData(jys, maxmin); strcpy(SendBuff, MAXMIN10_HEAD); len =strlen(MAXMIN10_HEAD)+sizeof(short); SendBuff[len++] =jys; SendBuff[len] =maxmin; len++; memcpy(&SendBuff[len], &MaxMinData[jys][maxmin], sizeof(MAXMIN_DATA)); len +=sizeof(MAXMIN_DATA); *(short *)&SendBuff[strlen(MAXMIN10_HEAD)] =len; return UDP_SendBuff("排行榜", sd, SendBuff, len, lpDestInfo);}int UDP_Server_Send_GetZqmc(int sd, LPSTR lpTmp, struct sockaddr *lpdest){ int jys, len, i, recCount, recNum; char SendBuff[2048]; memset(&SendBuff[0],0, sizeof(SendBuff)); jys =*lpTmp++; recCount =*(short *)lpTmp; lpTmp +=sizeof(short); strcpy(SendBuff, GETZQMC_HEAD); len =strlen(GETZQMC_HEAD)+sizeof(short); SendBuff[len++] =jys; *(short *)&SendBuff[len] =0; len +=sizeof(short); for(i =0; i<recCount; i++) { recNum =*(short *)lpTmp; lpTmp +=sizeof(short); if(recNum >=HqData[jys].recCount) break; *(short *)&SendBuff[len] =recNum; len +=sizeof(short); memcpy(&SendBuff[len], HqData[jys].lpPreData[recNum].zqmc, MAX_ZQMC_SIZE); len +=MAX_ZQMC_SIZE; } *(short *)&SendBuff[strlen(GETZQMC_HEAD)+sizeof(short)+1] =i; *(short *)&SendBuff[strlen(GETZQMC_HEAD)] =len; if(UDP_SendBuff("股票名称", sd, SendBuff, len, NULL)<0) return -1; return 0;}int UDP_Server_Send_Zx(int sd, LPSTR lpTmp, struct sockaddr *lpdest){ BYTE SendBuff[MAX_SEND_BUF_SIZE+1]; int len, file_len, read_len, read_total, start_pos; //if(FileTranLock) // return 0; if(hfZx ==HFILE_ERROR) return 0; memset(&SendBuff[0],0, sizeof(SendBuff)); start_pos =*(int *)lpTmp; _llseek(hfZx, 0, SEEK_SET); file_len =(int)_llseek(hfZx, 0, SEEK_END)-start_pos; if(file_len <=0) return 0; _llseek(hfZx, start_pos, SEEK_SET); read_len =1024; read_total =0; while(read_total <file_len) { while(ShoutBlockingHook()); if(run_cancelled) break; if(file_len-read_total <read_len) read_len =file_len-read_total; strcpy(SendBuff, ZX_HEAD); len =strlen(ZX_HEAD)+sizeof(short); if(_lread(hfZx, &SendBuff[len], read_len)!=(UINT)read_len) return read_total; len +=read_len; *(short *)&SendBuff[strlen(ZX_HEAD)] =len; if(UDP_SendBuff("资讯", sd, SendBuff, len,NULL)<0) return -1; read_total+=read_len; } return 0;}int SendDataDay(int sd, LPSTR lpTmp, struct sockaddr *lpdest){ BYTE SendBuff[MAX_SEND_BUF_SIZE+1]; int jys, i, len; char fileName[128]; HFILE hFile; OFSTRUCT os; short gp_rec_num, data_rec_count, data_rec_end, sendCount, sendNum; jys =*lpTmp++; if(jys > 1) return -1; memset(&SendBuff[0],0, sizeof(SendBuff)); gp_rec_num =*(short *)lpTmp; if(gp_rec_num >=HqData[jys].recCount) return -1; lpTmp +=sizeof(short); data_rec_end =*(int *)lpTmp; lpTmp +=sizeof(int); wsprintf(fileName, "%s\\%s\\%s.day", szDataPath, (jys ==0)?"SZDAY":"SHDAY", HqData[jys].lpPreData[gp_rec_num].zqdm); hFile =OpenFile(fileName, &os, OF_SHARE_DENY_NONE|OF_READ); if(hFile ==HFILE_ERROR) { return -1; } data_rec_count=(int) _llseek(hFile, 0l, FILE_END)/sizeof(DAY_DATA)-data_rec_end; if(data_rec_count<=0) { _lclose(hFile); return -1; } if(data_rec_count>500) data_rec_count =500; if(_llseek(hFile, data_rec_end*sizeof(DAY_DATA), FILE_BEGIN) ==HFILE_ERROR) { ErrMsg(ghWndMain, "定位日线文件失败!"); ErrMsg(ghWndMain, fileName); _lclose(hFile); return -1; } sendCount =MAX_GRA_SEND_COUNT; for(i =0; i<=data_rec_count/MAX_GRA_SEND_COUNT; i++) { sendNum =i*MAX_GRA_SEND_COUNT; if(sendCount+sendNum >data_rec_count) sendCount =data_rec_count-sendNum; strcpy(SendBuff, DATA_DAY_HEAD); len =strlen(DATA_DAY_HEAD)+sizeof(short); SendBuff[len++] =(char)jys; *((short *)&SendBuff[len]) =gp_rec_num; len +=sizeof(short); *((short *)&SendBuff[len]) =sendCount; len +=sizeof(short); *((short *)&SendBuff[len]) =sendNum; len +=sizeof(short); if(_lread(hFile, &SendBuff[len], sizeof(DAY_DATA)*sendCount) !=sizeof(DAY_DATA)*sendCount) { ErrMsg(ghWndMain, "读日线文件失败!"); _lclose(hFile); return -1; } len +=sendCount*sizeof(DAY_DATA); *(short *)&SendBuff[strlen(DATA_DAY_HEAD)] =len; if(sendCount) if(UDP_SendBuff("日线01", sd, SendBuff, len,NULL)<0) break; ShoutBlockingHook(); } _lclose(hFile); return 0;}int SendDayData(int sd, LPSTR lpTmp, struct sockaddr *lpdest){ char *SendBuff; int jys,len,day; char fileName[128]; HFILE hFile; OFSTRUCT os; short gp_rec_num, data_rec_count, data_rec_end, send_rec_count,sendCount, sendNum; char IsAll =0,range=0; DAY_DATA DayData; jys =*lpTmp++; if(jys > 1) return -1; gp_rec_num =*(short *)lpTmp; if(gp_rec_num >=HqData[jys].recCount) return -1; lpTmp +=sizeof(short); data_rec_end =*(int *)lpTmp; if(data_rec_end<0) return -1; lpTmp +=sizeof(int); day =*(int *)lpTmp; wsprintf(fileName, "%s\\%s\\%s.day", szDataPath, (jys ==0)?"SZDAY":"SHDAY", HqData[jys].lpPreData[gp_rec_num].zqdm); hFile =OpenFile(fileName, &os, OF_SHARE_DENY_NONE|OF_READ); if(hFile ==HFILE_ERROR) return -1; data_rec_count=(int) _llseek(hFile, 0l, FILE_END)/sizeof(DAY_DATA); if(data_rec_count <=0) goto exit_send; if(data_rec_end ==0) IsAll =1; else if(data_rec_end>0) { if(data_rec_end>data_rec_count) IsAll =1; else { _llseek(hFile, (data_rec_end-1)*sizeof(DAY_DATA), FILE_BEGIN); if(_lread(hFile, &DayData, sizeof(DAY_DATA))==sizeof(DAY_DATA)) { if(DayData.day!=day) IsAll=1; } else IsAll =1; } } if(IsAll) { send_rec_count=data_rec_count; _llseek(hFile, 0L, FILE_BEGIN); } else { send_rec_count=data_rec_count-data_rec_end; _llseek(hFile, data_rec_end*sizeof(DAY_DATA), FILE_BEGIN); } if(send_rec_count>1500) send_rec_count=1500; SendBuff =GlobalAllocPtr(GHND, strlen(DATA_DAY_HEAD)+11+sizeof(DAY_DATA)*send_rec_count); if(SendBuff ==NULL) { _lclose(hFile); return -1; } sendCount =send_rec_count; sendNum =0; strcpy(SendBuff, DATA_DAY_HEAD); //7 len =strlen(DATA_DAY_HEAD)+sizeof(short); //2 SendBuff[len++] =(char)jys; //1 *((short *)&SendBuff[len]) =gp_rec_num; len +=sizeof(short); //2 *((short *)&SendBuff[len]) =sendCount; len +=sizeof(short); //2 *((short *)&SendBuff[len]) =sendNum; len +=sizeof(short); //2 SendBuff[len++] =IsAll; //1 SendBuff[len++] =range; //1 if(sendCount) if(_lread(hFile, &SendBuff[len], sizeof(DAY_DATA)*sendCount) !=sizeof(DAY_DATA)*sendCount) goto exit_send; len +=sendCount*sizeof(DAY_DATA); *(short *)&SendBuff[strlen(DATA_DAY_HEAD)] =len; if(sendCount) SendMemData(sd,SendBuff, len);exit_send: GlobalFreePtr(SendBuff); _lclose(hFile); return 0;}typedef struct tag_UDP_SEND_INFO{ int sd; int len; BYTE version; LPDEST_INFO lpDestInfo; struct sockaddr dest; char SendBuf[MAX_SEND_BUF_SIZE+1]; char filename[80]; HANDLE hThread;}UDP_SEND_INFO, *LPUDP_SEND_INFO;////////////////////////////////////////////////////////Function : send data pack to client//Return :// return value >0,return send data number// return value =0,no data send// return value <0,a net error come,we must// close the socket or stop commuate//Modi date:// 1998/03/23 int UDP_SendBuff(LPSTR lpMsg, int sd, LPSTR lpBuf, int len, LPDEST_INFO lpDestInfo){ int j =0, //一次发送的结果 e, //SOCKET 错误码 x=0, //已发送数据包长 k, tlen; //数据包总长 char SendBuf[MAX_SEND_BUF_SIZE+sizeof(short)+1]; MsgSend(lpMsg); if(len+sizeof(short)+1>MAX_SEND_BUF_SIZE) { ErrMsg(ghWndMain, "来自UDP_SendBuff:发送记录太长"); return (-1); } memset(SendBuf,0,MAX_SEND_BUF_SIZE+1+sizeof(short)); SendBuf[0]=START_SIGN; *(short *)&SendBuf[1]=(short )len; memcpy(&SendBuf[1+sizeof(short)],lpBuf,len); if(lpDestInfo!=NULL) { if(lpDestInfo->isDead) return 0; } tlen = len+1+sizeof(short); for(k=0;k<200;k++) { if(run_cancelled) break; 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"); return 0; break; case WSAENETDOWN : //The network subsystem has failed. ErrMsg(ghWndMain,"WSAENETDOWN"); return x; break; case WSAEACCES: //The requested address is a broadcast //address, but the appropriate flag was not set. ErrMsg(ghWndMain,"WSAEACCES"); return 0; break; case WSAEINTR: //The (blocking) call was canceled through //WSACancelBlockingCall. return x; 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(30); break; case WSAEFAULT: //The buf parameter is not totally contained in //a valid part of the user address space. return x; break; case WSAENETRESET: //The connection has been broken due to the //remote host resetting. HqDestStopBySd(sd); return -1; break; case WSAENOBUFS: //No buffer space is available. return x; break; case WSAENOTCONN: //The socket is not connected. HqDestStopBySd(sd); return -1; break; case WSAENOTSOCK: //The descriptor is not a socket. return -1; 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. return x; 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. return -1; break; case WSAEWOULDBLOCK: //The socket is marked as nonblocking and //the requested operation would block. ShoutBlockingHook(); if(lpDestInfo!=NULL) { if(lpDestInfo->isDead) return 0; } Sleep(30); break; case WSAEMSGSIZE: //The socket is message oriented, and the //message is larger than the //maximum supported by the underlying transport. return x; break; case WSAEHOSTUNREACH: //The remote host cannot be reached from this //host at this time. return x; break; case WSAEINVAL: //The socket has not been bound with bind, or //an unknown flag was specified, return -1; break; case WSAEC
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -