aboutsummaryrefslogtreecommitdiffstats
path: root/lib/iowatch.cc
diff options
context:
space:
mode:
authorFritz Elfert <felfert@to.com>2000-08-07 23:42:40 +0000
committerFritz Elfert <felfert@to.com>2000-08-07 23:42:40 +0000
commit68d5fd192fee358ad195c32b47333f8f87ae13f2 (patch)
tree59f865b9679830a006c5c35fb13dcf8f81b85099 /lib/iowatch.cc
parent50dee0db8d5117ed3b9691140ceb02d8aac292d1 (diff)
downloadplptools-68d5fd192fee358ad195c32b47333f8f87ae13f2.tar.gz
plptools-68d5fd192fee358ad195c32b47333f8f87ae13f2.tar.bz2
plptools-68d5fd192fee358ad195c32b47333f8f87ae13f2.zip
General cleanup:
- Corrected some operators of bufferArray - Added more constructors to PsiTime - Added one more fallback for Timezone calculation in PsiTime - Use PsiTime in rfsv - Moved some common methods from rfsv16/32 to rfsv - Added more kdoc comments. - Made interface more robust (added const whereever possible, changed pointer arguments to references)
Diffstat (limited to 'lib/iowatch.cc')
-rw-r--r--lib/iowatch.cc68
1 files changed, 33 insertions, 35 deletions
diff --git a/lib/iowatch.cc b/lib/iowatch.cc
index 15e8ecf..df7be8e 100644
--- a/lib/iowatch.cc
+++ b/lib/iowatch.cc
@@ -30,48 +30,46 @@
#include "iowatch.h"
IOWatch::IOWatch() {
- num = 0;
- io = new int [MAX_IO];
+ num = 0;
+ io = new int [FD_SETSIZE];
}
IOWatch::~IOWatch() {
- delete [] io;
+ delete [] io;
}
-void IOWatch::addIO(int a) {
- int pos;
- for (pos = 0; pos < num && a < io[pos]; pos++);
- for (int i = num; i > pos; i--) io[i] = io[i-1];
- io[pos] = a;
- num++;
+void IOWatch::addIO(const int fd) {
+ int pos;
+ for (pos = 0; pos < num && fd < io[pos]; pos++);
+ if (io[pos] == fd)
+ return;
+ for (int i = num; i > pos; i--)
+ io[i] = io[i-1];
+ io[pos] = fd;
+ num++;
}
-void IOWatch::remIO(int a) {
- int pos;
- for (pos = 0; pos < num && a != io[pos]; pos++);
- if (pos != num) {
- num--;
- for (int i = pos; i <num; i++) io[i] = io[i+1];
- }
+void IOWatch::remIO(const int fd) {
+ int pos;
+ for (pos = 0; pos < num && fd != io[pos]; pos++);
+ if (pos != num) {
+ num--;
+ for (int i = pos; i <num; i++) io[i] = io[i+1];
+ }
}
-bool IOWatch::watch(long secs, long usecs) {
- if (num > 0) {
- fd_set iop;
- FD_ZERO(&iop);
- for (int i=0; i<num; i++) {
- FD_SET(io[i], &iop);
- }
- struct timeval t;
- t.tv_usec = usecs;
- t.tv_sec = secs;
- return select(io[0]+1, &iop, NULL, NULL, &t);
- }
- else {
- sleep(secs);
- usleep(usecs);
- }
- return false;
+bool IOWatch::watch(const long secs, const long usecs) {
+ if (num > 0) {
+ fd_set iop;
+ FD_ZERO(&iop);
+ for (int i = 0; i < num; i++)
+ FD_SET(io[i], &iop);
+ struct timeval t;
+ t.tv_usec = usecs;
+ t.tv_sec = secs;
+ return (select(io[0]+1, &iop, NULL, NULL, &t) > 0);
+ }
+ sleep(secs);
+ usleep(usecs);
+ return false;
}
-
-