mirror of
https://github.com/tio/tio.git
synced 2026-05-01 14:57:59 +02:00
Moved delay mechanism into separate function
This commit is contained in:
parent
14fc053e8b
commit
13a8bc7790
3 changed files with 13 additions and 8 deletions
|
|
@ -23,5 +23,6 @@
|
||||||
#define TIME_H
|
#define TIME_H
|
||||||
|
|
||||||
char * current_time(void);
|
char * current_time(void);
|
||||||
|
void delay(long ms);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
11
src/time.c
11
src/time.c
|
|
@ -23,6 +23,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include "tio/error.h"
|
#include "tio/error.h"
|
||||||
|
#include "tio/print.h"
|
||||||
|
|
||||||
char * current_time(void)
|
char * current_time(void)
|
||||||
{
|
{
|
||||||
|
|
@ -42,3 +43,13 @@ char * current_time(void)
|
||||||
|
|
||||||
return time_string;
|
return time_string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void delay(long ms)
|
||||||
|
{
|
||||||
|
struct timespec ts;
|
||||||
|
|
||||||
|
ts.tv_sec = ms / 1000;
|
||||||
|
ts.tv_nsec = (ms % 1000) * 1000000;
|
||||||
|
|
||||||
|
nanosleep(&ts, NULL);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,6 @@
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <time.h>
|
|
||||||
#include "tio/tty.h"
|
#include "tio/tty.h"
|
||||||
#include "tio/print.h"
|
#include "tio/print.h"
|
||||||
#include "tio/options.h"
|
#include "tio/options.h"
|
||||||
|
|
@ -309,8 +308,6 @@ int connect_tty(void)
|
||||||
|
|
||||||
if (forward)
|
if (forward)
|
||||||
{
|
{
|
||||||
struct timespec ts;
|
|
||||||
|
|
||||||
/* Send output to tty device */
|
/* Send output to tty device */
|
||||||
status = write(fd, &output_char, 1);
|
status = write(fd, &output_char, 1);
|
||||||
if (status < 0)
|
if (status < 0)
|
||||||
|
|
@ -324,11 +321,7 @@ int connect_tty(void)
|
||||||
tx_total++;
|
tx_total++;
|
||||||
|
|
||||||
/* Insert output delay */
|
/* Insert output delay */
|
||||||
ts.tv_sec = 0;
|
delay(option.output_delay);
|
||||||
ts.tv_nsec = option.output_delay * 1000000;
|
|
||||||
if (option.output_delay)
|
|
||||||
nanosleep(&ts, NULL);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Save previous key */
|
/* Save previous key */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue