This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RTOS/TMS320C6678: How to config recv() to non-blocking mode in NDK?

Part Number: TMS320C6678

Tool/software: TI-RTOS

Hello everyone. We use DaemonNew example In MCSDK, which c6678 to be a tcp server. It can send and receive data successfully.

Now we'd like to change recv() to non-blocking mode,   and we use the following code:

int sockblk = 0;

setsockopt(s, SOL_SOCKET, SO_BLOCKING, &sockblk, sizeof(sockblk));

However, the recv() returns -1 at once everytime, whatever the client send, the recv buffer is always 0.

It cannot receive data correctly. We use fdError() to see the error code is 35, whicn means EWOULDBLOCK.

So my question is, How to successfully config the recv() to non-blocking mode and receive  tcp data?

 

 

  • Hi,

    Have you tried usin recv() with the flag MSG_WAITALL. Have in mind the following e2e thread:
    e2e.ti.com/.../898576

    Best Regards,
    Yordan
  • Thank you for your reply. 

    Yes, I tried. There is no difference in the result.  I always got -1, and no data received.

    Is there any extra steps need to be done?   

  • Hi,

    The socket creation & settings seem ok in your code. Can you specify how do you call the DaemonNew() to create a TCP server?
    I'd recommend to go through section 5.4.1 Server Daemon Support API Functions from the NDK API Reference Guide in NDK documentation.
    "DaemonNew – Create a New TCP/UDP Server Entry

    void *DaemonNew( uint32_t Type,
    uint32_t LocalAddress,
    uint32_t LocalPort,
    int (*pCb)(SOCKET,uint32_t),
    uint32_t Priority,
    uint32_t StackSize,
    uint32_t Argument,
    uint32_t MaxSpawn );

    Parameters

    Type: Socket type (SOCK_STREAM, SOCK_STREAMNC, or SOCK_DGRAM)
    LocalAddress: Local IP address (set to NULL for wildcard)
    LocalPort: Local Port to serve (cannot be NULL)
    pCb: Pointer to callback to handle server event (connection or activity)
    Priority: Priority of new task to create for callback function
    StackSize: Stack size of new task to create for callback function
    Argument: Argument (besides socket) to pass to callback function
    MaxSpawn: Maximum number of callback function instances (must be 1 for UDP)

    Return Value This function returns a handle to a daemon , or NULL on error.

    Description Once a new entry is created, the daemon will create the desired TCP or UDP socket, and start listening for activity.

    In the case of TCP, when a new connection is established, a new task thread is created, and a socket session is opened. Then the user’s callback function is called on the new task thread, being supplied with both the socket to the new connection and the caller specified argument (as supplied to DaemonNew()). The callback function can keep the socket and task thread for as long as necessary. It returns from the callback once it is done with the connection. The function can choose to close the socket if desired. The return code informs the daemon whether the socket has been closed (0) or is still open (1).

    In the case of UDP, when any data is available on the UDP socket, a new task thread is created, and a socket session is opened. Then the user’s callback function is called on the new task thread, being supplied with both the UDP socket and the caller specified argument (as supplied to DaemonNew()). The callback function can keep the socket and task thread for as long as necessary. It returns from the callback only when it is done with the data. (While the callback function holds the UDP socket, the daemon will ignore further activity on it.) The callback should return 1, as it should not close the UDP socket."


    Best Regards,
    Yordan