Bug fixes

This commit is contained in:
Andrew Pamment 2019-12-01 19:36:24 +10:00
parent 12f70e6ce9
commit e13f7e0777
3 changed files with 31 additions and 14 deletions

View File

@ -6,8 +6,12 @@
#include <sys/socket.h>
#endif
#include <unistd.h>
#include <time.h>
#include "MagiDoor.h"
extern time_t mdtimeout;
extern time_t mdtimeremaining;
char md_getc() {
char c;
ssize_t ret;
@ -25,9 +29,18 @@ char md_getc() {
#else
if (ret == -1 && (errno == EAGAIN || errno == EWOULDBLOCK)) {
#endif
usleep(1);
if (mdtimeout <= time(NULL)) {
md_printf("\r\nIdle timeout!\r\n");
md_exit(0);
}
if (mdtimeremaining <= time(NULL)) {
md_printf("\r\nOut of time!\r\n");
md_exit(0);
}
usleep(100);
continue;
}
mdtimeout = time(NULL) + 900;
return c;
}
}

View File

@ -7,6 +7,7 @@
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include "MagiDoor.h"
@ -24,6 +25,9 @@ MDDoorControl_t mdcontrol;
struct termios ttysave;
#endif
time_t mdtimeout;
time_t mdtimeremaining;
static void md_cfg_read_line(char *buffer, int len, FILE *fptr) {
fgets(buffer, len, fptr);
if (buffer[strlen(buffer) - 1] == '\n') {
@ -74,13 +78,7 @@ int read_door32(const char *dropfile) {
md_cfg_read_line(buffer, 256, fptr); // node no
mdcontrol.node = strtol(buffer, NULL, 10);
#if defined(WIN32) || defined(_MSC_VER)
WSADATA wsa;
WSAStartup(WINSOCK_VERSION, &wsa);
#else
mdcontrol.socket = -1;
#endif
return 0;
}
@ -171,8 +169,6 @@ int read_doorsys(const char *dropfile) {
fclose(fptr);
mdcontrol.socket = -1;
return 0;
}
@ -187,13 +183,15 @@ void md_exit(int exitcode) {
exit(exitcode);
}
int md_init(const char *dropfile) {
int md_init(const char *dropfile, int socket) {
char *filename = strrchr(dropfile, PATH_SEP);
#if !defined(WIN32) && !defined(_MSC_VER)
struct termios ttystate;
#endif
int ret;
mdcontrol.socket = socket;
if (filename == NULL) {
filename = (char *)dropfile;
} else {
@ -207,8 +205,7 @@ int md_init(const char *dropfile) {
}
if (mdcontrol.socket == -1) {
#if defined(WIN32) || defined(_MSC_VER)
#else
#if !defined(WIN32) && !defined(_MSC_VER)
tcgetattr(STDIN_FILENO, &ttystate);
ttysave = ttystate;
@ -220,7 +217,14 @@ int md_init(const char *dropfile) {
tcsetattr(STDIN_FILENO, TCSANOW, &ttystate);
#endif
}
} else {
#if defined(WIN32) || defined(_MSC_VER)
WSADATA wsa;
WSAStartup(WINSOCK_VERSION, &wsa);
#endif
}
mdtimeremaining = time(NULL) + mdcontrol.user_timeleft;
mdtimeout = time(NULL) + 900;
return ret;
}

View File

@ -18,7 +18,7 @@ typedef struct MDDoorControl {
extern MDDoorControl_t mdcontrol;
extern int md_init(const char *dropfile);
extern int md_init(const char *dropfile, int socket);
extern void md_exit(int exitcode);
extern void md_putchar(char c);
extern void md_printf(const char *fmt, ...);