make the maximum number of retries configurable at compile time

using a preprocessor define like this: `CFLAGS="-Os -DNATPMP_MAX_RETRIES=4" make`.
The rationale is that users might want to reduce the maximum timeout of
127.75 seconds with an invalid gateway.
This commit is contained in:
Ștefan Talpalaru 2019-11-06 23:02:21 +01:00
parent 6d5c0db6a0
commit 4a720773d5
No known key found for this signature in database
GPG Key ID: CBF7934204F1B6F9
2 changed files with 8 additions and 1 deletions

View File

@ -286,7 +286,7 @@ NATPMP_LIBSPEC int readnatpmpresponseorretry(natpmp_t * p, natpmpresp_t * respon
gettimeofday(&now, NULL); // check errors !
if(timercmp(&now, &p->retry_time, >=)) {
int delay, r;
if(p->try_number >= 9) {
if(p->try_number >= NATPMP_MAX_RETRIES) {
return NATPMP_ERR_NOGATEWAYSUPPORT;
}
/*printf("retry! %d\n", p->try_number);*/

View File

@ -51,6 +51,13 @@ typedef unsigned short uint16_t;
#endif /* _WIN32 */
#include "natpmp_declspec.h"
/* Set to 9 by https://tools.ietf.org/html/rfc6886#section-3.1 which leads to a
* maximum timeout of 127.75 seconds, due to the initial 250 ms timeout doubling
* each time, so we allow a compile-time modification here.*/
#ifndef NATPMP_MAX_RETRIES
#define NATPMP_MAX_RETRIES (9)
#endif
typedef struct {
int s; /* socket */
in_addr_t gateway; /* default gateway (IPv4) */