F.9. para_msg_receive

Waits until an incoming message is available.

Synopsis. 

#include <parabellym/api.h>

int para_msg_receive(para_msgi_t *info);

Arguments. 

info
Receives information about the received message.

Access. 

Unrestricted.

Description. 

Call this functon to wait for new messages and receive them. The calling thread will block until a message or a signal is received.

A typical module's main thread spends the most of its time waiting in this call, which looks like this:

para_msgi_t info;

while (true) {
	switch (para_msg_receive(&info)) {
	case PEC_SUCCESS:
		// process the message...
		break;
	case PEC_MOD_SIGNAL:
		if (info.sig == PSIG_UNLOAD)
			return;
		// do additional work...
		break;
	}
};

Return value. 

PEC_SUCCESS
A message was successfully retreived.
PEC_MSGQ_BAD_ID
The current thread is not attached to a message queue, see para_msg_attach.
PEC_MOD_SIGNAL
The thread was unblocked by demand of another thread. The application-specific code with which the thread was awaken is stored in the signal member of the info structure.