Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

NVcontainer.cc File Reference

#include "NVcontainer.h"
#include "Error.h"
#include <iostream>
#include <fcntl.h>
#include <stdio.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <time.h>

Go to the source code of this file.

Functions

int nvflock (int fd, int cmnd, int block)
nvtime_t nvtime (nvtime_t *nvt)


Function Documentation

int nvflock int  fd,
int  cmnd,
int  block
 

Definition at line 14 of file NVcontainer.cc.

References ASSERT, cmnd, and DEBUG.

Referenced by NVcontainer::lock(), and NVcontainer::open().

00015 {
00016 #ifdef USE_FLOCK
00017         int ncmnd;
00018 
00019         switch (cmnd) {
00020         case NVcontainer::UnLock:
00021                 ncmnd = LOCK_UN;
00022                 break;
00023         case NVcontainer::ShrdLock:
00024                 ncmnd = LOCK_SH;
00025                 break;
00026         case NVcontainer::ExclLock:
00027                 ncmnd = LOCK_EX;
00028                 break;
00029         default:
00030                 DEBUG(cdbg << "myflockerr\n");
00031                 return EINVAL;
00032         }
00033         if (block == NVList::NoBlock)
00034                 ncmnd = ncmnd | LOCK_NB;
00035 
00036         return flock(fd, ncmnd);
00037 #else
00038         int lck;
00039         struct flock ncmnd;
00040         int r;
00041 
00042         switch (cmnd) {
00043         case NVcontainer::UnLock:
00044                 ncmnd.l_type = F_UNLCK;
00045                 break;
00046         case NVcontainer::ShrdLock:
00047                 ncmnd.l_type = F_RDLCK;
00048                 break;
00049         case NVcontainer::ExclLock:
00050                 ncmnd.l_type = F_WRLCK;
00051                 break;
00052         default:
00053                 ASSERT(cerr << "myflockerr\n");
00054                 return EINVAL;
00055         }
00056         ncmnd.l_whence = SEEK_SET;
00057         ncmnd.l_start = 0;
00058         ncmnd.l_len = 0;
00059         if (block == NVcontainer::NoBlock)
00060                 lck = F_SETLK;
00061         else
00062                 lck = F_SETLKW;
00063 
00064         // Unlock, before applying the new lock
00065         if (ncmnd.l_type != F_UNLCK) {
00066                 struct flock ulck;
00067                 ulck.l_type = F_UNLCK;
00068                 ulck.l_whence = SEEK_SET;
00069                 ulck.l_start = 0;
00070                 ulck.l_len = 0;
00071                 if (fcntl(fd, lck, &ulck) < 0)
00072                         return -1;
00073         }
00074         if ((r = fcntl(fd, lck, &ncmnd)) < 0) {
00075                 if (errno == EACCES || errno == EAGAIN)
00076                         errno = EWOULDBLOCK;
00077                 return -1;
00078         }
00079         return 0;
00080 #endif
00081 }

nvtime_t nvtime nvtime_t nvt  ) 
 

Definition at line 83 of file NVcontainer.cc.

References nvtime_t.

Referenced by CServer::active_valid(), CServer::groupinfo(), GroupInfo::set(), GroupInfo::setfln(), NVActiveDB::sset(), and CNewsgroup::updateOverview().

00084 {
00085         time_t tm;
00086         nvtime_t nvtm;
00087 
00088         time(&tm);
00089         nvtm = tm;
00090         if (nvt)
00091                 *nvt = nvtm;
00092 
00093         return nvtm;
00094 }


Generated on Fri Aug 20 10:58:09 2004 for NewsCache by doxygen 1.3.6-20040222