/* * C program to demonstrate the new features of the Mailbox driver * This program is a Mailbox WRITER. It assigns a WRITE_ONLY channel to the * mailbox. It's partner program is a Mailbox READER. */ #include #include #include /* Descriptor structure definitions */ #include /* LIB RTL symbol definitions */ #include /* RMS status code def'ns */ #include /* Standard C symbol definitions */ #include /* System Service status code def'ns */ #include /* CREMBX definitions */ #include /* ASSIGN definitions */ #include /* I/O definitions */ #define $ARRAY_DESCRIPTOR(name,size,array_name) \ char array_name[ size ]; \ struct dsc$descriptor_s name = \ { size, DSC$K_DTYPE_T, DSC$K_CLASS_S, array_name } void main(void) { #define max_msg_len 256 $DESCRIPTOR(mailbox_name_desc,"MAILBOX_EXAMPLE"); $DESCRIPTOR(prompt_string_desc, "DATA TO SEND TO MAILBOX( to terminate) >>>"); $ARRAY_DESCRIPTOR(write_buffer_desc,max_msg_len,write_buffer); int status, mailbox_channel, wait_efn; int true=1, false = 0; int MORE_ROOM_AST ( int ); struct io_status_block { /* I/O status block */ short int condition; short int count; int dev; } iosb; /* * Create a permanent mailbox with a WRITEONLY channel. It's logical name * will be entered into the LNM$PERMANENT_MAILBOX logical name table. */ sys$crembx(1,&mailbox_channel,0,0,0,0,&mailbox_name_desc,CMB$M_WRITEONLY); /* * Mark it for deletion */ sys$delmbx(mailbox_channel); /* * Loop forever, first waiting til a READ channel is assigned to the mailbox * and then write data until there is no more data to write. */ while (TRUE) { /* * Wait for a READER to assign a channel. If a READER is already * assigned, this will return immediatly. */ status = sys$qiow ( 0, mailbox_channel, IO$_SETMODE|IO$M_READERWAIT, &iosb, 0,0, 0,0,0,0,0,0); while (status) { write_buffer_desc.dsc$w_length = max_msg_len; status = lib$get_input( &write_buffer_desc, &prompt_string_desc, &write_buffer_desc.dsc$w_length); /* * If at end of file (user typed ) * then stop here. */ if (status == RMS$_EOF) sys$exit(SS$_NORMAL); /* Keep trying to write the message, until it fits in the mailbox * Note that if the NORSWAIT function modifier had been eliminated * below, then the ROOM_NOTIFY and the retry loop could have been * removed. ROOM_NOTIFY was used in this example simply to show * its' use. It would be more appropriately used when the program * has other things it can be working on, as opposed to the * example below in which the program is not doing anything except * WAITING for room in the mailbox. */ status = SS$_NOREADER; /* Force attempt to WRITE */ while (status != SS$_NORMAL) { status = sys$qiow( 0, mailbox_channel, IO$_WRITEVBLK|IO$M_READERCHECK|IO$M_NORSWAIT, &iosb, 0,0, write_buffer_desc.dsc$a_pointer, write_buffer_desc.dsc$w_length, 0,0,0,0); if (iosb.condition == SS$_NOREADER) sys$exit(SS$_NOREADER); if (status == SS$_MBFULL) { lib$get_ef(&wait_efn); sys$clref(wait_efn); sys$qiow ( 0, mailbox_channel, IO$_SETMODE|IO$M_MB_ROOM_NOTIFY, &iosb, 0,0, MORE_ROOM_AST,wait_efn,0,0,0,0); sys$waitfr(wait_efn); } } } } } int MORE_ROOM_AST(int efn_to_set) { sys$setef(efn_to_set); }