Fifo: code cosmetic

This commit is contained in:
Martin Duquesnoy 2011-10-30 18:38:44 +01:00
parent 4e9be5ff15
commit 2abbd8ca98
3 changed files with 19 additions and 18 deletions

View File

@ -9,6 +9,16 @@
#include "config.h" #include "config.h"
#include "fifo.h" #include "fifo.h"
static void
fifo_open(void)
{
if(W->fifo.fd)
close(W->fifo.fd);
if(!(W->fifo.fd = open(W->fifo.path, O_RDONLY | O_NDELAY, 0)))
warnx("Can't open FIFO: %s\n", strerror(errno));
}
void void
fifo_init(void) fifo_init(void)
{ {
@ -17,8 +27,7 @@ fifo_init(void)
if(mkfifo(W->fifo.path, 0644) < 0) if(mkfifo(W->fifo.path, 0644) < 0)
warnx("Can't create FIFO: %s\n", strerror(errno)); warnx("Can't create FIFO: %s\n", strerror(errno));
if(!(W->fifo.fd = open(W->fifo.path, O_RDONLY | O_NDELAY, 0))) fifo_open();
warnx("Can't open FIFO: %s\n", strerror(errno));
} }
static void static void
@ -42,14 +51,14 @@ fifo_parse(char *cmd)
XSync(W->dpy, false); XSync(W->dpy, false);
} }
int void
fifo_read(void) fifo_read(void)
{ {
char buf[256] = { 0 }; char buf[256] = { 0 };
int ret = 0; int ret;
if((ret = read(W->fifo.fd, buf, sizeof(buf) - 1)) > 0) if((ret = read(W->fifo.fd, buf, sizeof(buf) - 1)) > 0)
fifo_parse(buf); fifo_parse(buf);
else if(!ret)
return ret; fifo_open();
} }

View File

@ -14,6 +14,6 @@
#include <string.h> #include <string.h>
void fifo_init(void); void fifo_init(void);
int fifo_read(void); void fifo_read(void);
#endif /* __FIFO_H */ #endif /* __FIFO_H */

View File

@ -242,12 +242,12 @@ static void
wmfs_loop(void) wmfs_loop(void)
{ {
XEvent ev; XEvent ev;
int fd = ConnectionNumber(W->dpy); int maxfd, fd = ConnectionNumber(W->dpy);
fd_set iset; fd_set iset;
while(W->running) while(W->running)
{ {
int maxfd = fd + 1; maxfd = fd + 1;
FD_ZERO(&iset); FD_ZERO(&iset);
FD_SET(fd, &iset); FD_SET(fd, &iset);
@ -269,15 +269,7 @@ wmfs_loop(void)
} }
} }
else if(W->fifo.fd > 0 && FD_ISSET(W->fifo.fd, &iset)) else if(W->fifo.fd > 0 && FD_ISSET(W->fifo.fd, &iset))
{ fifo_read();
if(fifo_read() == 0)
{
close(W->fifo.fd);
if(!(W->fifo.fd = open(W->fifo.path, O_RDONLY | O_NDELAY, 0)))
warnx("Can't reopen FIFO: %s\n", strerror(errno));
}
}
} }
} }
} }