Exemplo n.º 1
0
void net_recv(void)
{
#define BUFSIZE 10240
	char buf[BUFSIZE];

	
	int bytes_read;



	bytes_read = recv(sock,buf,BUFSIZE, MSG_DONTWAIT);
//	bytes_read = recv(sock,buf,BUFSIZE, 0);

	if( bytes_read<0 )
	{
		if( ! ((errno==EAGAIN) || (errno==EWOULDBLOCK)) )
		{
			printf("recv failed - error %d!\n",errno);
			exitt(1);
		}
	}
	else if( bytes_read==0 )
	{
		printf("recv failed - closed! errno=%d\n",errno);
		exitt(1);
	}
	else // >0
	{
		parse_recv_data(buf,bytes_read);
	}

//	if( 4!=sscanf(buf,"%X<=%X:%X with %X",&addr,&dat_hi,&dat_lo,&sel) )
}
Exemplo n.º 2
0
void Connection::handle_read(const boost::system::error_code & e, size_t bytes_transferred)
{
    if (!e)
    {
        boost::logic::tribool result = parse_recv_data(m_buffer.data(), bytes_transferred);

        if (result)
        {
            handle_recv_success();
        }else
        {
            lout << "recv failed." << endl;
            handle_recv_error();
        }
    }else
    {
        lerr << "handle_read error: " << e.message() << endl;
        handle_recv_error();
    }
}
Exemplo n.º 3
0
static int check_send_transdtl()
{
	const int TRANSDTL_SLEEP_TM = 10;
	const int HEART_SLEEP_TM = 30;
	char recv_buf[1024] = {0};
	int recv_len = 0;
	int ret =0;
	LOG((LOG_DEBUG,"进入check_send_transdtl"));
	while (p16pos.app_running)
	{
		memset(recv_buf,0,1024);
		recv_len = 0;
		ret = send_rt_transdtl_data(recv_buf,&recv_len);
		if(ret == 0)//发送实时流水成功的情况
		{
			if(recv_len>0)
			{
				p16_recv_rt_transdtl_package recv_package;
				memset(&recv_package,0,sizeof(recv_package));
				parse_recv_data(recv_buf,3,&recv_package);
				if(recv_package.data.ret_code == 0)
				{
					LOG((LOG_DEBUG,"上传实时流水成功"));
				}
				else
				{
					LOG((LOG_DEBUG,"上传实时流水失败,pos机不再上传流水"));
				}
			}
			LOG((LOG_DEBUG,"=========================sleep %d========================",TRANSDTL_SLEEP_TM));
			sleep(TRANSDTL_SLEEP_TM);
		}
		else//没有交易流水需要发送
		{
			//发送心跳
			send_heart_data(recv_buf,&recv_len);
			if(recv_len>0)
			{
				//分析接收的数据
				p16_recv_heart_package recv_heart;
				parse_recv_data(recv_buf,0,&recv_heart);

				LOG((LOG_DEBUG,"心跳收到的系统版本号:"));
				p16dump_hex(LOG_DEBUG,recv_heart.data.cfgverno,4);
				LOG((LOG_DEBUG,"心跳收到的服务器时间:"));
				p16dump_hex(LOG_DEBUG,recv_heart.data.server_datetime,6);
				LOG((LOG_DEBUG,"心跳收到的服务器黑名单版本号:"));
				p16dump_hex(LOG_DEBUG,recv_heart.data.current_blacklist_version,6);
				LOG((LOG_DEBUG,"当前系统的黑名单版本号:"));
				p16dump_hex(LOG_DEBUG,p16pos.pos_blacklist_version, 6);
				if(memcmp(recv_heart.data.current_blacklist_version,p16pos.pos_blacklist_version, 6)>0)
				{
					LOG((LOG_DEBUG,"心跳收到的黑名单版本号大于当前系统的黑名单版本号,执行下载黑名单函数!!"));
					//下载黑名单
					memset(recv_buf,0,1024);
					recv_len = 0;
					send_download_blacklist_data(recv_buf,&recv_len);
					if(recv_len>0)
					{
						p16_recv_blacklist_package recv_package;
						parse_recv_data(recv_buf, 2, &recv_package);
						if(recv_package.data.list_cnt>0)
						{
							//有黑名单
							LOG((LOG_DEBUG,"有黑名单%d条",recv_package.data.list_cnt));
							ret = save_blackcard_record(recv_package.data.list_cnt, recv_package.data.blacklist_list);
							if(ret)
							{
								//致命错误,联系管理员
								disp_msg("操作数据库失败,请联系管理员",10);
								return -1;
							}
							//更新系统黑名单版本号
							char pos_blacklist_version[13] = {0};
							encode_hex(recv_package.data.sys_list_version, 6, pos_blacklist_version);
							//更新系统版本号
							ret = update_config("dev.pos_blacklist_version",pos_blacklist_version);
							if(ret)
							{
								//致命错误
								return -2;
							}
							memcpy(p16pos.pos_blacklist_version, recv_package.data.sys_list_version, 6);
							LOG((LOG_DEBUG,"更新版本号为:%s",pos_blacklist_version));
							LOG((LOG_DEBUG,"======================================================="));
						}
					}

				}
			}
			LOG((LOG_DEBUG,"=========================sleep %d========================",HEART_SLEEP_TM));
			sleep(HEART_SLEEP_TM);
		}
		
	}
    return 0;
}