Hi Daniel,

I think the reply will be the same for RTL & RTAI users :-).

On Thu, Jun 29, 2000 at 08:31:15PM -0500, daniel sheltraw wrote:
> Hello RTAIers
> 
> Would someone please write me a code snippet which shows the proper
> usage of the select function when used to wait for data to be sent to a fifo 
> from kernel-space. 

man select is your best friend.

> Does select to a busy-wait?

Waiting depends on the last parameter of select function. I think the 
waiting is active (ie other processes are run).

Some chunks of my code (messy, not exactly what you want, it's about
writing to a fifo from user space, easy to modify):

----------------------------------

static int fifo_0;
static struct timeval timeout={0,10000}; // timeout fifo operations
static fd_set fds;                      // for select (fifo)
static char *str="/dev/rtf0";

static void openFifo()
{ if((fifo_0=open(str,O_WRONLY))==-1)   // open fifo
  { fprintf(stderr,"fifo open %s, %s\n",str,strerror(errno)); 
    exit(0);                    // if failed
  }
  atexit(closeFifo);
}

static void closeFifo()
{ close(fifo_0);
}

void writeFifo(int code)
{ int j;
  FD_ZERO(&fds);
  FD_SET(fifo_0,&fds);
  if((j=select(fifo_0+1,NULL,&fds,NULL,&timeout))>0) // if OK to write
  { if((j=write(fifo_0,(char *)&code,sizeof(int)))!=sizeof(int))
    { fprintf(stderr,"writeFifo/write returned %d, %s\n",j,strerror(errno));
      exit(0);
    }
  }
  else
  { fprintf(stderr,"writeFifo/fifo not ready for write, %d chars written\n",j);
    exit(0);
  }
}

-----------------------------------

Regards,

pa

-- 
..........................................................................
Pavel Andris                               | tel: +421 7 5941 2167
Institute of Control Theory and Robotics   | fax: +421 7 5477 6045
Slovak Academy of Sciences                 | 
Dubravska cesta 9                          | e-mail: [EMAIL PROTECTED]
SK - 842 37 Bratislava                     |
Slovakia                                   |
.........................................................................
-- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
---
For more information on Real-Time Linux see:
http://www.rtlinux.org/rtlinux/

Reply via email to