Skip to content

Commit

Permalink
Updating lab1. Details about the update are availabe on Piazza, if ne…
Browse files Browse the repository at this point in the history
…cessary.
  • Loading branch information
ydmao committed Feb 16, 2012
1 parent f7a0992 commit 84bb67d
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions rpc/connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -371,13 +371,18 @@ tcpsconn::process_accept()

// garbage collect all dead connections with refcount of 1
std::map<int, connection *>::iterator i;
for (i = conns_.begin(); i != conns_.end(); 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();
conns_.erase(i);
}
// 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;
Expand Down

0 comments on commit 84bb67d

Please sign in to comment.