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

Non-blocking UDP socket (fcntl error: ENOTSOCK - argument is not a socket)

Hello, I'm working on programming a cycle to measure the power consumption. I need to send a message and wait for a response for some time, then shut the modem off, no matter if there was a response or not. The recvfrom function is going to wait for a response indefinitely, so I'm trying to make it non-blocking by setting the O_NONBLOCK flag, without success. Here's what I tried, this is edited NTP sample to ensure it works fine:

int client_fd = socket(AF_INET, SOCK_DGRAM, 0);
printk("client_fd: %d\n\r", client_fd);

int flags = fcntl(client_fd, F_GETFL);
printk("Flags = %d\n Errno = %d\n", flags, errno);

fcntl(client_fd, F_SETFL, flags | O_NONBLOCK);
printk("Flags = %d\n Errno = %d\n", flags, errno);

this is the response:

client_fd: 2
Flags = -1
Errno = 88
Flags = -1
Errno = 88

so basically the socket opening function works fine, but somehow the fcntl doesn't recognize just opened socket descriptor. The program goes all the way down to the recvfrom function and the bind/send functions work fine with the same socket:

bind err: 0
sendto ret: 48

I've also tried to do it with setsockopt:

 struct timeval tv;
 tv.tv_sec = 1;  /* 1 Secs Timeout */
setsockopt(client_fd, SOL_SOCKET, SO_RCVTIMEO,(struct timeval *)&tv,sizeof(struct timeval));

but the response is the same, indicating that there's a problem with the socket descriptor. Any of these lines don't change the behavior at all, it's just waiting for response indefinitely.

Firmware: 1.0.0
Board v0.7.0
SES V4.16 Nordic Edition (64-bit)

