标签:超时 usleep nanosleep timespec
如下一段代码可以借鉴:
static void _sleep_response_timeout(modbus_t *ctx) { #ifdef _WIN32 /* usleep doesn‘t exist on Windows */ Sleep((ctx->response_timeout.tv_sec * 1000) + (ctx->response_timeout.tv_usec / 1000)); #else /* usleep source code */ struct timespec request, remaining; request.tv_sec = ctx->response_timeout.tv_sec; request.tv_nsec = ((long int)ctx->response_timeout.tv_usec % 1000000) * 1000; while (nanosleep(&request, &remaining) == -1 && errno == EINTR) request = remaining; #endif }
标签:超时 usleep nanosleep timespec
原文地址:http://blog.csdn.net/fulinus/article/details/37598409