Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 6 Sep 2000 22:58:57 -0700 (PDT)
From:      Robert Dean <BobDean150@excite.com>
To:        freebsd-questions@FreeBSD.org
Cc:        BobDean150@excite.com
Subject:   select() returns on empty pipes
Message-ID:  <6137495.968306337764.JavaMail.imail@spike.excite.com>

next in thread | raw e-mail | index | archive | help

I am in the process of porting and existing Linux application
(http://dbmix.sourceforge.net) to FreeBSD at the request of one of my er...
clients ? (how's that work in open source anyways?  Is he a client? a user?)

The core of the system is a sound daemon which accepts data from named
fifos, and combines the data into a single output stream before sending it
to a soundcard.

Under linux, I achieved this with named pipes and a call to select(), and I
used the Stevens system V programming manual as my resource.

The basic process is:
1) create and open fifos in read only, nonblocking mode.  This occurs before
the pipes are opened for writing by client applications.
2) call select
3) if select returns with data ready, operate on the data
4) if an EOF is detected on the fifo, close the fifo and recreate it. This
recreate is used as an elegant way of handling client sessions. EOF is
detected by select returning that data is ready on the fifo, but a read() of
the fifo returns that there are 0 bytes ready. I used the Stevens book as a
reference for the EOF detection, and the freeBSD man pages corroborate that
this is correct.

On linux, this process works. (yay!)

On freeBSD, select constantly returns that all pipes have data ready, and
the subsequent calls to read detect the EOF condition. (boo!)  This occurs
before any of the pipes have been opened for writing by a client
application.  Therefore the server constantly invokes step 4 above, and
cannot accept any client data.

The full source (to large to post in full here) for the code can be found in
the sourceforge cvs at: 
http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/DBMix-cvs/dbfsd_src/dbfsd.c?rev=1.2&content-type=text/x-cvsweb-markup&cvsroot=DBMix

The relevant code snippets are the call to select:

/* var. declarations */
        static fd_set temp_read_set;
        static struct timeval timeout;

/* reset file descriptor set */
        FD_ZERO(&temp_read_set);
        temp_read_set = read_ch_set;

	code removed

        timeout.tv_sec = 60;
        timeout.tv_usec = 0;

        select_result = select(numch,&temp_read_set,(fd_set*) 0,(fd_set*) 0,
&timeout);
      
        if (select_result > 0)
        {
                current_timeout_count = 0;
                
                /* check each channel to see if data is ready */ 
                for (i=0; i < sysdata->num_channels;i++)
                {
                        if
(FD_ISSET(temp_ch->server_comm_fd,&temp_read_set))
			{
				code removed...

	                        result =
read(temp_ch->server_comm_fd,temp_buf->buf, DB_BUFSIZE_CHAR);
        	                if (result > 0)
                	        {
                        	    operate on data...
                      		}	
				else
				{
					if(result == 0)
					handle EOF case...
				}


and the creation of the fifos:

        /* create comm pipe */
        if(mkfifo(ch->comm_filename,0777) != 0)
        {
                if(errno != EEXIST)
                {
                        sprintf(tempstr,"init_channels: Error creating
%s",ch->comm_filename);
                        perror(tempstr); return FAILURE;
                }
        }

        /* open comm pipe */
        if((ch->server_comm_fd = open(ch->comm_filename, O_RDONLY |
O_NONBLOCK )) == -1)
        {
                sprintf(tempstr,"init_channels: Error opening %s for
read:",ch->comm_filename);
                perror(tempstr);
                return FAILURE;
        }

        Debug("Init_Channels: opened pipe %s",ch->comm_filename);


Any help or suggestions you all could provide would be much appreciated!!!


-BobDean

"You want to kiss the sky? Better learn how to kneel." -U2





_______________________________________________________
Say Bye to Slow Internet!
http://www.home.com/xinbox/signup.html



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?6137495.968306337764.JavaMail.imail>