blob: 0f399034ec194499eb2ddf71f953f071659ce580 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
#include "ace/SV_Shared_Memory.h"
#include "ace/Log_Msg.h"
#include "SV_Shared_Memory_Test.h"
#include "ace/OS_NS_stdio.h"
#include "ace/OS_NS_stdlib.h"
#include "ace/OS_NS_unistd.h"
#if defined (ACE_HAS_SYSV_IPC) && !defined(ACE_LACKS_SYSV_SHMEM)
static void
client (void)
{
ACE_SV_Shared_Memory shm_client;
if (shm_client.open_and_attach (SHM_KEY, SHMSZ) == -1)
ACE_OS::perror ("open"), ACE_OS::exit (1);
for (char *s = (char *) shm_client.get_segment_ptr (); *s != '\0'; s++)
putchar (*s);
putchar ('\n');
*(char *) shm_client.get_segment_ptr () = '*';
ACE_OS::exit (0);
}
static void
server (void)
{
ACE_SV_Shared_Memory shm_server;
if (shm_server.open_and_attach (SHM_KEY, SHMSZ, ACE_SV_Shared_Memory::ACE_CREATE) == -1)
ACE_OS::perror ("open"), ACE_OS::exit (1);
char *s = (char *) shm_server.get_segment_ptr ();
for (char c = 'a'; c <= 'z'; c++)
*s++ = c;
*s = '\0';
for (s = (char *) shm_server.get_segment_ptr (); *s != '*'; )
ACE_OS::sleep (1);
if (shm_server.remove () < 0)
ACE_OS::perror ("remove"), ACE_OS::exit (1);
ACE_OS::exit (0);
}
int
ACE_TMAIN(int, ACE_TCHAR *argv[])
{
switch (ACE_OS::fork ())
{
case -1:
ACE_OS::perror (argv[0]), ACE_OS::exit (1);
case 0:
ACE_OS::sleep (1);
client ();
default:
server ();
}
return 0;
}
#else
int ACE_TMAIN (int, ACE_TCHAR *[])
{
ACE_ERROR ((LM_ERROR,
"SYSV IPC, or SYSV SHMEM is not supported on this platform\n"));
return 0;
}
#endif /* ACE_HAS_SYSV_IPC && !ACE_LACKS_SYSV_SHMEM */
|