run.[hc]: Add new functions for main loop

This modification provides two new functions, coap_run_once() and
coap_run(), that can be used by applications to drive the library's
I/O logic.
This commit is contained in:
Olaf Bergmann committed 2016-02-26 18:26:03 +01:00
1 parent d1e3ecdf6e
commit fb1054d6cf
6 files changed
+141 -1

No files matched your search

+1
View File
@@ -46,6 +46,7 @@ extern "C" {
#include "pdu.h"
#include "prng.h"
#include "resource.h"
#include "run.h"
#include "str.h"
#include "subscribe.h"
#include "uri.h"
+37
View File
@@ -0,0 +1,37 @@
/*
* run.h -- CoAP main loop
*
* Copyright (C) 2016 Olaf Bergmann <bergmann@tzi.org>
*
* This file is part of the CoAP library libcoap. Please see README for terms
* of use.
*/
#ifndef _COAP_RUN_H_
#define _COAP_RUN_H_
#include "net.h"
/**
* Execute a single send/receive step. This function sends out any due
* message from the sendqueue and then waits up to @p timeout_ms
* milliseconds for incoming messages on the endpoints that are
* attached to @p ctx. The return value is less than zero on error or
* the number of milliseconds that have passed while waiting.
*
* @param ctx The context to operate on.
* @param timeout_ms The timeout in milliseconds.
* @return The number of milliseconds that have passed since the
* operation has started or a value less than zero on error.
*/
int coap_run_once(coap_context_t *ctx, unsigned int timeout_ms);
/**
* Simple main loop. This function infinitely runs coap_run_once()
* on the given context @p ctx.
*
* @param ctx The context to operate on.
*/
void coap_run(coap_context_t *ctx);
#endif /* COAP_RUN_H */