Receiving Messages

For Win32 and OS/2

The method for receiving messages from the DMOD is illustrated in the following figure.

Receiving messages using a routing procedure

After DMOD initialization, the 3270 emulator registers the routing procedure by calling sepdrout. When the DMOD receives a message, it calls the 3270 emulator routing procedure, which can then process the message.

With this approach, there is no context switch between the DMOD thread and the 3270 emulator thread. However, the routing procedure must return control to the DMOD fairly quickly. For instance, it cannot suspend waiting for a keyboard input.

The application must determine whether the received message is for this application or for another application. If the message is not for this application, the routing procedure must return, indicating that the message was not processed. If the application processes the message, it is responsible for freeing the buffer when the processing is finished.

In some cases, the routing procedure can process the message to completion. An alternative is for the routing procedure to put the message on an application queue and then clear an application semaphore. The application can then subsequently process the message.

A further performance gain can be achieved by sending a Status-Resource message (to return credit to the local node, allowing it to send further data) from the routing procedure when a message is received, rather than waiting until the message is processed to completion. This usage is illustrated in Sample Code: Initialization and Routing Procedure. See Pacing and Chunking for more information on credit and flow control.

For Windows version 3.x

If an application wishes to schedule its main (noncallback) part on receipt of a message, it can do so by posting a Windows message to its WndProc.

For all operating systems

Note that after the application has received a message it is responsible for the buffer in which the message was received; it must either reuse the buffer to send a message (using sbpusend) or release it (using sepdburl). If the buffer to be reused does not contain the correct number of elements for the message to be sent, the application can obtain additional elements (using sbpibegt) or release existing ones (using sbpiberl); in this case, it must also ensure that the numelts field in the buffer header indicates the correct number of elements.