direct-code-execution / ns-3-dce

Run real programs in the discrete time simulator ns3
http://www.nsnam.org/projects/direct-code-execution/
75 stars 46 forks source link

select used as sleep does not work #74

Open cwmos opened 6 years ago

cwmos commented 6 years ago

Some programs call select without any file descriptors as a sleep. This does not work with DCE. The following patch fixes this by calling Wait i this case:

diff --git a/model/dce-poll.cc b/model/dce-poll.cc
index 0cac665..9f5f728 100644
--- a/model/dce-poll.cc
+++ b/model/dce-poll.cc
@@ -128,11 +128,6 @@ int dce_poll (struct pollfd *fds, nfds_t nfds, int timeout)
   return count;
 }

-int dce___poll_chk (struct pollfd *fds, nfds_t nfds, int timeout, size_t fdslen)
-{
-  return dce_poll(fds, nfds, timeout);
-}
-
 int dce_select (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
                 struct timeval *timeout)
 {
@@ -146,18 +141,25 @@ int dce_select (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
       current->err = EINVAL;
       return -1;
     }
-  if (readfds == 0 && writefds == 0 && exceptfds == 0)
+  if (timeout)
+  {
+    if (timeout->tv_sec < 0 || timeout->tv_usec < 0)
     {
       current->err = EINVAL;
       return -1;
     }
-  if (timeout)
+  }
+  if (readfds == 0 && writefds == 0 && exceptfds == 0)
     {
-      if (timeout->tv_sec < 0 || timeout->tv_usec < 0)
+      if(!timeout) {
         {
           current->err = EINVAL;
           return -1;
         }
+      }
+      Time sleepTime = UtilsTimevalToTime(*timeout);
+      current->process->manager->Wait(sleepTime);
+      return 0;
     }
   for (int fd = 0; fd < nfds; fd++)
     {

Please let me know if I should make a pull request (I did not seem to have access to do this).

teto commented 6 years ago

looks ok. What program do you have in mind that exhibits such behavior ? feel free to open the PR