添加sender_scm开关
This commit is contained in:
@@ -43,5 +43,6 @@ statsd_port=8126
|
|||||||
histogram_bins=0.50,0.80,0.9,0.95
|
histogram_bins=0.50,0.80,0.9,0.95
|
||||||
|
|
||||||
[sender_scm]
|
[sender_scm]
|
||||||
|
switch = 1
|
||||||
kni_ip = 192.168.10.37
|
kni_ip = 192.168.10.37
|
||||||
kni_port = 8888
|
kni_port = 8888
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
struct sender_scm;
|
struct sender_scm;
|
||||||
struct sender_scm* sender_scm_init(const char *profile, void *logger);
|
struct sender_scm* sender_scm_init(const char *profile, void *logger);
|
||||||
void send_scm_destroy(struct sender_scm *sender);
|
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);
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ struct sender_scm
|
|||||||
{
|
{
|
||||||
int sockfd;
|
int sockfd;
|
||||||
struct sockaddr_in server_addr;
|
struct sockaddr_in server_addr;
|
||||||
|
int send_switch;
|
||||||
void *logger;
|
void *logger;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -24,16 +25,29 @@ void send_scm_destroy(struct sender_scm *sender)
|
|||||||
FREE(&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] = "";
|
char kni_ip[INET_ADDRSTRLEN] = "";
|
||||||
|
int send_switch = -1;
|
||||||
int kni_port = -1;
|
int kni_port = -1;
|
||||||
int sockfd = -1;
|
int sockfd = -1;
|
||||||
struct sockaddr_in server_addr;
|
struct sockaddr_in server_addr;
|
||||||
struct sender_scm *sender = ALLOC(struct sender_scm, 1);
|
struct sender_scm *sender = ALLOC(struct sender_scm, 1);
|
||||||
sender->logger = logger;
|
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)
|
if(ret < 0)
|
||||||
{
|
{
|
||||||
TFE_LOG_ERROR(logger, "MESA_prof_load: kni_ip not set, profile is %s, section is %s", profile, section);
|
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",
|
TFE_LOG_INFO(logger, "MESA_prof_load, [%s]:\n kni_ip: %s\n kni_port: %d",
|
||||||
section, kni_ip, kni_port);
|
section, kni_ip, kni_port);
|
||||||
|
sender->send_switch = send_switch;
|
||||||
|
if(send_switch == 0)
|
||||||
|
{
|
||||||
|
return sender;
|
||||||
|
}
|
||||||
//create socket
|
//create socket
|
||||||
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
|
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
if(sockfd < 0)
|
if(sockfd < 0)
|
||||||
@@ -71,6 +90,11 @@ error_out:
|
|||||||
int sender_scm_cmsg_send(struct sender_scm *sender, struct tfe_cmsg *cmsg)
|
int sender_scm_cmsg_send(struct sender_scm *sender, struct tfe_cmsg *cmsg)
|
||||||
{
|
{
|
||||||
void *logger = sender->logger;
|
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);
|
uint16_t bufflen = tfe_cmsg_serialize_size_get(cmsg);
|
||||||
unsigned char *buff = ALLOC(unsigned char, bufflen);
|
unsigned char *buff = ALLOC(unsigned char, bufflen);
|
||||||
uint16_t serialize_len = 0;
|
uint16_t serialize_len = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user