Publishing

Updated: April 19, 2023

To publish to a PPS object, a publisher simply calls open() for the object file with O_WRONLY to publish only, or O_RDWR to publish and subscribe. The publisher can then call write() to modify the object's attributes. This operation is nonblocking.

For a simple example, see Publishers in the Examples appendix.

When you write an attribute to the file, do so in a single operation. A single write() to an object is required to guarantee that simultaneous writes from multiple publishers can be handled correctly. For example, instead of this:

write( fd, "state::", 7);
if ( state == 0 )
   write( fd, "off", 3);
else
   write( fd, "on", 2);

do something like this:

snprintf( buf, sizeof(buf), "state::%s", state ? "on" : "off");
write( fd, buf, strlen(buf) );