Add clarification to rmr_send_msg manual page 42/2142/1
authorE. Scott Daniels <daniels@research.att.com>
Thu, 2 Jan 2020 17:35:05 +0000 (12:35 -0500)
committerE. Scott Daniels <daniels@research.att.com>
Thu, 2 Jan 2020 17:35:05 +0000 (12:35 -0500)
The man page for rm_send_msg() did not emphisize the need for
the user programme to use the returned message pointer for
all future references. This change adds the clarification in
the text of the return value and adds a comment to the example
code.

Signed-off-by: E. Scott Daniels <daniels@research.att.com>
Change-Id: I14c21636eafb7b936ad0ba62b3ae621e6f74c50b

doc/src/man/rmr_send_msg.3.xfm

index 36812c0..50f4383 100644 (file)
@@ -1,6 +1,6 @@
 .if false
 ==================================================================================
-       Copyright (c) 2019 Nokia 
+       Copyright (c) 2019 Nokia
        Copyright (c) 2018-2019 AT&T Intellectual Property.
 
    Licensed under the Apache License, Version 2.0 (the "License");
@@ -24,7 +24,7 @@
 .fi
 
 .gv e LIB lib
-.im &{lib}/man/setup.im 
+.im &{lib}/man/setup.im
 
 &line_len(6i)
 
@@ -42,42 +42,52 @@ rmr_mbuf_t* rmr_send_msg( void* vctx, rmr_mbuf_t* msg );
 &uindent
 
 &h2(DESCRIPTION)
-The &cw(rmr_send_msg) function accepts a message buffer from the user application 
+The &cw(rmr_send_msg) function accepts a message buffer from the user application
 and attempts to send it.
 The destination of the message is selected based on the message type specified
 in the message buffer, and the matching information in the routing tables
-which are currently in use by the RMR library. 
+which are currently in use by the RMR library.
 This may actually result in the sending of the message to multiple destinations
-which could degrade expected overall performance of the user application. 
+which could degrade expected overall performance of the user application.
 (Limiting excessive sending of messages is the responsibility of the application(s)
-responsible for building the routing table used by the RMR library, and not the 
+responsible for building the routing table used by the RMR library, and not the
 responsibility of the library.)
 
 
 .** pull in common retry text
-.im &{lib}/man/retry.im 
+.im &{lib}/man/retry.im
 
 
 &h2(RETURN VALUE)
 On success, a new message buffer, with an empty payload, is returned for the application
 to use for the next send.
-The state in this buffer will reflect the overall send operation state and should be
-&cw(RMR_OK.)
+The state in this buffer will reflect the overall send operation state and will be
+&cw(RMR_OK) when the send was successful.
 
 &space
-When the message cannot be successfully sent this function will return the unsent (original) 
-message buffer with the state set to indicate the reason for failure.  
+When the message cannot be successfully sent this function will return the unsent (original)
+message buffer with the state set to indicate the reason for failure.
 The value of &ital(errno) may also be set to reflect a more detailed failure reason if it
 is known.
 
 &space
-In the event of extreme failure, a NULL pointer is returned. In this case the value of 
-&cw(errno) might be of some use, for documentation, but there will be little that the 
+In the event of extreme failure, a NULL pointer is returned. In this case the value of
+&cw(errno) might be of some use, for documentation, but there will be little that the
 user application can do other than to move on.
 
+.sp 1
+&bold(CAUTION^:)
+In some cases it is extremely likely that the message returned by the send function
+does  &bold(not) reference the same memory structure.
+Thus is important for the user programme to capture the new pointer for future use
+or to be passed to &cw(rmr_free().)
+If you are experiencing either double free errors or segment faults in either &cw(rmr_free()) or
+&cw(rmr_send_msg(),) ensure that the return value from this function is being captured
+and used.
+
 &h2(ERRORS)
 The following values may be passed back in the &ital(state) field of the returned message
-buffer. 
+buffer.
 
 &space
 &beg_dlist(.75i : ^&bold_font )
@@ -147,21 +157,21 @@ eliminating alloc/free cycles.
 
        // reference payload and fill in message type
     pm = (msg_t*) send_msg->payload;
-    send_msg->mtype = MT_ANSWER;               
+    send_msg->mtype = MT_ANSWER;
 
-    msg->len = generate_data( pm );            // something that fills the payload in
-    msg = rmr_send_msg( mr, send_msg );
+    msg->len = generate_data( pm );       // something that fills the payload in
+    msg = rmr_send_msg( mr, send_msg );   // ensure new pointer used after send
        if( ! msg ) {
                return ERROR;
        } else {
                if( msg->state != RMR_OK ) {
-                       // check for eagain, and resend if needed
+                       // check for RMR_ERR_RETRY, and resend if needed
                        // else return error
                }
        }
 
        return OK;
-                       
+
 &ex_end