udp_get_socket listener function

I have been using TCPnet for ST10 but I imagine my question applies cross-platform.

The documentation for udp_get_socket specifies that a user-defined listener callback should be registered as below:

#include <AR166.h>

U8 udp_get_socket (
    U8   tos,           /* Type Of Service. */
    U8   opt,           /* Option to calculate or verify the checksum. */
    U16 (*listener)(    /* Function to call when TCPnet receives a data packet. */
        U8  socket,     /* Socket handle of the local machine. */
        U8* remip,      /* Pointer to IP address of remote machine. */
        U16 port,       /* Port number of remote machine. */
        U8* buf,        /* Pointer to buffer containing the received data. */
        U16 len ));     /* Number of bytes in the received data packet. */

I cannot find documentation about a few aspects of the listener function:

- Is it the responsibility of the udp_get_socket listener function to free the buffer memory, or does the listener caller take care of that?
- What significance does the U16 return value of the listener function have? What does the caller do with the return value?

Thanks, Tony

Parents
  • "Is it the responsibility of the udp_get_socket listener function to free the buffer memory, or does the listener caller take care of that?"

    When the UDP frame has been sent, TCPnet automatically de-allocates the memory used by the send buffer.

    Taken from page:

    http://www.keil.com/support/man/docs/rlarm/rlarm_udp_get_buf.htm

    "What significance does the U16 return value of the listener function have? What does the caller do with the return value?"

    Can't find the details concerning that at the moment. For a TCP connection, the manual states:

    If the listener function returns 0, TCPnet rejects the incoming connection. You can thus define the listener function to selectively reject incoming connections from particular IP addresses.

    but, since UDP cannot refuse a connection in the same way, I think the return value should always be zero. That's what I've always done and I've not found any problems with it.

    I think that the example given in the manual supports that thought; i.e., it returns zero and there is no mention of anything else:

    www.keil.com/.../rlarm_udp_get_socket.htm

Reply
  • "Is it the responsibility of the udp_get_socket listener function to free the buffer memory, or does the listener caller take care of that?"

    When the UDP frame has been sent, TCPnet automatically de-allocates the memory used by the send buffer.

    Taken from page:

    http://www.keil.com/support/man/docs/rlarm/rlarm_udp_get_buf.htm

    "What significance does the U16 return value of the listener function have? What does the caller do with the return value?"

    Can't find the details concerning that at the moment. For a TCP connection, the manual states:

    If the listener function returns 0, TCPnet rejects the incoming connection. You can thus define the listener function to selectively reject incoming connections from particular IP addresses.

    but, since UDP cannot refuse a connection in the same way, I think the return value should always be zero. That's what I've always done and I've not found any problems with it.

    I think that the example given in the manual supports that thought; i.e., it returns zero and there is no mention of anything else:

    www.keil.com/.../rlarm_udp_get_socket.htm

Children
More questions in this forum