diff --git a/conf/tfe/tfe.conf b/conf/tfe/tfe.conf index 3020c87..651009c 100644 --- a/conf/tfe/tfe.conf +++ b/conf/tfe/tfe.conf @@ -43,5 +43,6 @@ statsd_port=8126 histogram_bins=0.50,0.80,0.9,0.95 [sender_scm] +switch = 1 kni_ip = 192.168.10.37 kni_port = 8888 diff --git a/platform/include/internal/sender_scm.h b/platform/include/internal/sender_scm.h index 690eb86..b773059 100644 --- a/platform/include/internal/sender_scm.h +++ b/platform/include/internal/sender_scm.h @@ -1,4 +1,4 @@ struct sender_scm; struct sender_scm* sender_scm_init(const char *profile, void *logger); void send_scm_destroy(struct sender_scm *sender); -int sender_scm_cmsg_send(struct sender_scm *sender, struct tfe_cmsg *cmsg); +struct sender_scm* sender_scm_init(const char *profile, const char *section, void *logger); diff --git a/platform/src/sender_scm.cpp b/platform/src/sender_scm.cpp index 5bb1f4c..b5adc14 100644 --- a/platform/src/sender_scm.cpp +++ b/platform/src/sender_scm.cpp @@ -9,6 +9,7 @@ struct sender_scm { int sockfd; struct sockaddr_in server_addr; + int send_switch; void *logger; }; @@ -24,16 +25,29 @@ void send_scm_destroy(struct sender_scm *sender) FREE(&sender); } -struct sender_scm* sender_scm_init(const char *profile, void *logger) + +/* TODO: +0: switch +1. no_blocking + eagain +2. libevent +3. field_stat: success/failed +*/ +struct sender_scm* sender_scm_init(const char *profile, const char *section, void *logger) { - const char *section = "sender_scm"; char kni_ip[INET_ADDRSTRLEN] = ""; + int send_switch = -1; int kni_port = -1; int sockfd = -1; struct sockaddr_in server_addr; struct sender_scm *sender = ALLOC(struct sender_scm, 1); sender->logger = logger; - int ret = MESA_load_profile_string_nodef(profile, section, "kni_ip", kni_ip, sizeof(kni_ip)); + int ret = MESA_load_profile_int_nodef(profile, section, "send_switch", &send_switch); + if(ret < 0) + { + TFE_LOG_ERROR(logger, "MESA_prof_load: send_switch not set, profile is %s, section is %s", profile, section); + goto error_out; + } + ret = MESA_load_profile_string_nodef(profile, section, "kni_ip", kni_ip, sizeof(kni_ip)); if(ret < 0) { TFE_LOG_ERROR(logger, "MESA_prof_load: kni_ip not set, profile is %s, section is %s", profile, section); @@ -47,6 +61,11 @@ struct sender_scm* sender_scm_init(const char *profile, void *logger) } TFE_LOG_INFO(logger, "MESA_prof_load, [%s]:\n kni_ip: %s\n kni_port: %d", section, kni_ip, kni_port); + sender->send_switch = send_switch; + if(send_switch == 0) + { + return sender; + } //create socket sockfd = socket(AF_INET, SOCK_DGRAM, 0); if(sockfd < 0) @@ -71,6 +90,11 @@ error_out: int sender_scm_cmsg_send(struct sender_scm *sender, struct tfe_cmsg *cmsg) { void *logger = sender->logger; + int send_switch = sender->send_switch; + if(send_switch == 0) + { + return 0; + } uint16_t bufflen = tfe_cmsg_serialize_size_get(cmsg); unsigned char *buff = ALLOC(unsigned char, bufflen); uint16_t serialize_len = 0;