diff options
author | schmidt <douglascraigschmidt@users.noreply.github.com> | 1999-02-09 17:51:04 +0000 |
---|---|---|
committer | schmidt <douglascraigschmidt@users.noreply.github.com> | 1999-02-09 17:51:04 +0000 |
commit | 9f25a794054ba39b13e8959a38baae6e564681e2 (patch) | |
tree | 3187d7230499a69da0cbd7567b985beeb8984ed9 /examples/IPC_SAP | |
parent | f5be245f39a0e76eb245e1a6347cd4252817b6ec (diff) | |
download | ATCD-9f25a794054ba39b13e8959a38baae6e564681e2.tar.gz |
.
Diffstat (limited to 'examples/IPC_SAP')
-rw-r--r-- | examples/IPC_SAP/TLI_SAP/CPP-client.cpp | 35 | ||||
-rw-r--r-- | examples/IPC_SAP/TLI_SAP/CPP-server.cpp | 42 | ||||
-rw-r--r-- | examples/IPC_SAP/TLI_SAP/db-client.cpp | 18 | ||||
-rw-r--r-- | examples/IPC_SAP/TLI_SAP/db-server.cpp | 57 | ||||
-rw-r--r-- | examples/IPC_SAP/TLI_SAP/ftp-client.cpp | 6 | ||||
-rw-r--r-- | examples/IPC_SAP/TLI_SAP/ftp-server.cpp | 35 | ||||
-rw-r--r-- | examples/IPC_SAP/TLI_SAP/signal_thread.c | 53 |
7 files changed, 121 insertions, 125 deletions
diff --git a/examples/IPC_SAP/TLI_SAP/CPP-client.cpp b/examples/IPC_SAP/TLI_SAP/CPP-client.cpp index cd5734c5e51..2a0dbc9dc01 100644 --- a/examples/IPC_SAP/TLI_SAP/CPP-client.cpp +++ b/examples/IPC_SAP/TLI_SAP/CPP-client.cpp @@ -21,7 +21,8 @@ int main (int argc, char *argv[]) ACE_INET_Addr remote_addr (r_port, host); ACE_INET_Addr local_addr (l_port); - ACE_DEBUG ((LM_DEBUG, "starting non-blocking connect\n")); + ACE_DEBUG ((LM_DEBUG, + "starting non-blocking connect\n")); // Initiate timed, non-blocking connection with server. ACE_TLI_Connector con; @@ -31,18 +32,25 @@ int main (int argc, char *argv[]) local_addr, 1) == -1) { if (errno != EWOULDBLOCK) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "connection failed"), 1); + ACE_ERROR_RETURN ((LM_ERROR, + "%p\n", + "connection failed"), + 1); - ACE_DEBUG ((LM_DEBUG, "starting timed connect\n")); + ACE_DEBUG ((LM_DEBUG, + "starting timed connect\n")); - // Check if non-blocking connection is in progress, - // and wait up to timeout seconds for it to complete. + // Check if non-blocking connection is in progress, and wait up + // to timeout seconds for it to complete. ACE_Time_Value tv (timeout); if (con.complete (cli_stream, &remote_addr, &tv) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "connection failed"), 1); + ACE_ERROR_RETURN ((LM_ERROR, + "%p\n", + "connection failed"), 1); else - ACE_DEBUG ((LM_DEBUG, "connected to %s\n", + ACE_DEBUG ((LM_DEBUG, + "connected to %s\n", remote_addr.get_host_name ())); } @@ -51,11 +59,17 @@ int main (int argc, char *argv[]) for (int r_bytes; (r_bytes = ACE_OS::read (ACE_STDIN, buf, sizeof buf)) > 0; ) if (cli_stream.send_n (buf, r_bytes) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "send_n"), 1); + ACE_ERROR_RETURN ((LM_ERROR, + "%p\n", + "send_n"), + 1); /* Explicitly close the connection */ if (cli_stream.close () == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "close"), -1); + ACE_ERROR_RETURN ((LM_ERROR, + "%p\n", + "close"), + -1); return 0; } @@ -63,6 +77,7 @@ int main (int argc, char *argv[]) int main (int, char *[]) { ACE_ERROR_RETURN ((LM_ERROR, - "your platform must support ACE_TLI\n"), 1); + "your platform isn't configured to support TLI\n"), + 1); } #endif /* ACE_HAS_TLI */ diff --git a/examples/IPC_SAP/TLI_SAP/CPP-server.cpp b/examples/IPC_SAP/TLI_SAP/CPP-server.cpp index ee89a2fc96f..e5e0068c676 100644 --- a/examples/IPC_SAP/TLI_SAP/CPP-server.cpp +++ b/examples/IPC_SAP/TLI_SAP/CPP-server.cpp @@ -6,7 +6,7 @@ ACE_RCSID(TLI_SAP, CPP_server, "$Id$") #if defined (ACE_HAS_TLI) -/* ACE_TLI Server */ +// ACE_TLI Server int main (int argc, char *argv[]) @@ -14,48 +14,60 @@ main (int argc, char *argv[]) u_short port = argc > 1 ? ACE_OS::atoi (argv[1]) : ACE_DEFAULT_SERVER_PORT; ACE_Time_Value timeout (argc > 2 ? ACE_OS::atoi (argv[2]) : ACE_DEFAULT_TIMEOUT); - /* Create a server address. */ + // Create a server address. ACE_INET_Addr addr (port); - /* Create a server, reuse the addr. */ + // Create a server, reuse the addr. ACE_TLI_Acceptor peer_acceptor; if (peer_acceptor.open (addr, 1) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "open"), -1); + ACE_ERROR_RETURN ((LM_ERROR, + "%p\n", + "open"), + -1); ACE_TLI_Stream new_stream; - ACE_DEBUG ((LM_DEBUG, "starting server at port %d\n", + ACE_DEBUG ((LM_DEBUG, + "starting server at port %d\n", addr.get_port_number ())); - /* Performs the iterative server activities */ + // Performs the iterative server activities for (;;) { char buf[BUFSIZ]; - /* Create a new ACE_TLI_Stream endpoint (note automatic restart - if errno == EINTR) */ + // Create a new ACE_TLI_Stream endpoint (note automatic restart + // if errno == EINTR). if (peer_acceptor.accept (new_stream, &addr, &timeout) == -1) { - ACE_ERROR ((LM_ERROR, "%p\n", "accept")); + ACE_ERROR ((LM_ERROR, + "%p\n", + "accept")); continue; } - ACE_DEBUG ((LM_DEBUG, "client %s connected from %d\n", - addr.get_host_name (), addr.get_port_number ())); + ACE_DEBUG ((LM_DEBUG, + "client %s connected from %d\n", + addr.get_host_name (), + addr.get_port_number ())); // Read data from client (terminate on error). for (int r_bytes; (r_bytes = new_stream.recv (buf, sizeof buf)) > 0; ) if (ACE_OS::write (ACE_STDOUT, buf, r_bytes) != r_bytes) - ACE_ERROR ((LM_ERROR, "%p\n", "ACE::send_n")); + ACE_ERROR ((LM_ERROR, + "%p\n", + "ACE::send_n")); // Close new endpoint (listening endpoint stays open). if (new_stream.close () == -1) - ACE_ERROR ((LM_ERROR, "%p\n", "close")); + ACE_ERROR ((LM_ERROR, + "%p\n", + "close")); } /* NOTREACHED */ @@ -64,6 +76,8 @@ main (int argc, char *argv[]) #else int main (int, char *[]) { - ACE_ERROR_RETURN ((LM_ERROR, "your platform must support ACE_TLI\n"), 1); + ACE_ERROR_RETURN ((LM_ERROR, + "your platform isn't configured to support TLI\n"), + 1); } #endif /* ACE_HAS_TLI */ diff --git a/examples/IPC_SAP/TLI_SAP/db-client.cpp b/examples/IPC_SAP/TLI_SAP/db-client.cpp index 6855b1bbc69..3790f6a20ce 100644 --- a/examples/IPC_SAP/TLI_SAP/db-client.cpp +++ b/examples/IPC_SAP/TLI_SAP/db-client.cpp @@ -11,20 +11,22 @@ int main (int argc, char *argv[]) { if (argc < 2) - ACE_ERROR_RETURN ((LM_ERROR, "Usage: %s employee_id [server-host port-number]\n", - argv[0]), -1); + ACE_ERROR_RETURN ((LM_ERROR, + "Usage: %s employee_id [server-host port-number]\n", + argv[0]), + -1); - const char *emp_num = argv[1]; + const char *emp_num = argv[1]; const char *host_name = argc < 3 ? ACE_DEFAULT_SERVER_HOST : argv[2]; unsigned short port = argc < 4 ? ACE_DEFAULT_SERVER_PORT : ACE_OS::atoi (argv[3]); - int n; - char buf[MAXLINE]; + int n; + char buf[MAXLINE]; ACE_TLI_Stream client; ACE_TLI_Connector con; if (con.connect (client, ACE_INET_Addr (port, host_name)) == -1) - ACE_OS::t_error ((char *)host_name), ACE_OS::exit (1); + ACE_OS::t_error ((char *) host_name), ACE_OS::exit (1); ACE_OS::strcpy (buf, emp_num); n = ACE_OS::strlen (buf); @@ -48,6 +50,8 @@ main (int argc, char *argv[]) #else int main (int, char *[]) { - ACE_ERROR_RETURN ((LM_ERROR, "your platform must support ACE_TLI\n"), 1); + ACE_ERROR_RETURN ((LM_ERROR, + "your platform isn't configured to support TLI\n"), + 1); } #endif /* ACE_HAS_TLI */ diff --git a/examples/IPC_SAP/TLI_SAP/db-server.cpp b/examples/IPC_SAP/TLI_SAP/db-server.cpp index 5ebe8a3b909..f363332317e 100644 --- a/examples/IPC_SAP/TLI_SAP/db-server.cpp +++ b/examples/IPC_SAP/TLI_SAP/db-server.cpp @@ -1,6 +1,6 @@ // $Id$ -/* Simple multi-threaded database server example. */ +// Simple multi-threaded database server example. #include "ace/TLI_Acceptor.h" #include "ace/Thread_Manager.h" @@ -9,7 +9,7 @@ ACE_RCSID(TLI_SAP, db_server, "$Id$") #if defined (ACE_HAS_THREADS) && defined (ACE_HAS_TLI) -/* Global thread manager. */ +// Global thread manager. ACE_Thread_Manager thr_mgr; void * @@ -22,23 +22,24 @@ lookup_name (ACE_HANDLE handle) }; static struct + { + int emp_id; + const char *emp_name; + } employee_db[] = { - int emp_id; - const char *emp_name; - } employee_db[] = - { - {123, "John Wayne Bobbit"}, - {124, "Cindy Crawford"}, - {125, "O. J. Simpson"}, - {126, "Bill Clinton"}, - {127, "Rush Limbaugh"}, - {128, "Michael Jackson"}, - {129, "George Burns"}, - {130, "Paula Jones"}, - {0, ""} - }; - - int n; + {123, "John Wayne Bobbit"}, + {124, "Woody Allen"}, + {125, "O. J. Simpson"}, + {126, "Bill Clinton"}, + {127, "Rush Limbaugh"}, + {128, "Michael Jackson"}, + {129, "Kenneth Starr"}, + {130, "Paula Jones"}, + {131, "Monica Lewinsky"}, + {132, "Marv Albert"}, + {0, ""} + }; + int flags; int employee_id; int index; @@ -47,10 +48,14 @@ lookup_name (ACE_HANDLE handle) char recvline[MAXLINE]; char sendline[MAXLINE]; - ACE_DEBUG ((LM_DEBUG, "stream handle = %d, thread id = %t\n", handle)); + ACE_DEBUG ((LM_DEBUG, + "stream handle = %d, thread id = %t\n", + handle)); stream.set_handle (handle); - if ((n = stream.recv (recvline, MAXLINE, &flags)) == -1) + ssize_t n = stream.recv (recvline, MAXLINE, &flags); + + if (n == -1) ACE_OS::t_error ("stream.recv error"); employee_id = ACE_OS::atoi (recvline); @@ -60,7 +65,8 @@ lookup_name (ACE_HANDLE handle) if (employee_id == employee_db[index].emp_id) { found = 1; - n = ACE_OS::sprintf (sendline, "%s", employee_db[index].emp_name); + n = ACE_OS::sprintf (sendline, + "%s", employee_db[index].emp_name); } if (found == 0) @@ -92,12 +98,13 @@ main (int argc, char *argv[]) for (;;) { if (server.accept (new_stream) == -1) - ::t_error ("server.accept error"); + ACE_OS::t_error ("server.accept error"); if (thr_mgr.spawn (ACE_THR_FUNC (lookup_name), (void *) new_stream.get_handle (), THR_DETACHED) == -1) - ACE_DEBUG ((LM_ERROR, "server: can't create worker thread %d\n")); + ACE_DEBUG ((LM_ERROR, + "server: can't create worker thread %d\n")); } ACE_NOTREACHED (return 0); @@ -106,6 +113,8 @@ main (int argc, char *argv[]) #include <stdio.h> int main (int, char *[]) { - ACE_ERROR_RETURN ((LM_ERROR, "platform does not support ACE_TLI\n"), 1); + ACE_ERROR_RETURN ((LM_ERROR, + "platform isn't configured to support TLI\n"), + 1); } #endif /* ACE_HAS_THREADS */ diff --git a/examples/IPC_SAP/TLI_SAP/ftp-client.cpp b/examples/IPC_SAP/TLI_SAP/ftp-client.cpp index 03427c37224..89d51063490 100644 --- a/examples/IPC_SAP/TLI_SAP/ftp-client.cpp +++ b/examples/IPC_SAP/TLI_SAP/ftp-client.cpp @@ -14,7 +14,7 @@ main (int argc, char *argv[]) const char *filename = argv[1]; const char *host_name = argc < 3 ? ACE_DEFAULT_SERVER_HOST : argv[2]; - unsigned short port = argc < 4 ? ACE_DEFAULT_SERVER_PORT : ACE_OS::atoi (argv[3]); + u_short port = argc < 4 ? ACE_DEFAULT_SERVER_PORT : ACE_OS::atoi (argv[3]); ACE_TLI_Stream client; ACE_TLI_Connector con; @@ -39,6 +39,8 @@ main (int argc, char *argv[]) #else int main (int, char *[]) { - ACE_ERROR_RETURN ((LM_ERROR, "your platform does not support ACE_TLI\n"), 1); + ACE_ERROR_RETURN ((LM_ERROR, + "your platform isn't configured to support TLI\n"), + 1); } #endif /* ACE_HAS_TLI */ diff --git a/examples/IPC_SAP/TLI_SAP/ftp-server.cpp b/examples/IPC_SAP/TLI_SAP/ftp-server.cpp index 9f887d8bf49..3d185fa5e2d 100644 --- a/examples/IPC_SAP/TLI_SAP/ftp-server.cpp +++ b/examples/IPC_SAP/TLI_SAP/ftp-server.cpp @@ -1,6 +1,6 @@ // $Id$ -/* Simple file transfer example */ +// Simple file transfer example #include "ace/Thread_Manager.h" #include "ace/TLI_Acceptor.h" @@ -15,23 +15,24 @@ void * read_file (void *fd) { ACE_TLI_Stream stream; - char buf[BUFSIZ]; - int flags = 0; - int n; + char buf[BUFSIZ]; + int flags = 0; + ssize_t n; - // Cast the arg to a long, first, because a pointer is the same - // size as a long on all current ACE platforms. + // Cast the arg to a long, first, because a pointer is the same size + // as a long on all current ACE platforms. stream.set_handle ((int) (long) fd); - ACE_OS::printf ("start (tid = %d, fd = %d)\n", ACE_OS::thr_self (), stream.get_handle ()); - ACE_OS::fflush (stdout); + ACE_DEBUG(("start (tid = %t, fd = %d)\n", + stream.get_handle ())) while ((n = stream.recv (buf, sizeof buf, &flags)) > 0) continue; ACE_UNUSED_ARG (n); - ACE_OS::printf ("finish (tid = %d, fd = %d)\n", ACE_OS::thr_self (), stream.get_handle ()); + ACE_DEBUG (("finish (tid = %t, fd = %d)\n", + stream.get_handle ())); if (stream.close () == -1) ACE_OS::t_error ("stream.close error"); @@ -43,19 +44,21 @@ int main (int argc, char *argv[]) { u_short port = argc > 1 ? ACE_OS::atoi (argv[1]) : ACE_DEFAULT_SERVER_PORT; - ACE_TLI_Acceptor server; - ACE_TLI_Stream new_stream; + ACE_TLI_Acceptor server; + ACE_TLI_Stream new_stream; // Open the server and reuse the address if in use... if (server.open (ACE_INET_Addr (port), 1) == -1) ACE_OS::t_error ("server.open"), ACE_OS::exit (1); - /* Wait for a connection from a client. This is an example of a concurrent server */ + // Wait for a connection from a client. This is an example of a + // concurrent server. for (int count = 1; ; count++) { - ACE_OS::fprintf (stderr, "thread %d, blocking for accept #%d\n", - ACE_OS::thr_self (), count); + ACE_DEBUG ((LM_DEBUG, + "thread %t, blocking for accept #%d\n", + count)); if (server.accept (new_stream) == -1) ACE_OS::t_error ("server.accept error"); @@ -72,6 +75,8 @@ main (int argc, char *argv[]) #include <stdio.h> int main (int, char *[]) { - ACE_ERROR_RETURN ((LM_ERROR, "your platform must support ACE_TLI\n"), 1); + ACE_ERROR_RETURN ((LM_ERROR, + "your platform isn't configured to support TLI\n"), + 1); } #endif /* ACE_HAS_THREADS */ diff --git a/examples/IPC_SAP/TLI_SAP/signal_thread.c b/examples/IPC_SAP/TLI_SAP/signal_thread.c deleted file mode 100644 index e3a3485f1a2..00000000000 --- a/examples/IPC_SAP/TLI_SAP/signal_thread.c +++ /dev/null @@ -1,53 +0,0 @@ -#define _REENTRANT -// @(#)signal_thread.c 1.1 10/18/96 - -#include <stdio.h> -#include <stdlib.h> -#include <signal.h> -#include <thread.h> -#include <synch.h> -#include <unistd.h> - -void *handle (v) - void *v; -{ - sigset_t set; - - sigemptyset (&set); - sigaddset (&set, SIGINT); - - for (;;) - if (sigwait (&set) != SIGINT) - perror ("sigwait"), exit (1); - else - fprintf (stderr, "got sigint!\n"); -} - -int -main (void) -{ - int retval; - sigset_t set; - thread_t t_id; - - sigemptyset (&set); - sigaddset (&set, SIGINT); - - if (sigprocmask (SIG_BLOCK, &set, 0) == -1) - perror ("sigprocmask"), exit (1); - - if (thr_sigsetmask (SIG_BLOCK, &set, 0) == -1) - perror ("sigprocmask"), exit (1); - - if (thr_create (0, 0, handle, 0, THR_DETACHED, &t_id) != 0) - perror ("thr_create"), exit (1); - - for (;;) - { - fprintf (stderr, "blocking for read in thread\n"); - if (read (0, &retval, sizeof retval) != sizeof retval) - perror ("read"); - } - fprintf (stderr, "I'm exiting!\n"); - return 0; -} |