signal(SIGPIPE, SIG_IGN);
- VERIFY(gettimeofday(&create_time_, NULL) == 0);
+ create_time_ = std::chrono::steady_clock::now();
PollMgr::Instance()->add_callback(fd_, CB_RDONLY, this);
}
int
connection::compare(connection *another)
{
- if (create_time_.tv_sec > another->create_time_.tv_sec)
+ if (create_time_ > another->create_time_)
return 1;
- if (create_time_.tv_sec < another->create_time_.tv_sec)
- return -1;
- if (create_time_.tv_usec > another->create_time_.tv_usec)
- return 1;
- if (create_time_.tv_usec < another->create_time_.tv_usec)
+ if (create_time_ < another->create_time_)
return -1;
return 0;
}
ml.unlock();
PollMgr::Instance()->block_remove_fd(fd_);
ml.lock();
- }else{
+ } else {
if (wpdu_.solong == wpdu_.sz) {
- }else{
+ } else {
//should be rare to need to explicitly add write callback
PollMgr::Instance()->add_callback(fd_, CB_WRONLY, this);
while (!dead_ && wpdu_.solong >= 0 && wpdu_.solong < wpdu_.sz) {
sin.sin_port = htons(port);
tcp_ = socket(AF_INET, SOCK_STREAM, 0);
- if(tcp_ < 0){
+ if (tcp_ < 0) {
perror("tcpsconn::tcpsconn accept_loop socket:");
VERIFY(0);
}
setsockopt(tcp_, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes));
setsockopt(tcp_, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes));
- if(bind(tcp_, (sockaddr *)&sin, sizeof(sin)) < 0){
+ if (bind(tcp_, (sockaddr *)&sin, sizeof(sin)) < 0) {
perror("accept_loop tcp bind:");
VERIFY(0);
}
- if(listen(tcp_, 1000) < 0) {
+ if (listen(tcp_, 1000) < 0) {
perror("tcpsconn::tcpsconn listen:");
VERIFY(0);
}
s1, inet_ntoa(sin.sin_addr), ntohs(sin.sin_port));
connection *ch = new connection(mgr_, s1, lossy_);
- // garbage collect all dead connections with refcount of 1
- std::map<int, connection *>::iterator i;
- for (i = conns_.begin(); i != conns_.end();) {
- if (i->second->isdead() && i->second->ref() == 1) {
- jsl_log(JSL_DBG_2, "accept_loop garbage collected fd=%d\n",
- i->second->channo());
- i->second->decref();
- // Careful not to reuse i right after erase. (i++) will
- // be evaluated before the erase call because in C++,
- // there is a sequence point before a function call.
- // See http://en.wikipedia.org/wiki/Sequence_point.
- conns_.erase(i++);
- } else
- ++i;
- }
+ // garbage collect all dead connections with refcount of 1
+ std::map<int, connection *>::iterator i;
+ for (i = conns_.begin(); i != conns_.end();) {
+ if (i->second->isdead() && i->second->ref() == 1) {
+ jsl_log(JSL_DBG_2, "accept_loop garbage collected fd=%d\n",
+ i->second->channo());
+ i->second->decref();
+ // Careful not to reuse i right after erase. (i++) will
+ // be evaluated before the erase call because in C++,
+ // there is a sequence point before a function call.
+ // See http://en.wikipedia.org/wiki/Sequence_point.
+ conns_.erase(i++);
+ } else
+ ++i;
+ }
conns_[ch->channo()] = ch;
}
int max_fd = pipe_[0] > tcp_ ? pipe_[0] : tcp_;
try {
-
while (1) {
FD_ZERO(&rfds);
FD_SET(pipe_[0], &rfds);
}
catch (thread_exit_exception e)
{
- return;
}
}
connection *
connect_to_dst(const sockaddr_in &dst, chanmgr *mgr, int lossy)
{
- int s= socket(AF_INET, SOCK_STREAM, 0);
+ int s = socket(AF_INET, SOCK_STREAM, 0);
int yes = 1;
setsockopt(s, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes));
- if(connect(s, (sockaddr*)&dst, sizeof(dst)) < 0) {
+ if (connect(s, (sockaddr*)&dst, sizeof(dst)) < 0) {
jsl_log(JSL_DBG_1, "rpcc::connect_to_dst failed to %s:%d\n",
inet_ntoa(dst.sin_addr), (int)ntohs(dst.sin_port));
close(s);