IPC messaging example

One way to achieve inter-process communication is to use IPC messages like shown here.

Compilation

Easiest way to get this example running is to go to examples directory in package root, and run:

$ ./build.sh ipc_message

build.sh script compiles Ano script to C, copies source files in place and pops up instructions what to do next. Follow them. Check also examples/README for more info.

Preview

; ------------------------------------------------------------------------------
; ipc_message.ano
;
; To compile:
;
; $ ./build/ano ./examples/ipc_message/ipc_message.ano > \
;     engine/dsl_ano.h
; ------------------------------------------------------------------------------
;
@ANO_SCRIPT_NAME		ipc_message
@ANO_SCRIPT_VERSION		0.0.1
@ANO_SCRIPT_DESCRIPTION	Simple interprocess message send/receive example
;
@ANO_FLAGS_USE_PROTOS		[ ]
@ANO_FLAGS_VAR_NAME_SUBS	[ ]
@ANO_FLAGS_VAR_WARN_UNUSED	[ ]
;
; Copyright © 2016-2026, Jani Salonen <salojan@goto10.co>
; All rights reserved.
;
; One way to achieve inter-process communication is to use IPC messages like
; shown here.
;

main [exit: 0] {
	msg_receive (\
		queue:		"my_queue", \
		callback:	"msg_cb")

	; Message length is zero which is automatically corrected to actual
	; length of the message.
	;
	msg_send (\
		queue:		"my_queue", \
		message:	"This is interprocess message.", \
		message_length:	0, \
		message_prio:	0)

	; Sleep one second to make sure message is printed.
	;
	sleep (secs: 1, nanosecs: 0)

	; Autoremove attribute in callback function takes care of removing the
	; queue. It is ok if there is no more than one message as in this
	; example, because queue is removed just after first message is
	; processed. Otherwise it should be removed manually using msg_remove()
	; call.
	;
	;msg_remove (\
	;	queue:		"my_queue")
}

_MSG_RECEIVE_ contact msg_cb [autoremove: _queue] (\
	_queue, _msg, _msg_len) {

	dump _queue
	dump _msg
	dump _msg_len
}
; ------------------------------------------------------------------------------
; ipc_message.w2c
;
; To compile:
;
; $ ./build/widget ./examples/ipc_message/ipc_message.w2c > \
;     engine/widget_defs.h
; ------------------------------------------------------------------------------
; ------------------------------------------------------------------------------
; ipc_message.m2c
;
; To compile:
;
; $ ./build/menu ./examples/ipc_message/ipc_message.m2c > \
;     engine/menu_defs.h
; ------------------------------------------------------------------------------

Copyright © 2026, Jani Salonen <salojan at goto10 piste co>. Piste is finnish word and means dot. All rights reserved.