select system call behavior



In my program, every time writing into a FIFO, i made a check to see
writev system call will block or not using "select system call". But
select system call did not return positive value (positive value means
no. of descriptors available to write, in my case 1) even when writev
will able to write into FIFO (that means FIFO (buffer) is not full).
Here i used 5 seconds as a time out period. So every time select system
call is timed out.

I tried the same program on other unix platforms (AIX & HP). Here
select returned with positive value while process (writev) able to
write into FIFO (FIFO was not full) and timed out when the FIFO was
full.

I am not sure, is it how select system call behave on linux. please
help me to understand and also if i am doing anything wrong, please
point out me.


Program:

#include <sys/types.h>
#include <sys/stat.h>
#include <sys/uio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <sys/time.h>

int main(int argc,char *argv[])
{
void catch_sigpipe(int);
int fd;
char *buf=malloc(1000); /* on AIX, I used to write 15000 bytes
each time, because */
struct iovec data={buf,1000}; /* PIPE_BUF size 32K on AIX. (on
linux 4K) */
fd_set wfds;
struct timeval tv;
int retval;

if(mkfifo("./pfifo",0644)<0)
{
perror("Error");
exit(1);
}
printf("fifo is successfully created\n");

if((fd=open("./pfifo", O_RDWR|O_NONBLOCK )) == -1)
{
perror("open");
exit(1);
}

while(1)
{
FD_ZERO(&wfds);
FD_SET(fd, &wfds);
/* Wait up to five seconds. */
tv.tv_sec = 5;
tv.tv_usec = 0;

retval = select(fd+1, NULL, &wfds, NULL, &tv);
if (retval == -1)
perror("select()");
else if (retval)
printf("Data is available now.\n");
else
printf("No data within five seconds: %d\n",retval);

if(writev(fd,&data,1) == -1)
{
perror("Error");
FD_ZERO(&wfds);
FD_SET(fd, &wfds);
/* Wait up to five seconds. */
tv.tv_sec = 5;
tv.tv_usec = 0;
retval = select(fd+1, NULL, &wfds, NULL, &tv);
if (retval == -1)
perror("select()");
else if (retval)
printf("Data is available now.\n");
else
printf("No data within five seconds: %d\n",retval);

}
else {
printf("writev successful\n");
sleep(1);
}
}
exit(0);
}


LINUX output:
fifo is successfully created
Data is available now.
writev successful
No data within five seconds: 0
writev successful
No data within five seconds: 0
writev successful
No data within five seconds: 0
writev successful

Here PIPE_BUF size is 4K, You can see from the output the select system
call is timed out even when writev successful.

AIX output:

fifo is successfully created
Data is available now.
writev successful
Data is available now.
writev successful
Error: Resource temporarily unavailable
Data is available now.
Data is available now.
Error: Resource temporarily unavailable
Data is available now.
Data is available now.

Here PIPE_BUF size is 32K, select triggers only when FIFO is full.

.