Re: pipes
- From: CptDondo <yan@xxxxxxxxxxxxxxxx>
- Date: Wed, 29 Aug 2007 12:39:48 -0700
Rainer Weikusat wrote:
CptDondo <yan@xxxxxxxxxxxxxxxx> writes:
[...]
From what I gather, I'm better off using BSD mmap, rather than SysV
IPC... Right?
I think mmap is easier to use.
And in essence, all I have to do on the server is something like:
fd = open(somefile,O_WRONLY);
mmap(some block, PROT_WRITE....,fd)
then write to fd and do a msync????
Assuming a suitable file exists:
fd = open(somefile, O_RDWR);
p = mmap(NULL, length_of_data, PROT_READ | PROT_WRITE, MAP_SHARED,
fd, 0);
close(fd)
Afterwards, you can just use the memory area pointed to by 'p' like
any other memory area.
On the client,
fd = open(somefile,O_RDONLY);
mmap(some block, PROT_READ....,fd)
fd = open(somefile, O_RDONLY);
p = mmap(NULL, length_of_data, PROT_READ, MAP_SHARED, fd, 0);
close(fd);
Both 'client p' and 'server p' will point the same area of physical
memory from now on. 'msync' is only needed if you want to ensure that
changes are written to disk. You will need to come up with some sort
of 'access protocol' to ensure that the client doesn't read from the
same part of this area the server is currently writing to.
That's too easy... :-)
One last question about the "real time" aspect of this:
I only have one process that would write to this area. So if in the server I set
p[0] = -1;
write ...
p[0] = 0;
then the client would know not to try to read the area until p[0] == 0. Would this work? Or are the writes buffered somehow?
Thanks!
--Yan
.
- Prev by Date: Re: multi-process locking
- Next by Date: Re: putenv for AIX and ifdef for AIX
- Previous by thread: Re: pipes
- Next by thread: Re: pipes
- Index(es):
Relevant Pages
|