OpenersNotesSection(Spacer1)Details

The urgent message handler function is called when WSTP receives an urgent message from the other end of the connection.

WSSetMessageHandler() returns 0 in the event of an error, and a nonzero value if the function succeeds.

Use (NonWLLink[WSError(), paclet:ref/c/WSError]) to retrieve the error code if WSSetMessageHandler() fails.

(NonWLLink[WSMessageHandlerObject, paclet:ref/c/WSMessageHandlerObject]) is a pointer to a function of the form void f((NonWLLink[WSLINK, paclet:ref/c/WSLINK]) link,int m1,int m2).

WSSetMessageHandler() is declared in the WSTP header file (RefLink[wstp.h, paclet:ref/file/wstp.h]).

OpenersPrimaryExamplesSection(Spacer1)Examples  (1)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

#include "wstp.h"


/* handle three common WSTP urgent messages */

void f(WSLINK lp, int msg, int arg)
{
	if(msg == WSInterruptMessage)
		{ /* generate an interrupt menu */ }
	else if(msg == WSAbortMessage)
		{ /* abort the current operation */ }
	else if(msg == WSTerminateMessage)
		{ /* shutdown the program */ }

	/* ... */
}


int main(int argc, char **argv)
{
	WSENV env;
	WSLINK link;
	int error;

	env = WSInitialize((char *)0);
	if(env == (WSENV)0)
		{ /* unable to initialize WSTP environment */ }

	link = WSOpenArgcArgv(env, argc, argv, &error);
	if(link == (WSLINK)0 || error != WSEOK)
		{ /* unable to create link */ }

	if(! WSSetMessageHandler(link, (WSMessageHandlerObject)f)
		{ /* unable to install message handler for link */ }

	/* ... */

	WSClose(link);
	WSDeinitialize(env);

	return 0;
}

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(NonWLLink[WSGetMessageHandler(), paclet:ref/c/WSGetMessageHandler])  ▪  (NonWLLink[WSPutMessage(), paclet:ref/c/WSPutMessage])  ▪  (NonWLLink[WSGetMessage(), paclet:ref/c/WSGetMessage])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[WSTP C API Developer Guide (Mac OS X), paclet:tutorial/WSTPDeveloperGuide-MacintoshOverview])}, {▪(RefLinkPlain[WSTP C API Developer Guide (Unix and Linux), paclet:tutorial/WSTPDeveloperGuide-UnixOverview])}, {▪(RefLinkPlain[WSTP C API Developer Guide (Windows), paclet:tutorial/WSTPDeveloperGuide-WindowsOverview])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Alphabetical Listing of WSTP C Functions, paclet:guide/AlphabeticalListingOfWSTPCFunctions])}, {▪(RefLinkPlain[Low-Level WSTP Operations, paclet:guide/LowLevelWSTPOperations])}})}})