This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

NRF9160 BSD socket "send function" isn't blocked.

I use BSD socket to send and receive messages to a TCP server over LTE network.

When I send multiple messages by using send() (with flags = 0) function, I get an EINPROGRESS error.
It seems that send() function is not blocked.


I'm currently using the v1.1.0 release.

How can I fix this problem?

  • Hi,

     

    There are certain use-cases where send() isn't blocking, which are mentioned in the changelog:

    http://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrfxlib/bsdlib/doc/CHANGELOG.html

     

    Could you share the routine that you're running?

     

    Kind regards,

    Håkon

  • ERROR_STATUS blocking_send(int sock, u8_t *buf, u32_t datalen, u32_t flags, uint32_t timeout)
    {
         u32_t offset = 0U;
         int ret;
         s64_t time_stamp = k_uptime_get();
         s64_t milliseconds_spent = 0;

         while ((offset < datalen)&&(milliseconds_spent <timeout))
                 {
                     ret = send(sock, buf + offset,
                                        MIN(4096, (datalen - offset)), flags);
                     if (ret < 0)
                        {
                            return -errno;
                         }

                        offset += ret;
                       milliseconds_spent += k_uptime_delta(&time_stamp);
                 }
           if(milliseconds_spent >= timeout)
                  return STATUS_TIMEOUT;
           return 0;
    }

  • Hi,

     

    If the socket is configured as non-blocking with setsockopt(), you can get EINPROGRESS back. This can also occur if another sequence is on-going, like getaddrinfo(), or when the memory is full for prior bsdlib versions (but, then you should get another return code), or the buffer size is too high. Are you using zephyr minimal libc, or newlibc? The errno.h is different on those. Could you post the raw errno that you are getting?

    Is this TLS based communication? If yes, then the buffer size should be reduced to max. 2k

    Kind regards,

    Håkon

  • I am using default library (minimal libc) and setsockopt is not used.

    My purpose is to send 50KB buffer to remote tcp server, currently without TLS, so the buffer is full.
    As I understand, there is no other process in background.
    (Can I send 50KB buffer with single tcp packet?)

    Meni

  • Hi,

     

    A UDP packet has a length field of 16 bits, so the theoretical max length is just shy of 64k. However, you are limited here by the maximum size of the bsdlib, which is 4k, as defined in bsd_limits.h::BSD_IP_MAX_MESSAGE_SIZE, so you'll have to split it into chunks.

    And on the IP layer It'll again be split into chunks (MTU size is normally 1280 bytes), but reassembled on the other end again.

    What is the raw errno-number that is returned?

    Is this behavior consistent, ie; it always happens?

     

    Kind regards,

    Håkon

Related