Skip to content

Commit

Permalink
local
Browse files Browse the repository at this point in the history
  • Loading branch information
chenzongzhi committed Mar 13, 2015
1 parent 21d9414 commit c056777
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@

# Log path
log/


# third party
third
1 change: 1 addition & 0 deletions include/tick_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down
32 changes: 32 additions & 0 deletions include/tick_hb.h
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
25 changes: 25 additions & 0 deletions src/tick_hb.cc
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();
}

0 comments on commit c056777

Please sign in to comment.