Parents
  • Hi,

     

    It returned 0 here:

    ***** Booting Zephyr OS v1.14.99-ncs2 *****
    getaddrinfo err: 0
    client_fd: 3
    Flags = 0 Errno = 0
    Flags = 0 Errno = 0

     fcntl was offloaded in nrf91_sockets.c back in march. Have you checked out the latest nrfxlib and so forth?

    cd ncs/nrf
    git checkout master
    git pull
    git checkout v1.0.0
    west update

     

    Kind regards,

    Håkon

  • Apparently there was an update needed:

    C:\ncs\nrf>git checkout -f master
    Previous HEAD position was f925102 manifest: Updated manifest to use D4 release tags.
    Switched to branch 'master'
    Your branch is behind 'origin/master' by 59 commits, and can be fast-forwarded.
      (use "git pull" to update your local branch)
    
    C:\ncs\nrf>git pull
    remote: Enumerating objects: 12, done.
    remote: Counting objects: 100% (12/12), done.
    remote: Compressing objects: 100% (7/7), done.
    remote: Total 12 (delta 5), reused 5 (delta 5), pack-reused 0
    Unpacking objects: 100% (12/12), done.
    From https://github.com/NordicPlayground/fw-nrfconnect-nrf
       f88b4bd..7d7f70d  master     -> origin/master
    Updating ffd48bf..7d7f70d
    Fast-forward
     applications/asset_tracker/Kconfig                 |   7 +
     applications/asset_tracker/prj.conf                |   5 +
     .../asset_tracker/prj_nrf9160_pca20035ns.conf      |   5 +
     applications/asset_tracker/prj_qemu_x86.conf       |   5 +
     applications/asset_tracker/src/main.c              |  63 +++-
     applications/asset_tracker/src/ui/nmos.c           |  35 ++-
     .../configuration/common/hid_report_desc.c         |  49 +--
     .../configuration/common/hid_report_desc.h         |   7 +-
     .../nrf_desktop/configuration/common/led_effect.h  |  33 ++
     .../nrf_desktop/configuration/common/led_state.h   |  11 +
     .../nrf52810_pca20045/app_ZDebug.conf              |   6 +
     .../nrf52810_pca20045/app_ZRelease.conf            |   6 +
     .../nrf52840_pca10056/app_ZDebug.conf              |   5 +
     .../nrf52840_pca10056/app_ZDebugWithShell.conf     |   5 +
     .../nrf52840_pca10056/app_ZRelease.conf            |   5 +
     .../nrf52840_pca10056/led_state_def.h              |   2 +-
     .../nrf52840_pca10059/app_ZDebug.conf              |  11 +-
     .../nrf52840_pca10059/app_ZDebugMCUBoot.conf       |  11 +-
     .../nrf52840_pca10059/app_ZDebugWithShell.conf     |  11 +-
     .../nrf52840_pca10059/app_ZRelease.conf            |  11 +-
     .../nrf52840_pca10059/app_ZReleaseMCUBoot.conf     |  11 +-
     .../nrf52840_pca10059/led_state_def.h              |   2 +-
     .../nrf52840_pca10059/mcuboot_ZDebugMCUBoot.conf   |   5 +
     .../nrf52840_pca10059/mcuboot_ZReleaseMCUBoot.conf |   5 +
     .../nrf52840_pca20041/app_ZDebug.conf              |   5 +
     .../nrf52840_pca20041/app_ZDebugMCUBoot.conf       |   5 +
     .../nrf52840_pca20041/app_ZDebugWithShell.conf     |   5 +
     .../nrf52840_pca20041/app_ZRelease.conf            |   5 +
     .../nrf52840_pca20041/app_ZReleaseMCUBoot.conf     |   5 +
     .../nrf52840_pca20041/led_state_def.h              |   2 +-
     .../nrf52840_pca20041/mcuboot_ZDebugMCUBoot.conf   |   5 +
     .../nrf52840_pca20041/mcuboot_ZReleaseMCUBoot.conf |   5 +
     .../configuration/nrf52_pca20037/app_ZDebug.conf   |  13 +-
     .../nrf52_pca20037/app_ZDebugMCUBoot.conf          |  13 +-
     .../nrf52_pca20037/app_ZDebugWithShell.conf        |  13 +-
     .../configuration/nrf52_pca20037/app_ZRelease.conf |  13 +-
     .../nrf52_pca20037/app_ZReleaseMCUBoot.conf        |  13 +-
     .../configuration/nrf52_pca20037/hid_keymap_def.h  | 228 +++++++-------
     .../configuration/nrf52_pca20037/led_state_def.h   |  19 +-
     .../nrf52_pca20037/mcuboot_ZDebugMCUBoot.conf      |   5 +
     .../nrf52_pca20037/mcuboot_ZReleaseMCUBoot.conf    |   5 +
     .../configuration/nrf52_pca20044/app_ZDebug.conf   |   6 +
     .../configuration/nrf52_pca20044/app_ZRelease.conf |   6 +
     applications/nrf_desktop/src/events/Kconfig        |   4 +
     applications/nrf_desktop/src/events/config_event.h |   9 +-
     applications/nrf_desktop/src/events/hid_event.c    |  34 ++-
     applications/nrf_desktop/src/events/hid_event.h    |  11 +
     .../nrf_desktop/src/hw_interface/buttons.c         | 102 ++++---
     .../nrf_desktop/src/hw_interface/motion_buttons.c  |   4 +-
     applications/nrf_desktop/src/modules/ble_bond.c    |  67 ++---
     applications/nrf_desktop/src/modules/ble_scan.c    | 138 +++++----
     applications/nrf_desktop/src/modules/ble_state.c   |  38 ++-
     applications/nrf_desktop/src/modules/dfu.c         | 187 ++++++++----
     applications/nrf_desktop/src/modules/hid_forward.c | 216 +++++++++++---
     applications/nrf_desktop/src/modules/hid_state.c   | 151 ++++++++--
     applications/nrf_desktop/src/modules/usb_state.c   | 150 +++++++++-
     applications/nrf_desktop/src/services/Kconfig      |   9 +-
     applications/nrf_desktop/src/services/hids.c       |  80 ++++-
     boards/arm/nrf52810_pca20045/Kconfig               |   5 -
     boards/arm/nrf52810_pca20045/nrf52810_pca20045.dts |   2 +-
     doc/CMakeLists.txt                                 |   5 +
     doc/nrf/conf.py                                    |   4 +-
     doc/nrf/gs_programming.rst                         |  18 +-
     doc/nrf/images/ses_config.png                      | Bin 52500 -> 23444 bytes
     doc/nrf/index.rst                                  |   1 +
     doc/nrf/links.txt                                  |   8 +
     doc/nrf/release_notes.rst                          |   1 +
     doc/nrfxlib/conf.py                                |   4 +-
     doc/release-notes-1.0.0.rst                        | 331 +++++++++++++++++++++
     drivers/at_cmd/at_cmd.c                            |   2 +-
     .../clock_control/clock_control_ll_nrfxlib.c       |  77 +++--
     drivers/sensor/pmw3360/pmw3360.c                   |  12 +-
     drivers/st25r3911b/st25r3911b_nfca.c               |   4 +
     include/bluetooth/services/nus.h                   |  14 +
     include/drivers/st25r3911b_nfca.h                  |   4 +
     include/modem_info.h                               |   4 +
     include/{ => net}/download_client.h                |  35 ++-
     include/{ => net}/download_client.rst              |  16 +-
     include/net/fota_download.h                        |   2 +-
     include/nfc/ndef/le_oob_rec.h                      | 137 +++++++++
     include/nfc/ndef/le_oob_rec.rst                    |  31 ++
     include/nfc/ndef/nfc.rst                           |   1 +
     lib/at_host/at_host.c                              |   4 +-
     lib/bsdlib/bsd_os.c                                |  29 +-
     lib/bsdlib/bsdlib.c                                |  23 +-
     lib/modem_info/CMakeLists.txt                      |   2 +-
     lib/modem_info/modem_info_params.c                 |   1 -
     samples/bluetooth/central_bas/CMakeLists.txt       |   5 +
     samples/bluetooth/central_bas/prj.conf             |   5 +
     samples/bluetooth/central_dfu_smp/CMakeLists.txt   |   5 +
     samples/bluetooth/central_dfu_smp/prj.conf         |   5 +
     samples/bluetooth/central_hids/CMakeLists.txt      |   5 +
     samples/bluetooth/central_hids/prj.conf            |   5 +
     .../peripheral_hids_keyboard/CMakeLists.txt        |   5 +
     samples/bluetooth/peripheral_hids_keyboard/Kconfig |  22 ++
     .../bluetooth/peripheral_hids_keyboard/README.rst  |  94 +++++-
     .../bluetooth/peripheral_hids_keyboard/prj.conf    |   5 +
     .../bluetooth/peripheral_hids_keyboard/sample.yaml |   2 +-
     .../peripheral_hids_keyboard/src/app_nfc.c         | 116 ++++++++
     .../peripheral_hids_keyboard/src/app_nfc.h         |  18 ++
     .../bluetooth/peripheral_hids_keyboard/src/main.c  | 155 +++++++++-
     .../bluetooth/peripheral_hids_mouse/CMakeLists.txt |   5 +
     samples/bluetooth/peripheral_hids_mouse/Kconfig    |   4 +
     samples/bluetooth/peripheral_hids_mouse/README.rst |   6 +
     samples/bluetooth/peripheral_hids_mouse/prj.conf   |   5 +
     samples/bluetooth/peripheral_hids_mouse/src/main.c | 140 ++++++++-
     samples/bootloader/prj.conf                        |   5 +
     samples/debug/ppi_trace/prj.conf                   |   5 +
     samples/esb/prx/prj.conf                           |   5 +
     samples/esb/ptx/prj.conf                           |   5 +
     samples/event_manager/prj.conf                     |   5 +
     samples/nfc/record_text/prj.conf                   |   5 +
     samples/nfc/tag_reader/prj.conf                    |   5 +
     samples/nfc/tag_reader/src/main.c                  |   6 +
     samples/nfc/writable_ndef_msg/prj.conf             |   5 +
     samples/nrf9160/at_client/prj.conf                 |   5 +
     samples/nrf9160/aws_fota/prj.conf                  |   9 +-
     samples/nrf9160/coap_client/prj.conf               |   5 +
     samples/nrf9160/coap_client/prj_qemu_x86.conf      |   5 +
     samples/nrf9160/gps/prj.conf                       |   5 +
     samples/nrf9160/http_application_update/prj.conf   |   7 +-
     .../child_secure_partition_manager.conf            |   5 +
     samples/nrf9160/lte_ble_gateway/prj.conf           |   5 +
     samples/nrf9160/mqtt_simple/prj.conf               |   5 +
     samples/nrf9160/mqtt_simple/prj_qemu_x86.conf      |   5 +
     samples/nrf9160/secure_services/prj.conf           |   5 +
     samples/nrf9160/spm/CMakeLists.txt                 |   5 +
     samples/nrf9160/spm/prj.conf                       |   5 +
     samples/profiler/prj.conf                          |   5 +
     scripts/hid_configurator/configurator.py           | 184 ++++++++++--
     scripts/profiler/calc_stats.py                     |   2 +
     scripts/profiler/data_collector.py                 |   2 +
     scripts/profiler/events.py                         |   2 +
     scripts/profiler/plot_from_files.py                |   2 +
     scripts/profiler/plot_nordic.py                    |   2 +
     scripts/profiler/plot_nordic_config.py             |   2 +
     scripts/profiler/processed_events.py               |   5 +
     scripts/profiler/real_time_plot.py                 |   2 +
     scripts/profiler/rtt_nordic_config.py              |   2 +
     scripts/profiler/rtt_nordic_profiler_host.py       |   2 +
     scripts/profiler/stats_nordic.py                   |   2 +
     subsys/bluetooth/Kconfig.discovery                 |   6 +
     subsys/bluetooth/Kconfig.link                      |   6 +
     subsys/bluetooth/Kconfig.pool                      |   6 +
     subsys/bluetooth/Kconfig.scan                      |   6 +
     subsys/bluetooth/controller/Kconfig                |   6 +
     subsys/bluetooth/services/Kconfig                  |   6 +
     subsys/bluetooth/services/Kconfig.bas_c            |   6 +
     subsys/bluetooth/services/Kconfig.dfu_smp_c        |   6 +
     subsys/bluetooth/services/Kconfig.hids             |   6 +
     subsys/bluetooth/services/Kconfig.hids_c           |   6 +
     subsys/bluetooth/services/Kconfig.lbs              |   7 +-
     subsys/bluetooth/services/Kconfig.nus              |   7 +-
     subsys/bluetooth/services/Kconfig.nus_c            |   6 +
     subsys/bluetooth/services/Kconfig.throughput       |   7 +-
     subsys/bluetooth/services/lbs.c                    |  12 +-
     subsys/bluetooth/services/nus.c                    |  12 +-
     subsys/bluetooth/services/throughput.c             |  12 +-
     subsys/enhanced_shockburst/CMakeLists.txt          |   5 +
     subsys/net/lib/CMakeLists.txt                      |   2 +-
     subsys/net/lib/aws_jobs/CMakeLists.txt             |   5 +
     subsys/net/lib/cloud/CMakeLists.txt                |   5 +
     subsys/net/lib/download_client/CMakeLists.txt      |   2 +-
     subsys/net/lib/download_client/Kconfig             |  28 +-
     .../{http_download_client.c => download_client.c}  | 112 ++++---
     subsys/net/lib/fota_download/Kconfig               |   2 +-
     subsys/net/lib/fota_download/src/fota_download.c   |   8 +-
     subsys/net/lib/nrf_cloud/CMakeLists.txt            |   5 +
     subsys/net/lib/nrf_cloud/src/nrf_cloud.c           |   5 +-
     subsys/nfc/ndef/CMakeLists.txt                     |   1 +
     subsys/nfc/ndef/Kconfig                            |   5 +
     subsys/nfc/ndef/le_oob_rec.c                       | 187 ++++++++++++
     subsys/profiler/Kconfig                            |   5 +
     subsys/shell/shell_bt_nus.c                        |   2 +-
     tests/aws_fota_json/prj.conf                       |   5 +
     tests/aws_fota_json/src/main.c                     |   2 +-
     tests/gatt_dm/CMakeLists.txt                       |   5 +
     tests/gatt_dm/prj.conf                             |   5 +
     tests/subsys/event_manager/prj.conf                |   5 +
     tests/unity/example_test/prj.conf                  |   5 +
     west.yml                                           |   2 +-
     181 files changed, 3409 insertions(+), 724 deletions(-)
     create mode 100644 doc/release-notes-1.0.0.rst
     rename include/{ => net}/download_client.h (85%)
     rename include/{ => net}/download_client.rst (90%)
     create mode 100644 include/nfc/ndef/le_oob_rec.h
     create mode 100644 include/nfc/ndef/le_oob_rec.rst
     create mode 100644 samples/bluetooth/peripheral_hids_keyboard/Kconfig
     create mode 100644 samples/bluetooth/peripheral_hids_keyboard/src/app_nfc.c
     create mode 100644 samples/bluetooth/peripheral_hids_keyboard/src/app_nfc.h
     rename subsys/net/lib/download_client/src/{http_download_client.c => download_client.c} (80%)
     create mode 100644 subsys/nfc/ndef/le_oob_rec.c
    
    C:\ncs\nrf>git checkout v1.0.0
    Note: checking out 'v1.0.0'.
    
    You are in 'detached HEAD' state. You can look around, make experimental
    changes and commit them, and you can discard any commits you make in this
    state without impacting any branches by performing another checkout.
    
    If you want to create a new branch to retain commits you create, you may
    do so (now or later) by using -b with the checkout command again. Example:
    
      git checkout -b <new-branch-name>
    
    HEAD is now at 1f3f87d manifest: Updated manifest to use v1.0.0 release tags
    
    C:\ncs\nrf>west update
    === self-updating west:
    --- west: fetching changes
    From https://github.com/zephyrproject-rtos/west
     * tag               v0.5.8     -> FETCH_HEAD
    --- west: checked out 1980f707d6cb2b71d3488420e928051cc0a9df13 as detached HEAD
    === updating fw-nrfconnect-zephyr (zephyr):
    --- fw-nrfconnect-zephyr: fetching changes
    From https://github.com/NordicPlayground/fw-nrfconnect-zephyr
     * tag                     v1.14.99-ncs2 -> FETCH_HEAD
    --- fw-nrfconnect-zephyr: checked out 7e64ac737daead12d2dbdda5daec04188243a81c as detached HEAD
    === updating nffs (modules\fs\nffs):
    --- nffs: fetching changes
    --- nffs: checked out bc62a2fa9d98ddb5d633c932ea199bc68e10f194 as detached HEAD
    === updating segger (modules\debug\segger):
    --- segger: fetching changes
    --- segger: checked out 6fcf61606d6012d2c44129edc033f59331e268bc as detached HEAD
    === updating fw-nrfconnect-mcuboot (mcuboot):
    --- fw-nrfconnect-mcuboot: fetching changes
    From https://github.com/NordicPlayground/fw-nrfconnect-mcuboot
     * tag               v1.3.99-ncs2 -> FETCH_HEAD
    --- fw-nrfconnect-mcuboot: checked out 8b0e50cd5898e66e8bf92b5378c5b29fb0838471 as detached HEAD
    === updating fw-nrfconnect-mcumgr (modules\lib\mcumgr):
    --- fw-nrfconnect-mcumgr: fetching changes
    --- fw-nrfconnect-mcumgr: checked out c8f675a5fa7f62106b9d913844bd5ed6e16ae69e as detached HEAD
    === updating fw-nrfconnect-tinycbor (modules\lib\tinycbor):
    --- fw-nrfconnect-tinycbor: fetching changes
    --- fw-nrfconnect-tinycbor: checked out 543ecb7c8662580ef803d59ceda7bd3b8a84a11b as detached HEAD
    === updating nrfxlib (nrfxlib):
    --- nrfxlib: fetching changes
    From https://github.com/NordicPlayground/nrfxlib
     * tag               v1.0.0     -> FETCH_HEAD
    --- nrfxlib: checked out efcbc258d7c869457e5af59f100fe9a7eeb19b62 as detached HEAD
    === updating cmock (test\cmock):
    --- cmock: fetching changes
    --- cmock: checked out c243b9a7a7b3c471023193992b46cf1bd1910450 as detached HEAD
    === updating unity (test\cmock\vendor\unity):
    --- unity: fetching changes
    remote: Enumerating objects: 97, done.
    remote: Counting objects: 100% (97/97), done.
    remote: Compressing objects: 100% (28/28), done.
    remote: Total 161 (delta 77), reused 84 (delta 68), pack-reused 64
    Receiving objects: 100% (161/161), 42.11 KiB | 653.00 KiB/s, done.
    Resolving deltas: 100% (103/103), completed with 29 local objects.
    From https://github.com/ThrowTheSwitch/unity
       10f10b5..7514b89  master     -> refs/west/master
    --- unity: checked out 031f3bbe45f8adf504ca3d13e6f093869920b091 as detached HEAD
    === updating mbedtls (mbedtls):
    --- mbedtls: fetching changes
    remote: Enumerating objects: 620, done.
    remote: Counting objects: 100% (620/620), done.
    remote: Compressing objects: 100% (27/27), done.
    remote: Total 770 (delta 593), reused 617 (delta 592), pack-reused 150
    Receiving objects: 100% (770/770), 299.11 KiB | 1.18 MiB/s, done.
    Resolving deltas: 100% (622/622), completed with 207 local objects.
    From https://github.com/ARMmbed/mbedtls
     * tag                   mbedtls-2.13.1  -> FETCH_HEAD
     * [new tag]             mbedtls-2.18.1  -> mbedtls-2.18.1
     * [new tag]             mbedtls-3.0.0p1 -> mbedtls-3.0.0p1
    --- mbedtls: checked out 53546ea099f6f53d0be653a64accd250e170337f as detached HEAD

    and it caused all kinds of problems. Then i've updated the GNU Arm toolchain and SES, but I still can't build any of the projects:

    2> Compiling ‘secure_services.c’
    1> In file included from C:/ncs/nrf/subsys/spm/spm.c:20:
    1> C:/ncs/zephyr/arch/arm/include/cortex_m/tz.h:319:22: error: called object 'typeof(*(vtor_ns + 4))' is not a function or function pointer
    1> C:/ncs/nrf/subsys/spm/spm.c:392:13: note: in expansion of macro 'TZ_NONSECURE_FUNC_PTR_CREATE'
    Build failed

  • Are you using GCC 8? It has issues with the trustzone defines, and has linking issues on windows.

    There's a thread on this subject here: https://devzone.nordicsemi.com/f/nordic-q-a/49326/tz_nonsecure_func_ptr_create-spm-error-with-v1-0-0-for-nrf9160

     

    I would recommend using GCC 7-2018-q2-update, as this is the one we test with and use officially with ncs.

     

    Kind regards,

    Håkon

Reply Children
No Data
Related