scpi-parser icon indicating copy to clipboard operation
scpi-parser copied to clipboard

see issue #131 (problem talking to sigrok over tcp)

Open folkertvanheusden opened this issue 3 years ago • 2 comments

The problem of the fragmented *IDN? response can be mitigated somewhat by enabling nagle during the response to that command.

folkertvanheusden avatar Nov 18 '21 21:11 folkertvanheusden

I can't test it in now, but isn't it also necessary to explicitly flush the output so we are sure, that the concatenated message is send immediately?

https://stackoverflow.com/questions/855544/is-there-a-way-to-flush-a-posix-socket

Also in case of Linux, TCP_CORK would be probably a better choice. (And subsequent toggeling in flush callback)

j123b567 avatar Nov 19 '21 07:11 j123b567

I've tested in a toy-project of mine, and TCP_CORK also solves it:

size_t SCPI_Write(scpi_t * context, const char * data, size_t len) {
        if (context->user_context != NULL) {
                int fd = ((audio_dev_t *)context->user_context)->fd;

                int state = 1;
                setsockopt(fd, IPPROTO_TCP, TCP_CORK, &state, sizeof(state));

                return write(fd, data, len);
        }

        return 0;
}

scpi_result_t SCPI_Flush(scpi_t * context) {
        if (context->user_context != NULL) {
                int fd = ((audio_dev_t *)context->user_context)->fd;

                int state = 0;
                setsockopt(fd, IPPROTO_TCP, TCP_CORK, &state, sizeof(state));
        }

        return SCPI_RES_OK;
}

Thanks for the help!

folkertvanheusden avatar Nov 19 '21 07:11 folkertvanheusden