void AppendFile::append(const char *data , size_t len) { size_t wn = write(data , len); ssize_t remain = len - wn; size_t totle = wn; int err; while(remain > 0) { wn = write(data , len); if(wn == 0) { if((err = ferror(fp_))) { fprintf(stderr , "append file failed , %s \n" , strerror_tl(err)); } break; } totle += wn; remain -= wn; } writen_ += len; }
void Connector::handleWrite() { LOG_TRACE << "Connector::handleWrite " << state_; if (state_ == kConnecting) { int sockfd = removeAndResetChannel(); int err = getSocketError(sockfd); if (err) { LOG_WARN << "Connector::handleWrite - SO_ERROR = " << err << " " << strerror_tl(err); retry(sockfd); } else if (isSelfConnect(sockfd)) { LOG_WARN << "Connector::handleWrite - Self connect"; retry(sockfd); } else { setState(kConnected); if (connect_) { new_conn_cb_(sockfd); } else { close(sockfd); } } } else { // what happened? assert(state_ == kDisconnected); } }
void Connector::handleError() { LOG_ERROR << "Connector::handleError state=" << state_; if (state_ == kConnecting) { int sockfd = removeAndResetChannel(); int err = getSocketError(sockfd); LOG_TRACE << "SO_ERROR = " << err << " " << strerror_tl(err); retry(sockfd); } }
Logger::Impl::Impl(LogLevel level, int savedErrno, const SourceFile &baseName, int line) : time_(Timestamp::now()), stream_(), level_(level), line_(line), baseName_(baseName) { formatTime(); CurrentThread::tid(); stream_ << T(CurrentThread::tidString(), 6); stream_ << T(LogLevelName[level], 6); if (savedErrno != 0) { stream_ << strerror_tl(savedErrno) << " (errno=" << savedErrno << ") "; } }