Commit 39274137 by wuyang.zou

New Feature: Plugin 支持 config.ini 中 ip 变更为 域名功能

parent 5f417e24
......@@ -12,6 +12,9 @@
#else
#include <pthread.h>
#include <unistd.h>
#include <netdb.h>
#include <sys/socket.h>
#include <stdio.h>
#endif
#define ELPP_NO_DEFAULT_LOG_FILE
......@@ -19,7 +22,7 @@
INITIALIZE_EASYLOGGINGPP
#define VERSION "1.2.0 RC" //版本号
#define VERSION "1.2.1 RC " //版本号
std::string g_init_data;
std::string g_init_data_ods_back;
......@@ -41,6 +44,8 @@ TCPClient longConnectionOds; //长连接tcp对象
//函数,订单信息发送给pos
bool order_send_to_pos(IN std::string &order_json,IN std::string &ods_json,OUT std::string &back_json);
void getIpByDns(IN std::string &ods_ip);
//但进程运行,杀掉已有进程
void kill_origin_process();
......@@ -284,9 +289,11 @@ int main(int argc,char *argv[])
LOG(INFO) << "strIniPath: " << strIniPath.data();
ods_ip = ZIni::readString("ODS","ip", "", strIniPath.c_str());
getIpByDns(ods_ip);
ods_push_port = ZIni::readInt("ODS", "pushPort", 0, strIniPath.c_str());
ods_recv_port = ZIni::readInt("ODS", "recvPort", 0, strIniPath.c_str());
int ods_socket_timeout = ZIni::readInt("ODS", "socketTimeout", 0, strIniPath.c_str());
pos_ip = ZIni::readString("POS","ip", "", strIniPath.c_str());
pos_listen_port = ZIni::readInt("POS","port", 0, strIniPath.c_str());
......@@ -490,6 +497,59 @@ bool order_send_to_pos(IN std::string &order_json,IN std::string &ods_json,OUT s
return rlt;
}
void getIpByDns(IN std::string &ods_ip) {
if (ods_ip.front() < '0' || ods_ip.front() > '9') {
struct hostent* pHost = NULL;
bool bGetDnsRet = false;
for (int n = 0; n < 3; n++) {
pHost = gethostbyname(ods_ip.c_str());
if (!pHost) {
LOG(INFO) << "DNS Resolve Failed: ods domain name: " << n << " " << ods_ip.c_str();
LOG(ERROR) << "DNS Resolve Failed: I don't know what to do, sleep 1 minute first ";
os_sleep(6);
}
else {
bGetDnsRet = true;
break;
}
}
if (bGetDnsRet) {
int i = 0;
if (pHost->h_addrtype == AF_INET) {
char str[32];
char **pptr;
pptr = pHost->h_addr_list;
#ifdef WIN32
ods_ip = *(ULONG*)(pHost->h_addr);
#else
for (; *pptr != NULL; pptr++) {
inet_ntop(pHost->h_addrtype, *pptr, str, sizeof(str) );
LOG(INFO) << "DNS Resolve IP List: " << str;
}
inet_ntop(pHost->h_addrtype, pHost->h_addr, str, sizeof(str));
ods_ip = str;
#endif
}
}
else {
LOG(ERROR) << "DNS Resolve Failed: I will exit, bye-bye";
exit(0);
}
LOG(INFO) << "DNS Resolve Sucessful ODS_IP: " << ods_ip.c_str();
}
else {
LOG(INFO) << "No Need DNS Resolve ODS_IP: " << ods_ip.c_str();
}
}
//实现逻辑:向本地socket发送一个命令,程序接到命令后自杀,如果没有自杀成功,根据名称杀掉
void kill_origin_process()
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment