From 68d5fd192fee358ad195c32b47333f8f87ae13f2 Mon Sep 17 00:00:00 2001 From: Fritz Elfert Date: Mon, 7 Aug 2000 23:42:40 +0000 Subject: 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) --- lib/iowatch.cc | 68 ++++++++++++++++++++++++++++------------------------------ 1 file changed, 33 insertions(+), 35 deletions(-) (limited to 'lib/iowatch.cc') 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 0) { - fd_set iop; - FD_ZERO(&iop); - for (int i=0; i 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; } - - -- cgit v1.2.3