0

I have a Labwindows server that listens for data from a python client on a remote machine. On the Labwindows server, whenever the TCP_DATAREADY event is fired, I read the buffer to get the data from the client. At this point I need to parse the data and update UI controls. However, since data arrives frequently, it is best if I can assign the task of parsing the data and updating UI controls to a different thread, so the server won't lose any data from the client.

I have thought of using thread safe queues in Labwindows. However, the data I get from the client is a string. How do I construct a queue which has string elements? I can't use pointers as the data received from the client is updated everytime data arrives.

Here is the piece of code that reads data from the socket:

case TCP_DATAREADY:
            if ((dataSize = ServerTCPRead (g_hconversation, receiveBuf,
                                           dataSize, 1000))
                < 0)
                {
                SetCtrlVal(g_hconversation, MAINPNL_TEXTBOX,"Receive Error");
        }
            else
                {
        //receiveBuff should be passed to function that decides where to display it
        display_value_from_client(receiveBuf);

                }

So, receiveBuf is constantly changing and saving pointers to it in the queue won't help. How do I implement threading here so my threads take care of the parsing functionality and I only need to worry about reading data from the socket in the main thread?

4

1 回答 1

1

执行此类线程间通信的“经典”方式是 malloc 接收缓冲区,在接收到数据后将缓冲区指针排队,并立即分配另一个接收缓冲区以用于下一次数据加载。您可以在 GUI 中处理它们后释放缓冲区指针。

这种方法意味着 UI 和网络线程永远不会在同一个缓冲区上运行,因此可以独立运行。

于 2013-08-16T16:12:42.063 回答