0

I've been searching the web for quite a while now and I've come across a few answers here on SO, but they didn't really answer my questions.

Before I head on, these are some of the questions I checked out: Equivalence of WaitForSingleObject() & ResetEvent() in Linux, Linux/POSIX equivalent for Win32's CreateEvent, SetEvent, WaitForSingleObject, Linux WaitForSingleObject?

I'm currently porting proprietary code that was developed a few years ago to update our ECUs on our machines. The code was originally developed for WinCE (which is what runs on the terminals in the cabin and on the ECU itself).

Most of the code is ported, it compiles and links and I'm still implementing a new updater around the ported code, however there is one piece of the puzzle that is missing. I have a structure that contains HANDLEs. I've re-used these intptrs so I can use them to manage file descriptors, however the code requires WaitForSingleObject to wait on other HANDLEs.

if (WaitForSingleObject(updateStruct->abortEvent, 0) == WAIT_OBJECT_0)
{
    updateStruct->errorNumber = 0x0014L;
    return FALSE;
}

I've read a lot about using pthreads, I even found a library called pevents that supposedly translates WinAPI calls to POSIX calls, however most of the solutions I've found either require C++11 (which I can't use for reasons I'm not entirely sure of myself) or they're simply not implementable because I'm required to leave the code as intact as possible so it can be compiled/used on the original platform - so I can't simply switch from using HANDLEs.

Is there a relatively straightforward way to implement this kind of function with C++98/03? I could always pfusch it and just create a loop that loops for the amount of the timeout and run in to the timeout, but then the application won't work, so that's not really an option ;)

SimonC
  • 1,547
  • 1
  • 19
  • 43
  • @David Heffernan I've also looked at that question, and as you can tell by my answer I cannot use Pthreads, as I do not have any threads to work with. – SimonC Oct 24 '18 at 14:03
  • You don't need to have a thread to create an event. Of course, I'm assuming that `updateStruct->abortEvent` is a Win32 event. The name suggests that. Do you know what it is? What did you replace this object with in your POSIX port? – David Heffernan Oct 24 '18 at 14:04
  • It's a handle, sadly I don't know more. I only have this one source and header file to go off of. It's never set, and only required as a parameter in a function I don't need. To top it off, I know barely anything about the C++ WIn32 API. I'm okay with POSIX, fine with C#/.net, but Win32 really isn't my world. – SimonC Oct 24 '18 at 14:08
  • If you don't know what it is, then you can't possibly wait on it. If it is a condition variable, then the closure as a dupe is good. If you can't tell us what it is, then the question should be closed as off topic. So, let's leave it closed as a dupe. If you can find out what this thing is then you can ask a new question, or edit this one. – David Heffernan Oct 24 '18 at 14:12
  • Switching from using HANDLEs is probably the first thing you want to do even if there was no need to port anything. – user7860670 Oct 25 '18 at 09:46
  • Although I wanted to at first, the code is to remain as unchanged as possible, to ensure compatiblity with WIN32 for some reason. – SimonC Oct 25 '18 at 09:54
  • 1
    You still don't seem to know what `updateStruct->abortEvent` actually is. If you don't know, why do you think we can help you. It feels like you are attempting to port to POSIX without changing anything. That's obviously impossible. Perhaps that's the message that you need to take back to the people stopping you from doing your job properly. – David Heffernan Oct 25 '18 at 13:19
  • 1
    Well, the Win32 API is C, not C++ based.That said, assuming the application was actually developed as a c++ app using Win32, then it actually is quite easy to perform a limited cross platform compatibility library. None of the windows #includes will resolve on non windows platforms, on those platforms your project can reference an extra include search path that has your own implementations. In your own implementation you implement things like "HANDLE" as a c++ class that you specialize as a class that holds a fd, and another that holds a cond_var. – Chris Becke Oct 25 '18 at 18:20
  • 1
    Then you implement each of the entry points the app needs, that does a runtime type cast to the expected implementation and fail if the cast fails, or calls the relevant implementation method if the cast returns null. – Chris Becke Oct 25 '18 at 18:23

0 Answers0