none
Socket non-blocking RRS feed

  • Question

  • I lookig for example for non-blocking socket

    Note: ioctl() and fctl() is not allowed...

    I observe a strange condition: recv(1 byte) is non-blocked, recv(N bytes) blocked....

    Thursday, August 22, 2019 4:49 PM

Answers

  • Hi WizIO.bg,

    I have an update from product group:

    Best place to look is this file in one of our samples.


    Specifically, the sending socket is opened as non-blocking:

        int sockType = SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK;
        serverState->listenFd = OpenIpV4Socket(ipAddr, port, sockType);

    And HandleClientReadEvent() and HandleClientWriteEvent() show how to avoid blocking if all bytes can't be sent or received immediately.
    Wednesday, September 4, 2019 10:00 PM
    Moderator

All replies

  • Hi you might want to open an issue with your question at the samples repo: https://github.com/Azure/azure-sphere-samples/issues
    Tuesday, August 27, 2019 12:39 AM
    Moderator
  • Hi WizIO.bg  I'm reaching out internally for help with this one. I will update you as soon as I hear back.
    Friday, August 30, 2019 12:39 AM
    Moderator
  • Hi WizIO.bg,

    I have an update from product group:

    Best place to look is this file in one of our samples.


    Specifically, the sending socket is opened as non-blocking:

        int sockType = SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK;
        serverState->listenFd = OpenIpV4Socket(ipAddr, port, sockType);

    And HandleClientReadEvent() and HandleClientWriteEvent() show how to avoid blocking if all bytes can't be sent or received immediately.
    Wednesday, September 4, 2019 10:00 PM
    Moderator
  • Thanks Alberto,

    this days I will test and will inform you 

    Thursday, September 5, 2019 3:45 AM
  • I found "simple" solution

    before connect() ... setsockopt(client->sock, SOL_SOCKET, SO_RCVTIMEO, 10 seconds

    after connect() ... setsockopt(client->sock, SOL_SOCKET, SO_RCVTIMEO, 1 milisecond

    as for Arduino (education) source work very fine

    Sunday, September 8, 2019 6:34 AM