Use =default for skeleton copy constructor
[ACE_TAO.git] / ACE / examples / System_V_IPC / SV_Message_Queues / MQ_Server.cpp
blobb38313766a2b0a8a4e3fed59193b3d9e58a820d6
1 #include "ace/Signal.h"
2 #include "ace/SV_Message_Queue.h"
4 // FUZZ: disable check_for_streams_include
5 #include "ace/streams.h"
7 #include "test.h"
8 #include "ace/OS_NS_stdio.h"
9 #include "ace/OS_NS_unistd.h"
10 #include "ace/OS_NS_stdlib.h"
13 #if defined (ACE_HAS_SYSV_IPC) && !defined(ACE_LACKS_SYSV_SHMEM)
15 // Must be global for signal Message...
16 static ACE_SV_Message_Queue ace_sv_message_queue (SRV_KEY,
17 ACE_SV_Message_Queue::ACE_CREATE);
19 extern "C" void
20 handler (int)
22 if (ace_sv_message_queue.remove () < 0)
23 ACE_OS::perror ("ace_sv_message_queue.close"), ACE_OS::exit (1);
24 ACE_OS::exit (0);
27 int
28 ACE_TMAIN (int, ACE_TCHAR *[])
30 long pid = long (ACE_OS::getpid ());
31 Message_Block recv_msg (SRV_ID);
32 Message_Block send_msg (0,
33 pid,
34 ACE_OS::cuserid (static_cast<char *> (0)),
35 "I received your message.");
37 // Register a signal handler.
38 ACE_Sig_Action sa ((ACE_SignalHandler) handler, SIGINT);
39 ACE_UNUSED_ARG (sa);
41 for (;;)
43 if (ace_sv_message_queue.recv (recv_msg,
44 sizeof (Message_Data),
45 recv_msg.type ()) == -1)
46 ACE_OS::perror ("ace_sv_message_queue.recv"), ACE_OS::exit (1);
48 cout << "a msg of length "
49 << recv_msg.length ()
50 << " sent from client "
51 << recv_msg.pid ()
52 << " (user "
53 << recv_msg.user () << "): "
54 << recv_msg.text () << "\n";
56 cout.flush ();
58 send_msg.type (recv_msg.pid ());
60 if (ace_sv_message_queue.send (send_msg,
61 send_msg.length ()) == -1)
62 ACE_OS::perror ("ace_sv_message_queue.send"), ACE_OS::exit (1);
65 ACE_NOTREACHED (return 0;)
68 #else
70 #include "ace/Log_Msg.h"
72 int ACE_TMAIN (int, ACE_TCHAR *[])
74 ACE_ERROR ((LM_ERROR,
75 "SYSV IPC, or SYSV SHMEM is not supported on this platform\n"));
76 return 0;
78 #endif /* ACE_HAS_SYSV_IPC && !ACE_LACKS_SYSV_SHMEM */