- changed select to uselect

- some fixes in tecs.c
This commit is contained in:
zolliker
2008-10-16 14:33:25 +00:00
parent 5cb057f645
commit d239d98edb
12 changed files with 50 additions and 17 deletions

View File

@ -172,7 +172,7 @@ int CocCmdWithRetry(CocConn *conn) {
}
iret=CocTryCmd(conn);
if (iret>=0) break;
close(conn->fd);
if (conn->fd > 0) close(conn->fd);
conn->fd=-1;
if (iret==-1) goto OnError; /* severe error */
ErrShort(ErrMessage);

View File

@ -16,6 +16,7 @@
#include "coc_server.h"
#include "myc_str.h"
#include "myc_time.h"
#include "uselect.h"
#define COC_NUL COC_SEP
@ -480,7 +481,7 @@ void CocShowHandlers(char *buf, int buf_len) {
#ifdef __VMS
typedef size_t socklen_type;
#else
typedef int socklen_type;
typedef socklen_t socklen_type;
#endif
int CocHandle1Request(int tmo_msec, int fd) {
@ -496,10 +497,10 @@ int CocHandle1Request(int tmo_msec, int fd) {
rmask=mask;
if (fd>0) FD_SET(fd, &rmask);
if (fd>=maxfd) maxfd=fd+1;
tmo.tv_sec=tmo_msec / 1000;
tmo.tv_usec=(tmo_msec % 1000)*1000+1;
if (fd>=maxfd) maxfd=fd+1;
ERR_SI(i=select(maxfd,&rmask,NULL,NULL,&tmo));
ERR_I(i=uselect(maxfd,&rmask,NULL,NULL,&tmo));
if (fd>0 && FD_ISSET(fd, &rmask)) return(1); /* event on fd */
if (i==0) return(0); /* timeout */

View File

@ -8,6 +8,7 @@
#include "myc_err.h"
#include "myc_str.h"
#include "coc_util.h"
#include "uselect.h"
/*-------------------------------------------------------------------------*/
/* CreateSocketAddress stolen from Tcl. Thanks to John Ousterhout */
@ -52,7 +53,7 @@ void CocDelay(int msec) {
tmo.tv_sec=msec / 1000;
tmo.tv_usec=(msec % 1000)*1000+1;
select(1,NULL,NULL,NULL,&tmo);
uselect(1,NULL,NULL,NULL,&tmo);
}
/*-------------------------------------------------------------------------*/
@ -79,7 +80,7 @@ int CocRecv(int fd, StrBuf *buf, int timeout, int *flag) {
FD_ZERO(&mask);
FD_SET(fd, &mask);
ERR_SI(i=select(fd+1,&mask,NULL,NULL,&tmo));
ERR_SI(i=uselect(fd+1,&mask,NULL,NULL,&tmo));
if (flag!=NULL) {
*flag=0;
if (i==0) return(0);

View File

@ -10,10 +10,10 @@
LIBR_OBJ =coc_util.o myc_err.o myc_str.o myc_buf.o myc_time.o
SERV_OBJ =tecs.o coc_server.o tecs_lsc.o tecs_serial.o coc_logfile.o \
tecs_data.o tecs_logger.o $(LIBR_OBJ)
tecs_data.o tecs_logger.o uselect.o $(LIBR_OBJ)
CLI_OBJ =tecs_cli.o coc_client.o $(LIBR_OBJ)
TCLI_OBJ =sys_getenv.o sys_env.o myc_tmp.o sys_cmdpar.o \
sys_date.o sys_wait.o sys_lun.o sys_rdline.o \
sys_date.o sys_wait.o sys_lun.o sys_rdline.o uselect.o \
sys_get_key.o sys_unix.o sys_open$(SYS_OPEN).o \
$(CLI_OBJ)
TECLI_OBJ =tecs_client.o tecs_plot.o str.o instr_hosts.o \
@ -71,7 +71,7 @@ tecs_serial.o: tecs_serial.c
keep_running: keep_running.c
$(CC) $(CFLAGS) -o $@ $Q $(FORTIFYOBJ)
six: six.c term.o sys_select.o libtecsl.a instr_hosts.o
six: six.c term.o sys_select.o libtecsl.a instr_hosts.o uselect.o
$(CC) $(CFLAGS) -o $@ $Q $(FORTIFYOBJ)
rexstart: rstart.c myc_str.o myc_err.o instr_hosts.o

View File

@ -21,6 +21,7 @@ void *outarg;
void ErrTxt(char *text, int systemError)
{
if (systemError) {
stack_empty = 0;
sp=0; ErrCode=errno; ErrMessage=strerror(errno);
}
if (stack_empty && sp>0) {

View File

@ -241,6 +241,7 @@ int str_ncpy(char *dst, const char *src, int maxdest) {
}
int str_ncat(char *dst, const char *src, int maxdest) {
dst[maxdest-1]='\0';
strncat(dst, src, maxdest-strlen(dst)-1);
if (dst[maxdest-1]!='\0') {
dst[maxdest-1]='\0';

View File

@ -2,6 +2,7 @@
#include <unistd.h>
#include <stdio.h>
#include <sys/time.h>
#include "uselect.h"
static int lastFd=-1;
static struct termios atts;
@ -53,7 +54,7 @@ int sys_select_or_key(fd_set *mask, int msecTmo, int *key) {
sys_keys_on();
rmask=*mask;
iret=select(FD_SETSIZE, &rmask, NULL, NULL, &tmo0);
iret=uselect(FD_SETSIZE, &rmask, NULL, NULL, &tmo0);
if (iret<0) {
FD_ZERO(&rmask);
perror("error in select");
@ -72,9 +73,9 @@ int sys_select_or_key(fd_set *mask, int msecTmo, int *key) {
}
tmo.tv_sec=msecTmo / 1000;
tmo.tv_usec=(msecTmo%1000)*1000;
iret=select(FD_SETSIZE, &rmask, NULL, NULL, &tmo);
iret=uselect(FD_SETSIZE, &rmask, NULL, NULL, &tmo);
} else {
iret=select(FD_SETSIZE, &rmask, NULL, NULL, NULL);
iret=uselect(FD_SETSIZE, &rmask, NULL, NULL, NULL);
}
if (iret<0) {
FD_ZERO(&rmask);

View File

@ -633,6 +633,7 @@ again:
loop=1;
initMaxPower=1;
resist=10;
nScan=0;
} else {
InitSensor(&sensC);
InitSensor(&sensD);
@ -1831,7 +1832,7 @@ int Settings(void) {
if (k>4) k=kk;
i++;
}
k = kk + nScan + 1;
/* k = kk + nScan + 1; */
if (k > 4) k = 5;
}
maxfld=k-1;
@ -2337,7 +2338,7 @@ int PeriodicTask(void) {
ERR_P(LscCmd(ser, "ALMRST"));
}
} else if (loop == 1) {
if (!relay0) logfileOut(LOG_MAIN, "Relay is on!\n");
if (relay && !relay0) logfileOut(LOG_MAIN, "Relay is on!\n");
alarmStatus[0]='\0';
}
@ -2630,7 +2631,6 @@ int DeviceHdl(int mode, void *base, int fd) {
t=strchr(device, '/');
if (t==NULL) {
if (0==strcmp(device, "0") || 0==strcasecmp(device, "auto")) {
nScan=0;
ERR_I(ConfigByCode(0));
ERR_I(ConfigByCode(1));
} else {

View File

@ -14,6 +14,7 @@
#include "coc_util.h"
#include "myc_str.h"
#include "myc_mem.h"
#include "uselect.h"
#define ASYNSRV_TYPE 1
#define TERMSRV_TYPE 2
@ -50,9 +51,11 @@ int SerWait(int tmo_msec, int fd) {
FD_ZERO(&mask);
FD_SET(fd, &mask);
tmo.tv_sec=tmo_msec / 1000;
tmo.tv_usec=(tmo_msec % 1000) % 1000 +1;
ERR_SI(i=select(fd+1,&mask,NULL,NULL,&tmo));
ERR_SI(i=uselect(fd+1,&mask,NULL,NULL,&tmo));
if (i==0) return(0); /* timeout */
return(1);
OnError: return(-1);

View File

@ -67,7 +67,7 @@ int term_wait_socket(int socket, int msecTmo) {
FD_SET(STDIN_FILENO, &mask);
tmo.tv_sec=msecTmo / 1000;
tmo.tv_usec=(msecTmo % 1000) * 1000;
i=select(FD_SETSIZE, &mask, NULL, NULL, &tmo);
i=uselect(FD_SETSIZE, &mask, NULL, NULL, &tmo);
if (FD_ISSET(STDIN_FILENO, &mask)) {
return 0;
}

18
tecs/uselect.c Normal file
View File

@ -0,0 +1,18 @@
#include <signal.h>
#include <errno.h>
#include "uselect.h"
/* an uninterruptable version of select. M.Z. Oct 2008 */
int uselect(int nfds,
fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
struct timeval *timeout) {
sigset_t sigmask;
struct timespec tmo;
sigfillset(&sigmask);
tmo.tv_sec = timeout->tv_sec;
tmo.tv_nsec = timeout->tv_usec * 1000;
return pselect(nfds, readfds, writefds, exceptfds, &tmo, &sigmask);
}

7
tecs/uselect.h Normal file
View File

@ -0,0 +1,7 @@
#include <sys/select.h>
/* an uninterruptable version of select. M.Z. Oct 2008 */
int uselect(int nfds,
fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
struct timeval *timeout);