Added support for interuptable windows sleep

This commit is contained in:
Jack Reacher 2016-02-06 02:45:10 -05:00
parent 554d66c768
commit 00e6cc3a6c
2 changed files with 27 additions and 5 deletions

View file

@ -1,8 +1,7 @@
#include <time.h>
#include "hydra.h"
#ifndef _WIN32
#include <time.h>
int sleepn(time_t seconds)
{
struct timespec ts;
@ -10,10 +9,23 @@ int sleepn(time_t seconds)
ts.tv_nsec = 0;
return nanosleep(&ts, NULL);
}
int usleepn(long int milisec) {
struct timespec ts;
ts.tv_sec = milisec / 1000;
ts.tv_nsec = (milisec % 1000) * 1000000L;
return nanosleep(&ts, NULL);
}
#endif
#ifdef _WIN32
#include <windows.h>
int sleepn(unsigned int seconds)
{
return SleepEx(milisec*1000,TRUE);
}
int usleepn(unsigned int milisec)
{
return SleepEx(milisec,TRUE);
}
#endif

12
hydra.h
View file

@ -132,9 +132,19 @@
#define INET_ADDRSTRLEN 16
#endif
int sleepn(time_t seconds);
#ifndef _WIN32
int sleepn(time_t seconds);
int usleepn(long int useconds);
#endif
#ifdef _WIN32
int sleepn(unsigned int seconds);
int usleepn(unsigned int useconds);
#endif
#define _HYDRA_H
#endif