sock: change "no timeout" value from 0 to UINT32_MAX

This commit is contained in:
Kaspar Schleiser 2016-10-11 23:23:20 +02:00
parent 39eb55953f
commit aace13624b
4 changed files with 34 additions and 23 deletions

View File

@ -147,6 +147,11 @@ extern "C" {
.netif = SOCK_ADDR_ANY_NETIF } .netif = SOCK_ADDR_ANY_NETIF }
#endif #endif
/**
* @brief Special value meaning "wait forever" (don't timeout)
*/
#define SOCK_NO_TIMEOUT (UINT32_MAX)
/** /**
* @brief Abstract IP end point and end point for a raw IP sock object * @brief Abstract IP end point and end point for a raw IP sock object
*/ */

View File

@ -45,7 +45,8 @@
* sock_ip_ep_t remote; * sock_ip_ep_t remote;
* ssize_t res; * ssize_t res;
* *
* if ((res = sock_ip_recv(&sock, buf, sizeof(buf), 0, &remote)) >= 0) { * if ((res = sock_ip_recv(&sock, buf, sizeof(buf), SOCK_NO_TIMEOUT,
* &remote)) >= 0) {
* puts("Received a message"); * puts("Received a message");
* if (sock_ip_send(&sock, buf, res, 0, &remote) < 0) { * if (sock_ip_send(&sock, buf, res, 0, &remote) < 0) {
* puts("Error sending reply"); * puts("Error sending reply");
@ -97,8 +98,8 @@
* The application then waits indefinitely for an incoming message in * The application then waits indefinitely for an incoming message in
* `buf` from `remote`. If we want to timeout this wait period we could * `buf` from `remote`. If we want to timeout this wait period we could
* alternatively set the `timeout` parameter of @ref sock_ip_recv() to a * alternatively set the `timeout` parameter of @ref sock_ip_recv() to a
* value `> 0`. If an error occurs on receive we just ignore it and continue * value `!= SOCK_NO_TIMEOUT`. If an error occurs on receive we just ignore it
* looping. * and continue looping.
* *
* If we receive a message we use its `remote` to reply. Note since the `proto` * If we receive a message we use its `remote` to reply. Note since the `proto`
* was already set during @ref sock_ip_create() we can just leave `proto` for * was already set during @ref sock_ip_create() we can just leave `proto` for
@ -110,7 +111,8 @@
* sock_ip_ep_t remote; * sock_ip_ep_t remote;
* ssize_t res; * ssize_t res;
* *
* if ((res = sock_ip_recv(&sock, buf, sizeof(buf), 0, &remote)) >= 0) { * if ((res = sock_ip_recv(&sock, buf, sizeof(buf), SOCK_NO_TIMEOUT,
* &remote)) >= 0) {
* puts("Received a message"); * puts("Received a message");
* if (sock_ip_send(&sock, buf, res, 0, &remote) < 0) { * if (sock_ip_send(&sock, buf, res, 0, &remote) < 0) {
* puts("Error sending reply"); * puts("Error sending reply");
@ -389,10 +391,10 @@ int sock_ip_get_remote(sock_ip_t *sock, sock_ip_ep_t *ep);
* @param[out] data Pointer where the received data should be stored. * @param[out] data Pointer where the received data should be stored.
* @param[in] max_len Maximum space available at @p data. * @param[in] max_len Maximum space available at @p data.
* @param[in] timeout Timeout for receive in microseconds. * @param[in] timeout Timeout for receive in microseconds.
* This value can be ignored (no timeout) if the * If 0 and no data is available, the function returns
* @ref sys_xtimer module is not present or the * immediately.
* implementation does not support timeouts on its own. * May be SOCK_NO_TIMEOUT for no timeout (wait until data
* May be 0 for no timeout. * is available).
* @param[out] remote Remote end point of the received data. * @param[out] remote Remote end point of the received data.
* May be NULL, if it is not required by the application. * May be NULL, if it is not required by the application.
* *
@ -401,6 +403,7 @@ int sock_ip_get_remote(sock_ip_t *sock, sock_ip_ep_t *ep);
* @return The number of bytes received on success. * @return The number of bytes received on success.
* @return 0, if no received data is available, but everything is in order. * @return 0, if no received data is available, but everything is in order.
* @return -EADDRNOTAVAIL, if local of @p sock is not given. * @return -EADDRNOTAVAIL, if local of @p sock is not given.
* @return -EAGAIN, if @p timeout is `0` and no data is available.
* @return -ENOBUFS, if buffer space is not large enough to store received * @return -ENOBUFS, if buffer space is not large enough to store received
* data. * data.
* @return -ENOMEM, if no memory was available to receive @p data. * @return -ENOMEM, if no memory was available to receive @p data.

View File

@ -191,16 +191,17 @@ int sock_tcp_accept(sock_tcp_queue_t *queue, sock_tcp_t **sock);
* truncated and the remaining data can be retrieved * truncated and the remaining data can be retrieved
* later on. * later on.
* @param[in] timeout Timeout for receive in microseconds. * @param[in] timeout Timeout for receive in microseconds.
* This value can be ignored (no timeout) if the * If 0 and no data is available, the function returns
* @ref sys_xtimer module is not present and the * immediately.
* implementation does not support timeouts on its own. * May be SOCK_NO_TIMEOUT for no timeout (wait until data
* May be 0 for no timeout. * is available).
* *
* @note Function may block. * @note Function may block.
* *
* @return The number of bytes read on success. * @return The number of bytes read on success.
* @return 0, if no read data is available, but everything is in order. * @return 0, if no read data is available, but everything is in order.
* @return -EADDRNOTAVAIL, if local of @p sock is not given. * @return -EADDRNOTAVAIL, if local of @p sock is not given.
* @return -EAGAIN, if @p timeout is `0` and no data is available.
* @return -ECONNABORTED, if the connection is aborted while waiting for the * @return -ECONNABORTED, if the connection is aborted while waiting for the
* next data. * next data.
* @return -ECONNRESET, if the connection was forcibly closed by remote end * @return -ECONNRESET, if the connection was forcibly closed by remote end

View File

@ -46,7 +46,8 @@
* sock_udp_ep_t remote; * sock_udp_ep_t remote;
* ssize_t res; * ssize_t res;
* *
* if ((res = sock_udp_recv(&sock, buf, sizeof(buf), 0, &remote)) >= 0) { * if ((res = sock_udp_recv(&sock, buf, sizeof(buf), SOCK_NO_TIMEOUT,
* &remote)) >= 0) {
* puts("Received a message"); * puts("Received a message");
* if (sock_udp_send(&sock, buf, res, &remote) < 0) { * if (sock_udp_send(&sock, buf, res, &remote) < 0) {
* puts("Error sending reply"); * puts("Error sending reply");
@ -94,11 +95,11 @@
* } * }
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* *
* The application then waits indefinitely for an incoming message in * The application then waits indefinitely for an incoming message in `buf`
* `buf` from `remote`. If we want to timeout this wait period we could * from `remote`. If we want to timeout this wait period we could alternatively
* alternatively set the `timeout` parameter of @ref sock_udp_recv() to a * set the `timeout` parameter of @ref sock_udp_recv() to a value != @ref
* value `> 0`. If an error occurs on receive we just ignore it and continue * SOCK_NO_TIMEOUT. If an error occurs on receive we just ignore it and
* looping. * continue looping.
* *
* If we receive a message we use its `remote` to reply. In case of an error on * If we receive a message we use its `remote` to reply. In case of an error on
* send we print an according message: * send we print an according message:
@ -108,7 +109,7 @@
* sock_udp_ep_t remote; * sock_udp_ep_t remote;
* ssize_t res; * ssize_t res;
* *
* if ((res = sock_udp_recv(&sock, buf, sizeof(buf), 0, &remote)) >= 0) { * if ((res = sock_udp_recv(&sock, buf, sizeof(buf), SOCK_NO_TIMEOUT, &remote)) >= 0) {
* puts("Received a message"); * puts("Received a message");
* if (sock_udp_send(&sock, buf, res, &remote) < 0) { * if (sock_udp_send(&sock, buf, res, &remote) < 0) {
* puts("Error sending reply"); * puts("Error sending reply");
@ -377,10 +378,10 @@ int sock_udp_get_remote(sock_udp_t *sock, sock_udp_ep_t *ep);
* @param[out] data Pointer where the received data should be stored. * @param[out] data Pointer where the received data should be stored.
* @param[in] max_len Maximum space available at @p data. * @param[in] max_len Maximum space available at @p data.
* @param[in] timeout Timeout for receive in microseconds. * @param[in] timeout Timeout for receive in microseconds.
* This value can be ignored (no timeout) if the * If 0 and no data is available, the function returns
* @ref sys_xtimer module is not present or the * immediately.
* implementation does not support timeouts on its own. * May be SOCK_NO_TIMEOUT for no timeout (wait until data
* May be 0 for no timeout. * is available).
* @param[out] remote Remote end point of the received data. * @param[out] remote Remote end point of the received data.
* May be `NULL`, if it is not required by the application. * May be `NULL`, if it is not required by the application.
* *
@ -389,6 +390,7 @@ int sock_udp_get_remote(sock_udp_t *sock, sock_udp_ep_t *ep);
* @return The number of bytes received on success. * @return The number of bytes received on success.
* @return 0, if no received data is available, but everything is in order. * @return 0, if no received data is available, but everything is in order.
* @return -EADDRNOTAVAIL, if local of @p sock is not given. * @return -EADDRNOTAVAIL, if local of @p sock is not given.
* @return -EAGAIN, if @p timeout is `0` and no data is available.
* @return -ENOBUFS, if buffer space is not large enough to store received * @return -ENOBUFS, if buffer space is not large enough to store received
* data. * data.
* @return -ENOMEM, if no memory was available to receive @p data. * @return -ENOMEM, if no memory was available to receive @p data.