Basically I have a server running an almost infinite, select controlled, mini webserver. I have created a fifo file with mkfifo called "pipe" which is opened in read only mode. My select is suppose to wait for something to happen in that file (which talks to a java GUI using JNI but not important) or if a client connects asking for a website. The GUI has pause, unpause and shutdown options so I figured I would have a variable "paused" in my server which if paused would stop the "FD_SET(s_sock, &fs)" with an if statement. The server will wait perfectly until I send it something along the pipe (the first time) then the select picks it out my "readGUI()" function reads the message and returns; 1, if there was nothing in the pipe or an unpaused call; 0, if there was a pause call; and -1, if there was a shutdown call. My problem is that after it goes back and initializes the select variables again the select automatically calls my readGUI again, says theres nothing in there, returns a 1 and continues this loop indefinetly.
This would have to be a problem with my select I would assume because it proves my pipe is empty.
Heres the code:
Let me know if you need more code. Only posted the problem.
shutter_down = 1;
paused = 1;
T.tv_sec = 1;
T.tv_usec = 0;
r = select(FD_SETSIZE, &fs, NULL, NULL, &T);
if (r < 0)
else if (r > 0)
if (FD_ISSET(fd, &fs))
paused = readGUI();
if (paused == -1)
shutter_down = 0;
else if (FD_ISSET(s_sock, &fs))
/*Accept incoming socket and do stuff*/
ret_val = read(fd, buf, sizeof(buf));
if (ret_val < 1)
return 1; /*Nothings there, big problem*/
buf[ret_val] = '\0';
printf ("buf: %s\n", buf); /*This only gets printed the first time*/
/*Its how I know theres nothing in the pipe*/
if (!(strcasecmp(buf, "1")))
if (!(strcasecmp(buf, "0")))
if (!(strcasecmp(buf, "-1")))
Thanks in advance.