The order in which you return results to clients is important:
Do not interrupt a set of data rows with other kinds of results. Data rows must be sent one after another until the entire set has been sent to the client. For example, you cannot send a few rows, then send a message, then send more rows.
After you have sent all of the data rows (if any), you can send messages and status information to the client in any order.
At the end of a set of results, call srv_senddone to signal the end of the results.