diff --git a/.gitignore b/.gitignore index b4d061d915..5cca4a8590 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,7 @@ # Log path log/ + + +# third party +third diff --git a/include/tick_conf.h b/include/tick_conf.h index 96e8c036e8..17d2bde498 100644 --- a/include/tick_conf.h +++ b/include/tick_conf.h @@ -18,6 +18,7 @@ class TickConf : public BaseConf private: int port_; + int hb_port_; int thread_num_; char log_path_[TICK_WORD_SIZE]; int log_level_; diff --git a/include/tick_hb.h b/include/tick_hb.h new file mode 100644 index 0000000000..874175e13e --- /dev/null +++ b/include/tick_hb.h @@ -0,0 +1,32 @@ +#ifndef __TICK_HB_H__ +#define __TICK_HB_H__ + +#include "status.h" +#include "csapp.h" +#include "tick_thread.h" +#include "tick_define.h" +#include "tick_epoll.h" + +class TickHb +{ +public: + TickHb(int hb_port); + + +private: + TickEpoll *tickEpoll_; + pthread_t thread_id_; + + /* + * The heartbeat servaddr and port information + * get the servaddr_ from the tick_server + * get the port from config file + */ + int sockfd_; + int flags_; + int hb_port_; + struct sockaddr_in servaddr_; + +}; + +#endif diff --git a/src/tick_hb.cc b/src/tick_hb.cc new file mode 100644 index 0000000000..3eb50ff2a9 --- /dev/null +++ b/src/tick_hb.cc @@ -0,0 +1,25 @@ +#include "tick_hb.h" + + +TickHb::TickHb(int hb_port) : + hb_port_(hb_port) +{ + thread_id_ = pthread_self(); + // init sock + sockfd_ = socket(AF_INET, SOCK_STREAM, 0); + memset(&servaddr_, 0, sizeof(servaddr_)); + + hb_port_ = g_tickConf->hb_port(); + servaddr_.sin_family = AF_INET; + servaddr_.sin_addr.s_addr = htonl(INADDR_ANY); + servaddr_.sin_port = htons(port_); + + bind(sockfd_, (struct sockaddr *) &servaddr_, sizeof(servaddr_)); + listen(sockfd_, 10); + + SetBlockType(kNonBlock); + /* + * inital the tickepoll object, add the notify_receive_fd to epoll + */ + tickEpoll_ = new TickEpoll(); +}