forked from OpenAtomFoundation/pika
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
chenzongzhi
committed
Mar 13, 2015
1 parent
21d9414
commit c056777
Showing
4 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,3 +29,7 @@ | |
|
||
# Log path | ||
log/ | ||
|
||
|
||
# third party | ||
third |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |