Re: Synchronous signal delivery..

Werner Almesberger
2003-02-15T05:04:13Z

I wrote:
> ssize_t overwrite(int fd,
> const void *data_if_empty,size_t size_if_empty,
> const void *data_if_full,size_t size_if_full,
> int *was_empty);

Bah, rubbish. Make this

ssize_t overwrite(int fd,const void *data,size_t size);

If the pipe/queue is empty, don't write, and return 0. Now, this
could probably be implemented with a flag to send(2) (then this
wouldn't work for pipes, but you could use socketpair(2) for a
similar effect). Example:

void add_signal(int signum)
{
static int signal_set = 0;
int new_signal = 1 << signum;
int sent;

signal_set |= new_signal;
sent = send(fd,&signal_set,sizeof(int),MSG_OVERWRITE);
if (!sent) {
send(fd,&new_signal,sizeof(int),0);
signal_set = new_signal;
}
}

- Werner

--
_________________________________________________________________________
/ Werner Almesberger, Buenos Aires, Argentina wa@almesberger.net /
/_http://www.almesberger.net/____________________________________________/