src/logcache.h File Reference

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void logcache_list (dbref player)
void logcache_init ()
void logcache_destruct ()
int logcache_writelog (char *fname, char *fdata)


Function Documentation

void logcache_destruct (  ) 

Definition at line 147 of file logcache.c.

References _logcache_destruct(), dprintk, logfiles, rb_destroy(), rb_walk(), and WALK_INORDER.

Referenced by main(), and shutdown_services().

00148 {
00149         dprintk("logcache destructing.");
00150         if(!logfiles) {
00151                 dprintk("logcache_destruct() CALLED WHILE UNITIALIZED!");
00152                 return;
00153         }
00154         rb_walk(logfiles, WALK_INORDER, _logcache_destruct, NULL);
00155         rb_destroy(logfiles);
00156         logfiles = NULL;
00157 }

void logcache_init (  ) 

Definition at line 130 of file logcache.c.

References dprintk, logcache_compare(), logfiles, and rb_init().

Referenced by logcache_writelog(), and main().

00131 {
00132         if(!logfiles) {
00133                 dprintk("logcache initialized.");
00134                 logfiles = rb_init(logcache_compare, NULL);
00135         } else {
00136                 dprintk("REDUNDANT CALL TO logcache_init()!");
00137         }
00138 }

void logcache_list ( dbref  player  ) 

Definition at line 85 of file logcache.c.

References _logcache_list(), logfiles, notify, rb_size(), rb_walk(), and WALK_INORDER.

Referenced by do_list().

00086 {
00087         notify(player, "/--------------------------- Open Logfiles");
00088         if(rb_size(logfiles) == 0) {
00089                 notify(player, "- There are no open logfile handles.");
00090                 return;
00091         }
00092         notify(player, "Filename                               Timeout");
00093         rb_walk(logfiles, WALK_INORDER, _logcache_list, &player);
00094 }

int logcache_writelog ( char *  fname,
char *  fdata 
)

Definition at line 159 of file logcache.c.

References logfile_t::ev, logfile_t::fd, logfile_t::filename, logcache_close(), logcache_init(), logcache_open(), LOGFILE_TIMEOUT, logfiles, and rb_find().

00160 {
00161         struct logfile_t *log;
00162         struct timeval tv = { LOGFILE_TIMEOUT, 0 };
00163         int len;
00164 
00165         if(!logfiles)
00166                 logcache_init();
00167 
00168         len = strlen(fdata);
00169 
00170         log = rb_find(logfiles, fname);
00171 
00172         if(!log) {
00173                 if(logcache_open(fname) < 0) {
00174                         return 0;
00175                 }
00176                 log = rb_find(logfiles, fname);
00177                 if(!log) {
00178                         return 0;
00179                 }
00180         }
00181 
00182         if(evtimer_pending(&log->ev, NULL)) {
00183                 event_del(&log->ev);
00184                 event_add(&log->ev, &tv);
00185         }
00186 
00187         if(write(log->fd, fdata, len) < 0) {
00188                 fprintf(stderr,
00189                                 "System failed to write data to file with error '%s' on logfile '%s'. Closing.\n",
00190                                 strerror(errno), log->filename);
00191                 logcache_close(log);
00192         }
00193         return 1;
00194 }


Generated on Mon May 28 04:25:45 2007 for BattletechMUX by  doxygen 1.4.7