j123b567 / scpi-parser

Open Source SCPI device library
BSD 2-Clause "Simplified" License
447 stars 191 forks source link

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

Closed folkertvanheusden closed 1 year ago

folkertvanheusden commented 2 years ago

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

j123b567 commented 2 years ago

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)

folkertvanheusden commented 2 years ago

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!