]> git.sur5r.net Git - ngadmin/blobdiff - lib/src/libconf.c
Use portable way to handle timeouts
[ngadmin] / lib / src / libconf.c
index e26a7224e23ba964210d635e20cffc843c060c91..e691f07acb3d4e6c3f5ef26766baf5167f9498ee 100644 (file)
@@ -1,14 +1,14 @@
 
 #include <ngadmin.h>
 
-#include <attr.h>
-#include <protocol.h>
+#include <nsdp/attr.h>
+#include <nsdp/protocol.h>
 
 #include "lib.h"
 #include "network.h"
 
 
-static const struct timeval default_timeout = {.tv_sec = 4, .tv_usec = 0};
+static const struct timespec default_timeout = {.tv_sec = 4, .tv_nsec = 0};
 
 
 struct ngadmin* ngadmin_init (const char *iface)
@@ -19,6 +19,7 @@ struct ngadmin* ngadmin_init (const char *iface)
        /* allocate main structure */
        nga = malloc(sizeof(struct ngadmin));
        memset(nga, 0, sizeof(struct ngadmin));
+       nga->globalbroad = true;
        
        strncpy(nga->iface, iface, IFNAMSIZ - 1);
        
@@ -28,10 +29,6 @@ struct ngadmin* ngadmin_init (const char *iface)
        }
        
        nga->timeout = default_timeout;
-       if (updateTimeout(nga) < 0) {
-               free(nga);
-               return NULL;
-       }
        
        
        return nga;
@@ -76,9 +73,10 @@ int ngadmin_useGlobalBroadcast (struct ngadmin *nga, bool value)
        if (nga == NULL)
                return ERR_INVARG;
        
-       nga->globalbroad = value;
-       
-       return ERR_OK;
+       if (setBroadcastType(nga, value) == 0)
+               return ERR_OK;
+       else
+               return ERR_NET;
 }
 
 
@@ -101,10 +99,8 @@ int ngadmin_setTimeout (struct ngadmin *nga, const struct timeval *tv)
        if (nga == NULL || tv == NULL)
                return ERR_INVARG;
        
-       nga->timeout = *tv;
-       if (updateTimeout(nga) < 0)
-               ret = ERR_NET;
-       
+       nga->timeout.tv_sec = tv->tv_sec;
+       nga->timeout.tv_nsec = tv->tv_usec * 1000;
        
        return ret;
 }