2 //=============================================================================
6 * Driver program for the server. Note that it is easy to reuse the
7 * server for other distributed programs. Pretty much all that must
8 * change are the functions registered with the communciations
11 * @author Douglas C. Schmidt
13 //=============================================================================
17 #include "SMR_Server.h"
19 #include "ace/Log_Msg.h"
20 #include "ace/OS_NS_signal.h"
21 #include "ace/OS_NS_time.h"
22 #include "ace/OS_NS_stdlib.h"
23 #include "ace/OS_NS_sys_socket.h"
31 time_now
= ACE_OS::time (0);
32 temp
= ACE_OS::asctime (ACE_OS::localtime (&time_now
));
37 // Catch the obvious signals and die with dignity...
43 "%s exiting on signal %S\n",
49 // Returns TRUE if the program was started by INETD.
55 int size
= sizeof sin
;
57 return ACE_OS::getsockname (0,
58 reinterpret_cast<sockaddr
*> (&sin
),
62 // Does the drwho service.
65 do_drwho (SMR_Server
&smr_server
)
67 if (smr_server
.receive () == -1)
70 Options::program_name
));
72 if (smr_server
.send () == -1)
75 Options::program_name
));
78 // If the server is started with any argument at all then it doesn't
79 // fork off a child process to do the work. This is useful when
83 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
85 ACE_OS::signal (SIGTERM
, (ACE_SignalHandler
)exit_server
);
86 ACE_OS::signal (SIGINT
, (ACE_SignalHandler
)exit_server
);
87 ACE_OS::signal (SIGQUIT
, (ACE_SignalHandler
)exit_server
);
89 Options::set_options (argc
, argv
);
90 Options::set_opt (Options::STAND_ALONE_SERVER
);
92 int inetd_controlled
= started_by_inetd ();
94 if (!inetd_controlled
&& Options::get_opt (Options::BE_A_DAEMON
))
97 SMR_Server
smr_server (Options::port_number
);
100 do_drwho (smr_server
);
104 do_drwho (smr_server
);