How to Start a C++ Plugin That Listens On A Socket With A While Loop

I have a C++ plugin that is triggered by running:

[DllImport(“raas_plugin”)]
public static extern void start_ssp_client_raas_c_wrapper();

The C++ library listens on a zmq socket and listens for messages has a function to return those messages
[DllImport(“raas_plugin”)]
public static extern void return_new_messages(IntPtr messages);

I start the C++ plugin by running on Start()

raasThread = new Thread(() => {
start_ssp_client_raas_c_wrapper();
});
raasThread.Start();

Unity is interrupting the C++ thread and causing “Interrupted system call”

I know this isn’t exactly sanctioned by Unity, threading plugins, but I know it has been done before very well and shouldn’t be an issue if you set it up correctly.

How can I set up my C++ plugin so it doesn’t get suspended by Unity and cause “Interrupted system call”?

I’ve never run C++ code on anything but the main thread, eg. synchronously call / return.

But it certainly SEEMS like you should be able to!!!

To debug this, first up I would eliminate the raas library and make your own C++ code with a loop:

  • sleep for a second or two

  • do something you can observe (console out?)

Start that with your thread mechanism above and see what gives.

That way you can reason about if:

  • something the raas plugin is using is failing

or

  • if it’s just an interop issue.