ckchee@dgp.toronto.edu (Chuan Chee) (09/22/90)
I would like suggestions on how to best solve the following problem. Suppose you have many named pipes where some of them have many writers and some have only 1 writer but all have 1 reader. All writers call a routine (which I'll call write_pipe() ). However, since each writer is a totally different (unrelated) process, write_pipe() is linked into each process (with different data space each). What I'd like to do is keep a threshhold at 85% of the pipe capacity (which I believe is 10K bytes) so at after 85%, only high priority messages go through. I am working under the assumption that fstat() is slow. For the single writer case, I have the following solution: static p_size = 0; int write_pipe(filedes, data, len, priority) { if (priority == LOW) { if (p_size > THRESHHOLD) { fstat (statbuf); p_size = statbuf.size; if (p_size > THRESHHOLD) return (OVERFLOW); } } p_size += write (filedes, data, len); return (OK); } Note: I make no claims that the above checks all errors, I quickly wrote it to show my point. Essentially, fstat() is only called when the writer has written enough bytes to overflow the pipe. However, the reader is also reading from the pipe, hence the second if(p_size...). Unfortunately, the above does not work when there are multiple writers since p_size is a "different" variable in each process's data space. (1) Create a shared memory - however, there must be a semaphore around updating the p_size variable. (2) Do fstat() always (only with chosen pipes) - ie. call another routine (eg set_multiple_pipe(filedes) ) to tell which filedes/pipe has multiple writers. However, calling fstat() for every write_pipe() is inefficient. Are there any other suggestions? In case it matters, I'm using Xenix 2.2.3. Thanks very much. ...Chuan Chee ckchee@dgp.utoronto.ca ckchee@dgp.toronto.edu (internet) ckchee@dgp.utoronto (bitnet)