bug fix: change netconn_write() argument from NETCONN_NOCOPY to NETCONN_COPY
Fix corrupted output when using chained queries and single queries with multiple return values. NETCONN_NOCOPY can only be used in cases like *IDN? where the buffer is const, which is used in tests and is probably why it hasn't been discovered.
netconn_write() documentation calling NETCONN_COPY "inefficient" may get people to generally avoid it, even if NETCONN_NOCOPY **cannot** be used, as is the case in SCPI_Write(). There would need to be a mechanism either for freeing buffers after use without copying, or one to ensure the corresponding tcp frame has been received by the client. Considering SCPI performance only really matters when low latency is key, or transfer of large amounts of block data is required - while at the same time the target has small amounts of memory and low performance - NETCONN_COPY is the obvious safe choice for this project.
"When passed the flag NETCONN_COPY the data is copied into internal buffers which are allocated for the data. This allows the data to be modified directly after the call, but is inefficient both in terms of execution time and memory usage. If the flag is not set then the data is not copied but rather referenced, and the NETCONN_NOCOPY manifest is provided for backwards compatibility. *The data must not be modified after the call*, since the data can be put on the retransmission queue for the connection, and stay there for an indeterminate amount of time."
| | |
| | | if (context->user_context != NULL) { |
| | | user_data_t * u = (user_data_t *) (context->user_context); |
| | | if (u->io) { |
| | | return (netconn_write(u->io, data, len, NETCONN_NOCOPY) == ERR_OK) ? len : 0; |
| | | return (netconn_write(u->io, data, len, NETCONN_COPY) == ERR_OK) ? len : 0; |
| | | } |
| | | } |
| | | return 0; |
| | |
| | | user_data_t * u = (user_data_t *) (context->user_context); |
| | | if (u->control_io) { |
| | | snprintf(b, sizeof (b), "SRQ%d\r\n", val); |
| | | return netconn_write(u->control_io, b, strlen(b), NETCONN_NOCOPY) == ERR_OK ? SCPI_RES_OK : SCPI_RES_ERR; |
| | | return netconn_write(u->control_io, b, strlen(b), NETCONN_COPY) == ERR_OK ? SCPI_RES_OK : SCPI_RES_ERR; |
| | | } |
| | | } |
| | | return SCPI_RES_OK; |