/* * Function: write_progress * Description: Write a progress message. * NOTE: A single message when formatted should not exceed * 1000 bytes or it will cause corruptions and core dumps. * If a message needs to be longer than this, the * FMTPARTIAL format flag should be used on consecutive * message calls. * Scope: public * Parameters: dest - [RO] * [LOG - write only to the log file * SCR - write only to the display * LOGSCR - write to both the file and display] * specify where to record the message * format - [RO] * [LEVEL0 - base level message * LEVEL1 - first level message * LEVEL2 - second level message * LEVEL3 - third level message * CONTINUE - msg continuation from preceding message * LISTITEM - item type message * FMTPARTIAL - part of a message (more to come)] * format of the msg (used by the formatting routine). * string - [RO] * print format string * ... - [RO] * optional printf arguments * Return: none */ void /*VARARGS3*/ write_progress(u_char dest, u_int format, char *string, ...) { va_list ap; char buf[MAXPATHLEN + 1] = ""; va_start(ap, string); (void) vsprintf(buf, string, ap); _write_message(dest, PROGMSG, format, buf); va_end(ap); }
/* * Function: write_notice * Description: Write text data to the log file and the display. The * text should already be internationalized by the calling * routine. If the application has registered a display routine, * that routine should be used to present the text, otherwise * the display will be assumed to be stderr. * * NOTE: A single message when formatted should not exceed * 1000 bytes or it will cause corruptions and core dumps. * If a msg needs to be longer than this, the FMTPARTIAL * format flag should be used on consecutive message calls. * Scope: public * Parameters: type - [RO] * [ERRMSG - non-reconcilable problem * PROGMSG - progress * WARNMSG - advisory warning] * Notification type. * string - [RO] * print format string * ... - [RO] * optional printf arguments * Return: none */ void /*VARARGS2*/ write_notice(u_int type, char *string, ...) { va_list ap; char buf[MAXPATHLEN + 1] = ""; va_start(ap, string); (void) vsprintf(buf, string, ap); _write_message(LOG|SCR, type, LEVEL0, buf); va_end(ap); }
void tcp_basesession::run() { { boost::mutex::scoped_lock lock( m_mutex ); _write_message(); } if( m_isneedcat ) _check_action_time(); if( m_close_time ) { if( (unsigned int)time( NULL ) >= m_close_time ) { m_close_time = 0; this->close(); net_global::write_close_log( "IP:[%s] delay close", this->get_remote_address_string().c_str() ); } } if( m_close_time_if_no_data ) { if( m_father && (unsigned int)time( NULL ) >= m_close_time_if_no_data ) { m_close_time_if_no_data = 0; if( m_recv_size < 12 ) { { boost::mutex::scoped_lock lock( m_father->m_proc_mutex ); std::map<unsigned int, unsigned int>::iterator it = m_father->m_idleip.find( this->get_remote_address_ui() ); if( it != m_father->m_idleip.end() ) { if( ++it->second > 50 ) { m_father->m_idleip.erase( it ); m_father->add_ban_ip( this->get_remote_address_ui(), 3600, net_global::BAN_REASON_TOO_MANY_IDLE_CONNECTION ); } } else m_father->m_idleip[this->get_remote_address_ui()] = 1; } this->close(); net_global::write_close_log( "IP:[%s] close if no data recv size = %d", this->get_remote_address_string().c_str(), m_recv_size ); } } } }
/* * Function: write_debug * Description: * Print a standardly formatted debug output line. * There is a standard 'header' line format that can be generated * that will look something like: * Debug LIBSPMITTY -- "util.c", line 80 * Debug LIBSPMITTY -- "util.c", line 95 * And you can print just data lines like: * x = 32 * Scope: PUBLIC * Parameters: * dest - [RO] * [LOG - write only to the log file * SCR - write only to the display * LOGSCR - write to both the file and display] * debug_flag - Is debug actually turned on? If not - nothing is * printed. * who_called - A caller can use this to identify where this * debug output is coming from (e.g. each library and app * can have its own tag to easily distinguish where output * is coming from). * If who_called is NULL, then the header line of * output is not printed, and only the data line from the * format/var args is printed. * file_name - name of file the debug output request was called from. * Use macro __FILE__. * line_number - line number the debug output request was called from. * Use macro __LINE__. * format - [RO] * [LEVEL0 - base level message * LEVEL1 - first level message * LEVEL2 - second level message * LEVEL3 - third level message * CONTINUE - message continuation from preceding message * LISTITEM - item type message * FMTPARTIAL - part of a message (more to come)] * format of the message (used by the formatting routine) * fmtstr - format string to print any message you want. * Used to pass to vfprintf. * ... - var args to be used with format above to pass to vfprintf. * Return: none * Globals: none * Notes: * The defines, DEBUG_LOC and DEBUG_LOC_NOHD may be useful * to use as parameters when calling this routine. */ void write_debug(u_char dest, int debug_flag, char *who_called, char *file_name, int line_number, u_int format, char *fmtstr, ...) { va_list ap; char buf[MAXPATHLEN + 1] = ""; int old_trace_level; if (!debug_flag) return; old_trace_level = get_trace_level(); (void) set_trace_level(1); /* * if they specified a 'who_called', then * print first debug info line with who_called, function name, * file name, line number, etc... * * if no 'who_called', then * don't print first line with debug info. * i.e. so we can end up with debug output like: * Debug LIBSPMITTY -- "util.c", line 80: main() * x = 32 * y = 32 */ if (who_called) { (void) write_status(dest, LEVEL0, "Debug %s -- \"%s\", line %d", who_called, file_name ? file_name : "", line_number); } if (fmtstr) { va_start(ap, fmtstr); (void) vsprintf(buf, fmtstr, ap); _write_message(dest, STATMSG, format, buf); va_end(ap); } (void) set_trace_level(old_trace_level); }
void tcp_basesession::handle_write( const boost::system::error_code& error, int size, int block_idx ) { if( !is_valid() ) return; if( !error ) { { boost::mutex::scoped_lock lock( m_mutex ); m_is_sending_data = false; m_not_sent_size -= size; _write_message(); } #ifdef NET_FLOW_RATE_LOG m_send_size += size; #endif _record_action(); } else _on_close( error ); }
/* * Function: write_status_nofmt * Description: Write a status message. * * The difference between this and write_status is that * we DO NOT pass the string through vsprintf. * Callers who want to pass strings directly through to be printed * (e.g. from a child pkgadd) that may have "%" modifiers * in them should use this routine. If they use * write_status directly and it has a "%" modifier in it * then the app is bound to core dump because it will have * no data to also feed to the vsprintf. * (See bug 1267474 for an example of this happening). * * NOTE: Since we are not vsprintf'ing into an internal * buffer for these, the string passed in may be of * any length. * Scope: public * Parameters: dest - [RO] * [LOG - write only to the log file * SCR - write only to the display * LOGSCR - write to both the file and display] * specify where to record the message * format - [RO] * [LEVEL0 - base level message * LEVEL1 - first level message * LEVEL2 - second level message * LEVEL3 - third level message * CONTINUE - message continuation from preceding * message * LISTITEM - item type message * FMTPARTIAL - part of a message (more to come)] * format of the message (used by the formatting * routine). * Return: none */ void write_status_nofmt(u_char dest, u_int format, char *string) { _write_message(dest, STATMSG, format, string); }
/* * Function: write_notice_nofmt * Description: Write text data to the log file and the display. The * text should already be internationalized by the calling * routine. If the application has registered a display routine, * that routine should be used to present the text, otherwise * the display will be assumed to be stderr. * * The difference between this and write_notice is that * we DO NOT pass the string through vsprintf. * Callers who want to pass strings directly through to be printed * (e.g. from a child pkgadd) that may have "%" modifiers * in them should use this routine. If they use * write_notice directly and it has a "%" modifier in it * then the app is bound to core dump because it will have * no data to also feed to the vsprintf. * (See bug 1267474 for an example of this happening). * * NOTE: Since we are not vsprintf'ing into an internal * buffer for these, the string passed in may be of * any length. * Scope: public * Parameters: type - [RO] * [ERRMSG - non-reconcilable problem * PROGMSG - progress * WARNMSG - advisory warning] * Notification type. * string - [RO] * string to print * Return: none */ void write_notice_nofmt(u_int type, char *string) { _write_message(LOG|SCR, type, LEVEL0, string); }
/* * Function: write_message_nofmt * Description: Write text data to the log file and/or the display. * The text should already be internationalized by the calling * routine. If the application has registered a display routine, * that routine should be used to present the text, otherwise * the display will be assumed to be stdout. * * The difference between this and write_message is that * we DO NOT pass the string through vsprintf. * Callers who want to pass strings directly through to be printed * (e.g. from a child pkgadd) that may have "%" modifiers * in them should use this routine. If they use * write_message directly and it has a "%" modifier in it * then the app is bound to core dump because it will have * no data to also feed to the vsprintf. * (See bug 1267474 for an example of this happening). * * NOTE: Since we are not vsprintf'ing into an internal * buffer for these, the string passed in may be of * any length. * Scope: public * Parameters: dest - [RO] * [LOG - write only to the log file * SCR - write only to the display * LOGSCR - write to both the file and display] * Specify where to record the message. * type - [RO] * [STATMSG - status message * ERRMSG - non-reconcilable problem * PROGMSG - progress * WARNMSG - advisory warning] * Notification type. * format - [RO] * [LEVEL0 - base level message * LEVEL1 - first level message * LEVEL2 - second level message * LEVEL3 - third level message * CONTINUE - message continuation from preceding * message * LISTITEM - item type message * FMTPARTIAL - part of a message (more to come)] * format of the message (used by the formatting * routine). * string - [RO] * string to print * Return: none */ void write_message_nofmt(u_char dest, u_int type, u_int format, char *string) { _write_message(dest, type, format, string); }