Name

netconn_recv() — Wait for data

Synopsis

err_t netconn_recv (struct netconn *conn , struct netbuf **new_buf );

Description

This function blocks the process while waiting for data to arrive on the connection conn. The return value will be ERR_OK on success. On error, for example if the connection has been closed by the remote host, NULL is returned in new_buf, otherwise a netbuf containing the received data is returned in new_buf.

Example

Example 156.6. This example demonstrates usage of the netconn_recv() function

In the following code, we assume that a connection has been established before the call to example_function().

voidexample_function(struct netconn *conn)
{
    struct netbuf *buf;
    err_t err;

    /* receive data until the other host closes the connection */
    while((err = netconn_recv(conn, buf)) == ERR_OK) {
        do_something(buf);
    }

    /* the connection has now been closed by the other end, so we close our end */
    netconn_close(conn);
}