summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPixel <Pixel>2002-06-10 15:55:07 +0000
committerPixel <Pixel>2002-06-10 15:55:07 +0000
commita69ef2131749e05bb43106d48139638de0144f69 (patch)
treedc0579b2a759877676058af01fe829f1b385cc19 /lib
parent6cc9c2c329b00c51f399e5b040a4d4a1d1213ecd (diff)
Begin of the timeout handling.
Diffstat (limited to 'lib')
-rw-r--r--lib/TaskMan.cc57
1 files changed, 18 insertions, 39 deletions
diff --git a/lib/TaskMan.cc b/lib/TaskMan.cc
index 1bc8cd8..8cb2e8e 100644
--- a/lib/TaskMan.cc
+++ b/lib/TaskMan.cc
@@ -262,7 +262,22 @@ void TaskMan::MainLoop() throw (GeneralException) {
}
}
- /* Now is time to check all the handle and enters into a wait state. */
+ /* Let's compute the nearest timeout, and eventually, launch the outdated timeouts. */
+ int timeout = -1;
+ event = E_TIMEOUT;
+
+ if (!w4to.empty()) {
+ time_t curtime = time();
+ for (std::vector<w4to_t>::iterator p = w4to.begin(); p != w4to.end(); p++) {
+ int cur_to;
+ cur_to = (p->to.tv_sec - curtime) * 1000 + p->to.tv_usec;
+ if (cur_to < 0) {
+
+ }
+ }
+ }
+
+ /* Now is time to check all the handle and enter into a wait state. */
event = E_HANDLE;
// cerr << "-=- TaskMan: processing handle-waiting tasks.\n";
@@ -273,14 +288,8 @@ void TaskMan::MainLoop() throw (GeneralException) {
if (nfds != 0) {
int r;
std::vector<w4ha_t>::iterator p;
-#ifdef USE_POLL
struct pollfd * q;
-#else
- int highest;
- fd_set readfds, writefds, exceptfds;
-#endif
-#ifdef USE_POLL
ufsd = (struct pollfd *) malloc(nfds * sizeof(struct pollfd));
if (!w4ha.empty()) {
for (q = ufsd, p = w4ha.begin(); p != w4ha.end(); p++, q++) {
@@ -310,38 +319,17 @@ void TaskMan::MainLoop() throw (GeneralException) {
sigprocmask(SIG_UNBLOCK, &sigchildset, 0);
r = poll(ufsd, nfds, (no_burst) && !(Zombies.size()) && !(got_sigchild) ? -1: 0);
sigprocmask(SIG_BLOCK, &sigchildset, 0);
-#else
- FD_ZERO(readfds);
- FD_ZERO(writefds);
- FD_ZERO(exceptfds);
-
- highest = -1;
- for (p = w4ha.begin(); p && (p != w4ha.end()); p++) {
- if (p->T->IsStopped()) continue;
- if (p->flags & W4_READING) {
- FD_SET(p->ha->GetHandle(), readfds);
- }
- if (p->flags & W4_WRITING) {
- FD_SET(p->ha->GetHandle(), writefds);
- }
- FD_SET(p->ha->GetHandle(), exceptfds);
- }
-
- sigprocmask(SIG_UNBLOCK, &sigchildset, 0);
- r = select(highest + 1, &readfds, &writefds, &exceptfds, NULL);
- sigprocmask(SIG_BLOCK, &sigchildset, 0);
-#endif
+
if (r < 0) {
if (errno != EINTR) {
throw GeneralException(String(_("Error during poll: ")) + strerror(errno));
}
} else if (r == 0) {
- // timeout or child.
+ // timeout.
// **FIXME**
#warning FIXME
} else {
int fd;
-#ifdef USE_POLL
struct pollfd * q;
unsigned int i;
for (q = ufsd, i = 0; i < nfds; i++, q++) {
@@ -359,13 +347,6 @@ void TaskMan::MainLoop() throw (GeneralException) {
fd = q->fd;
if (q->revents & (POLLIN | POLLOUT | POLLERR | POLLHUP)) {
-#else
- /* Later perhaps... Let's use poll for now.
- The following is independant of the use of select or poll.
- Just have to set 'fd' to the changed handle. Two '{' to open with
- the first as the loop through the handles and the second with
- the test "if handle has changed" */
-#endif
// We have to look into the handle structure now...
bool touched;
if (!w4ha.empty()) {
@@ -403,9 +384,7 @@ void TaskMan::MainLoop() throw (GeneralException) {
}
}
}
-#ifdef USE_POLL
free((void *) ufsd);
-#endif
}
/* And finally, let's clean-up all the zombies around here. */