#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>#include <strstream>Go to the source code of this file.
Functions | |
| int | nvflock (int fd, int cmnd, int block) |
| nvtime_t | nvtime (nvtime_t *nvt) |
|
||||||||||||||||
|
Definition at line 20 of file NVcontainer.cc. References ASSERT, cmnd, and DEBUG. Referenced by NVcontainer::lock(), and NVcontainer::open().
00021 {
00022 #ifdef USE_FLOCK
00023 int ncmnd;
00024
00025 switch (cmnd) {
00026 case NVcontainer::UnLock:
00027 ncmnd = LOCK_UN;
00028 break;
00029 case NVcontainer::ShrdLock:
00030 ncmnd = LOCK_SH;
00031 break;
00032 case NVcontainer::ExclLock:
00033 ncmnd = LOCK_EX;
00034 break;
00035 default:
00036 DEBUG(cdbg << "myflockerr\n");
00037 return EINVAL;
00038 }
00039 if (block == NVList::NoBlock)
00040 ncmnd = ncmnd | LOCK_NB;
00041
00042 return flock(fd, ncmnd);
00043 #else
00044 int lck;
00045 struct flock ncmnd;
00046 int r;
00047
00048 switch (cmnd) {
00049 case NVcontainer::UnLock:
00050 ncmnd.l_type = F_UNLCK;
00051 break;
00052 case NVcontainer::ShrdLock:
00053 ncmnd.l_type = F_RDLCK;
00054 break;
00055 case NVcontainer::ExclLock:
00056 ncmnd.l_type = F_WRLCK;
00057 break;
00058 default:
00059 ASSERT(cerr << "myflockerr\n");
00060 return EINVAL;
00061 }
00062 ncmnd.l_whence = SEEK_SET;
00063 ncmnd.l_start = 0;
00064 ncmnd.l_len = 0;
00065 if (block == NVcontainer::NoBlock)
00066 lck = F_SETLK;
00067 else
00068 lck = F_SETLKW;
00069
00070 // Unlock, before applying the new lock
00071 if (ncmnd.l_type != F_UNLCK) {
00072 struct flock ulck;
00073 ulck.l_type = F_UNLCK;
00074 ulck.l_whence = SEEK_SET;
00075 ulck.l_start = 0;
00076 ulck.l_len = 0;
00077 if (fcntl(fd, lck, &ulck) < 0)
00078 return -1;
00079 }
00080 if ((r = fcntl(fd, lck, &ncmnd)) < 0) {
00081 if (errno == EACCES || errno == EAGAIN)
00082 errno = EWOULDBLOCK;
00083 return -1;
00084 }
00085 return 0;
00086 #endif
00087 }
|
|
|
Definition at line 89 of file NVcontainer.cc. References nvtime_t. Referenced by CServer::active_valid(), CServer::groupinfo(), GroupInfo::set(), GroupInfo::setfln(), NVActiveDB::sset(), and CNewsgroup::updateOverview().
00090 {
00091 time_t tm;
00092 nvtime_t nvtm;
00093
00094 time(&tm);
00095 nvtm = tm;
00096 if (nvt)
00097 *nvt = nvtm;
00098
00099 return nvtm;
00100 }
|
1.3.6-20040222