@@ -11,43 +11,43 @@ void handyUnregisterIdle(EventBase *base, const IdleId &idle);
1111void handyUpdateIdle (EventBase *base, const IdleId &idle);
1212
1313void TcpConn::attach (EventBase *base, int fd, Ip4Addr local, Ip4Addr peer) {
14- fatalif ((destPort_ <= 0 && state_ != State::Invalid) || (destPort_ >= 0 && state_ != State::Handshaking),
14+ hfatalif ((destPort_ <= 0 && state_ != State::Invalid) || (destPort_ >= 0 && state_ != State::Handshaking),
1515 " you should use a new TcpConn to attach. state: %d" , state_);
1616 base_ = base;
1717 state_ = State::Handshaking;
1818 local_ = local;
1919 peer_ = peer;
2020 delete channel_;
2121 channel_ = new Channel (base, fd, kWriteEvent | kReadEvent );
22- trace (" tcp constructed %s - %s fd: %d" , local_.toString ().c_str (), peer_.toString ().c_str (), fd);
22+ htrace (" tcp constructed %s - %s fd: %d" , local_.toString ().c_str (), peer_.toString ().c_str (), fd);
2323 TcpConnPtr con = shared_from_this ();
2424 con->channel_ ->onRead ([=] { con->handleRead (con); });
2525 con->channel_ ->onWrite ([=] { con->handleWrite (con); });
2626}
2727
2828void TcpConn::connect (EventBase *base, const string &host, unsigned short port, int timeout, const string &localip) {
29- fatalif (state_ != State::Invalid && state_ != State::Closed && state_ != State::Failed, " current state is bad state to connect. state: %d" , state_);
29+ hfatalif (state_ != State::Invalid && state_ != State::Closed && state_ != State::Failed, " current state is bad state to connect. state: %d" , state_);
3030 destHost_ = host;
3131 destPort_ = port;
3232 connectTimeout_ = timeout;
3333 connectedTime_ = util::timeMilli ();
3434 localIp_ = localip;
3535 Ip4Addr addr (host, port);
3636 int fd = socket (AF_INET, SOCK_STREAM, 0 );
37- fatalif (fd < 0 , " socket failed %d %s" , errno, strerror (errno));
37+ hfatalif (fd < 0 , " socket failed %d %s" , errno, strerror (errno));
3838 net::setNonBlock (fd);
3939 int t = util::addFdFlag (fd, FD_CLOEXEC);
40- fatalif (t, " addFdFlag FD_CLOEXEC failed %d %s" , t, strerror (t));
40+ hfatalif (t, " addFdFlag FD_CLOEXEC failed %d %s" , t, strerror (t));
4141 int r = 0 ;
4242 if (localip.size ()) {
4343 Ip4Addr addr (localip, 0 );
4444 r = ::bind (fd, (struct sockaddr *) &addr.getAddr (), sizeof (struct sockaddr ));
45- error (" bind to %s failed error %d %s" , addr.toString ().c_str (), errno, strerror (errno));
45+ herror (" bind to %s failed error %d %s" , addr.toString ().c_str (), errno, strerror (errno));
4646 }
4747 if (r == 0 ) {
4848 r = ::connect (fd, (sockaddr *) &addr.getAddr (), sizeof (sockaddr_in));
4949 if (r != 0 && errno != EINPROGRESS) {
50- error (" connect to %s error %d %s" , addr.toString ().c_str (), errno, strerror (errno));
50+ herror (" connect to %s error %d %s" , addr.toString ().c_str (), errno, strerror (errno));
5151 }
5252 }
5353
@@ -56,7 +56,7 @@ void TcpConn::connect(EventBase *base, const string &host, unsigned short port,
5656 if (r == 0 ) {
5757 r = getsockname (fd, (sockaddr *) &local, &alen);
5858 if (r < 0 ) {
59- error (" getsockname failed %d %s" , errno, strerror (errno));
59+ herror (" getsockname failed %d %s" , errno, strerror (errno));
6060 }
6161 }
6262 state_ = State::Handshaking;
@@ -90,7 +90,7 @@ void TcpConn::cleanup(const TcpConnPtr &con) {
9090 } else {
9191 state_ = State::Closed;
9292 }
93- trace (" tcp closing %s - %s fd %d %d" , local_.toString ().c_str (), peer_.toString ().c_str (), channel_ ? channel_->fd () : -1 , errno);
93+ htrace (" tcp closing %s - %s fd %d %d" , local_.toString ().c_str (), peer_.toString ().c_str (), channel_ ? channel_->fd () : -1 , errno);
9494 getBase ()->cancel (timeoutId_);
9595 if (statecb_) {
9696 statecb_ (con);
@@ -118,7 +118,7 @@ void TcpConn::handleRead(const TcpConnPtr &con) {
118118 int rd = 0 ;
119119 if (channel_->fd () >= 0 ) {
120120 rd = readImp (channel_->fd (), input_.end (), input_.space ());
121- trace (" channel %lld fd %d readed %d bytes" , (long long ) channel_->id (), channel_->fd (), rd);
121+ htrace (" channel %lld fd %d readed %d bytes" , (long long ) channel_->id (), channel_->fd (), rd);
122122 }
123123 if (rd == -1 && errno == EINTR) {
124124 continue ;
@@ -140,7 +140,7 @@ void TcpConn::handleRead(const TcpConnPtr &con) {
140140}
141141
142142int TcpConn::handleHandshake (const TcpConnPtr &con) {
143- fatalif (state_ != Handshaking, " handleHandshaking called when state_=%d" , state_);
143+ hfatalif (state_ != Handshaking, " handleHandshaking called when state_=%d" , state_);
144144 struct pollfd pfd;
145145 pfd.fd = channel_->fd ();
146146 pfd.events = POLLOUT | POLLERR;
@@ -150,13 +150,13 @@ int TcpConn::handleHandshake(const TcpConnPtr &con) {
150150 state_ = State::Connected;
151151 if (state_ == State::Connected) {
152152 connectedTime_ = util::timeMilli ();
153- trace (" tcp connected %s - %s fd %d" , local_.toString ().c_str (), peer_.toString ().c_str (), channel_->fd ());
153+ htrace (" tcp connected %s - %s fd %d" , local_.toString ().c_str (), peer_.toString ().c_str (), channel_->fd ());
154154 if (statecb_) {
155155 statecb_ (con);
156156 }
157157 }
158158 } else {
159- trace (" poll fd %d return %d revents %d" , channel_->fd (), r, pfd.revents );
159+ htrace (" poll fd %d return %d revents %d" , channel_->fd (), r, pfd.revents );
160160 cleanup (con);
161161 return -1 ;
162162 }
@@ -176,15 +176,15 @@ void TcpConn::handleWrite(const TcpConnPtr &con) {
176176 channel_->enableWrite (false );
177177 }
178178 } else {
179- error (" handle write unexpected" );
179+ herror (" handle write unexpected" );
180180 }
181181}
182182
183183ssize_t TcpConn::isend (const char *buf, size_t len) {
184184 size_t sended = 0 ;
185185 while (len > sended) {
186186 ssize_t wd = writeImp (channel_->fd (), buf + sended, len - sended);
187- trace (" channel %lld fd %d write %ld bytes" , (long long ) channel_->id (), channel_->fd (), wd);
187+ htrace (" channel %lld fd %d write %ld bytes" , (long long ) channel_->id (), channel_->fd (), wd);
188188 if (wd > 0 ) {
189189 sended += wd;
190190 continue ;
@@ -196,7 +196,7 @@ ssize_t TcpConn::isend(const char *buf, size_t len) {
196196 }
197197 break ;
198198 } else {
199- error (" write error: channel %lld fd %d wd %ld %d %s" , (long long ) channel_->id (), channel_->fd (), wd, errno, strerror (errno));
199+ herror (" write error: channel %lld fd %d wd %ld %d %s" , (long long ) channel_->id (), channel_->fd (), wd, errno, strerror (errno));
200200 break ;
201201 }
202202 }
@@ -219,7 +219,7 @@ void TcpConn::send(Buffer &buf) {
219219 }
220220 }
221221 } else {
222- warn (" connection %s - %s closed, but still writing %lu bytes" , local_.toString ().c_str (), peer_.toString ().c_str (), buf.size ());
222+ hwarn (" connection %s - %s closed, but still writing %lu bytes" , local_.toString ().c_str (), peer_.toString ().c_str (), buf.size ());
223223 }
224224}
225225
@@ -234,7 +234,7 @@ void TcpConn::send(const char *buf, size_t len) {
234234 output_.append (buf, len);
235235 }
236236 } else {
237- warn (" connection %s - %s closed, but still writing %lu bytes" , local_.toString ().c_str (), peer_.toString ().c_str (), len);
237+ hwarn (" connection %s - %s closed, but still writing %lu bytes" , local_.toString ().c_str (), peer_.toString ().c_str (), len);
238238 }
239239}
240240
@@ -250,7 +250,7 @@ void TcpConn::onMsg(CodecBase *codec, const MsgCallBack &cb) {
250250 con->channel_ ->close ();
251251 break ;
252252 } else if (r > 0 ) {
253- trace (" a msg decoded. origin len %d msg len %ld" , r, msg.size ());
253+ htrace (" a msg decoded. origin len %d msg len %ld" , r, msg.size ());
254254 cb (con, msg);
255255 con->getInput ().consume (r);
256256 }
@@ -269,20 +269,20 @@ int TcpServer::bind(const std::string &host, unsigned short port, bool reusePort
269269 addr_ = Ip4Addr (host, port);
270270 int fd = socket (AF_INET, SOCK_STREAM, 0 );
271271 int r = net::setReuseAddr (fd);
272- fatalif (r, " set socket reuse option failed" );
272+ hfatalif (r, " set socket reuse option failed" );
273273 r = net::setReusePort (fd, reusePort);
274- fatalif (r, " set socket reuse port option failed" );
274+ hfatalif (r, " set socket reuse port option failed" );
275275 r = util::addFdFlag (fd, FD_CLOEXEC);
276- fatalif (r, " addFdFlag FD_CLOEXEC failed" );
276+ hfatalif (r, " addFdFlag FD_CLOEXEC failed" );
277277 r = ::bind (fd, (struct sockaddr *) &addr_.getAddr (), sizeof (struct sockaddr ));
278278 if (r) {
279279 close (fd);
280- error (" bind to %s failed %d %s" , addr_.toString ().c_str (), errno, strerror (errno));
280+ herror (" bind to %s failed %d %s" , addr_.toString ().c_str (), errno, strerror (errno));
281281 return errno;
282282 }
283283 r = listen (fd, 20 );
284- fatalif (r, " listen failed %d %s" , errno, strerror (errno));
285- info (" fd %d listening at %s" , fd, addr_.toString ().c_str ());
284+ hfatalif (r, " listen failed %d %s" , errno, strerror (errno));
285+ hinfo (" fd %d listening at %s" , fd, addr_.toString ().c_str ());
286286 listen_channel_ = new Channel (base_, fd, kReadEvent );
287287 listen_channel_->onRead ([this ] { handleAccept (); });
288288 return 0 ;
@@ -292,7 +292,7 @@ TcpServerPtr TcpServer::startServer(EventBases *bases, const std::string &host,
292292 TcpServerPtr p (new TcpServer (bases));
293293 int r = p->bind (host, port, reusePort);
294294 if (r) {
295- error (" bind to %s:%d failed %d %s" , host.c_str (), port, errno, strerror (errno));
295+ herror (" bind to %s:%d failed %d %s" , host.c_str (), port, errno, strerror (errno));
296296 }
297297 return r == 0 ? p : NULL ;
298298}
@@ -307,16 +307,16 @@ void TcpServer::handleAccept() {
307307 socklen_t alen = sizeof (peer);
308308 int r = getpeername (cfd, (sockaddr *) &peer, &alen);
309309 if (r < 0 ) {
310- error (" get peer name failed %d %s" , errno, strerror (errno));
310+ herror (" get peer name failed %d %s" , errno, strerror (errno));
311311 continue ;
312312 }
313313 r = getsockname (cfd, (sockaddr *) &local, &alen);
314314 if (r < 0 ) {
315- error (" getsockname failed %d %s" , errno, strerror (errno));
315+ herror (" getsockname failed %d %s" , errno, strerror (errno));
316316 continue ;
317317 }
318318 r = util::addFdFlag (cfd, FD_CLOEXEC);
319- fatalif (r, " addFdFlag FD_CLOEXEC failed" );
319+ hfatalif (r, " addFdFlag FD_CLOEXEC failed" );
320320 EventBase *b = bases_->allocBase ();
321321 auto addcon = [=] {
322322 TcpConnPtr con = createcb_ ();
@@ -338,7 +338,7 @@ void TcpServer::handleAccept() {
338338 }
339339 }
340340 if (lfd >= 0 && errno != EAGAIN && errno != EINTR) {
341- warn (" accept return %d %d %s" , cfd, errno, strerror (errno));
341+ hwarn (" accept return %d %d %s" , cfd, errno, strerror (errno));
342342 }
343343}
344344
0 commit comments