Browse Source

Fifo: code cosmetic

Martin Duquesnoy 12 years ago
parent
commit
2abbd8ca98
3 changed files with 19 additions and 18 deletions
  1. 15 6
      src/fifo.c
  2. 1 1
      src/fifo.h
  3. 3 11
      src/wmfs.c

+ 15 - 6
src/fifo.c

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

+ 1 - 1
src/fifo.h

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

+ 3 - 11
src/wmfs.c

@@ -242,12 +242,12 @@ static void
 wmfs_loop(void)
 {
      XEvent ev;
-     int fd = ConnectionNumber(W->dpy);
+     int maxfd, fd = ConnectionNumber(W->dpy);
      fd_set iset;
 
      while(W->running)
      {
-          int maxfd = fd + 1;
+          maxfd = fd + 1;
 
           FD_ZERO(&iset);
           FD_SET(fd, &iset);
@@ -269,15 +269,7 @@ wmfs_loop(void)
                     }
                }
                else if(W->fifo.fd > 0 && FD_ISSET(W->fifo.fd, &iset))
-               {
-                    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));
-                    }
-               }
+                    fifo_read();
           }
      }
 }