你子线程控制同步了么? 断错误一般是内存操作出错 和oci 或者pthread的关系不大!
void* OracleProcess(GPS_DATA GpsRec)// 数据库数据处理
{
interval = 0;
struct HashItem* pHash;
pHash = inithashtable(MAX_REC2);
char sql[384] = {0};
char temp[256] = {0};
char tName[10] = {0};// 表名字
int i,k;
int j = TotalRecRATE;
double distance;
for(i=0; ij; i++)
{
sprintf(temp,"%s%f%f%f%d",gps_last[i].tid,gps_last[i].lon,gps_last[i].lat,gps_last[i].speed,gps_last[i].udate);
InsertHash(temp, pHash, MAX_REC2);// 插入最后GPS信息到hash
memset(temp,0x00,256);
}
for(i = 0; iTotalRec; i++)
{
for(k=0; kj; k++)// 查询车机是否在册
if(strcmp(GpsRec[i].tid,tid[k]) == 0)
break;
if(kj)
{
if(GpsRec[i].udate != 0.00)
{
distance = InfoUpdate(GpsRec,i);// 最新GPS数据更新
sprintf(temp,"%s%f%f%f%d",GpsRec[i].tid,GpsRec[i].lon,GpsRec[i].lat,GpsRec[i].speed,GpsRec[i].udate);
if(GetHashTablePos(temp, pHash, MAX_REC2) == -1) // 查找hash是否存在
{
if (distance0.0001)
{
sprintf(tName,"GPS_%d_Y",tf[k]);
InsertHash(temp, pHash, MAX_REC2); // 插入
sprintf(sql,"insert into %s (id,tm_id,lon,lat, speed, utc_time, udate,mileage,DIRECTION,DISTANCE) values (seq_gps.nextVal,'%s','%f','%f','%f','%d','%d','%f','%d','%f','%d')",
tName,GpsRec[i].tid,GpsRec[i].lon,GpsRec[i].lat,GpsRec[i].speed,GpsRec[i].utime,GpsRec[i].udate,GpsRec[i].mileage,GpsRec[i].dir,distance,interval);
printf("%s\n",sql);
oci_excu(oracle_env,(text *)sql,0);// 插入数据
memset(tName,0x00,10);
}
}
memset(sql,0x00,384);
memset(temp,0x00,256);
}
}
}
memset(GpsRec,0x00,sizeof(GpsRec));
free(pHash);
pthread_exit(NULL);
}
void TcpProcess(int tfd)// 处理TCP连接上的事务
{
struct timeval ntime;
int index = 0,times,ret;
int rlen = 0,rflag = 0;
char recvbuf[513] = {0};
bzero(recvbuf,513);
while(1)
{
ret = rlen = read(tfd,recvbuf,512);
if(rlen = 0)
break;
if((rlen%32) == 0) // 32长度为标准TCP信息
{
times = 0;
ret = 5;
while(ret--)
{
if(tflag[tfd] == tfd) // 已经存在的socket
{
LOVENIX *info = (LOVENIX *)malloc(sizeof(LOVENIX));
memset(info,0x00,sizeof(LOVENIX));
if(recvbuf[times] == 0x58 || recvbuf[times] == 0x59)
ProtocolAnalysisLovenixTcp(recvbuf[times],info);
else if(recvbuf[times] == 0x24)
ProtocolAnalysisLovenixUdp(recvbuf[times],info);
sprintf(info-tid,"%s",seq[tfd]);// 合成车辆ID
DataProcess(info);// 处理GPS数据
free(info);
gettimeofday(ntime, NULL);
cntime[tfd] = ntime.tv_sec;// 更新时间
times += 32;
}
}
}
else if(rlen32)
{
if(!rflag)
{
if((index = RegLovenix(tfd,recvbuf))-1)
{
sprintf(seq[tfd],"%s",tid[index]);// 将对应的socket设备ID保存
gettimeofday(ntime, NULL);
sfd[tfd] = tfd;
cntime[tfd] = ntime.tv_sec;
tflag[tfd] = tfd;
rflag = 1;
}
}
}
if(rlen512);// 已经读完
break;
memset(recvbuf,0x00,rlen);
}
}
void *TcpServer(void *arg)
{
int port = (unsigned int) arg;
int efd,i;
struct timeval ntime;
int listener, nfds, n, listen_opt = 1, lisnum;
struct sockaddr_in my_addr, their_addr;
socklen_t len = sizeof(their_addr);
lisnum = MAXLISTEN;
for(i=0; iMAX_REC; i++)
{
sfd[i] = 0;
tflag[i] = 0;
}
if ((listener = socket(PF_INET, SOCK_STREAM, 0)) == -1)// 开启 socket 监听
{
lprintf(lfd, FATAL, "TCP Socket error!\n");
exit(1);
推荐阅读
- 多功能电视怎么设置摄像头,电视摄像机怎么用
- jquery滑动对比,jquery滑动事件
- 类似与jquery,类似与凤行的仙侠文
- 小时候网页格斗小游戏大全,小时候玩的格斗电子游戏
- vb.net键盘扫码 vbs键盘代码
- oracle表关联自己更新,oracle多表关联
- redis查看列表数据,redis 查看list内容
- 1688直播伴侣,1688直播伴侣性能指标显示脱机状态怎么办
- go语言切片扩容技巧 go 切片添加切片