Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / examples / IPC_SAP / TLI_SAP / ftp-server.cpp
blob735a3f327bb5c132c4636205c5751e9ebdcc9ec5
1 // Simple file transfer example
3 #include "ace/OS_NS_stdio.h"
4 #include "ace/Thread_Manager.h"
5 #include "ace/TLI_Acceptor.h"
8 #if defined (ACE_HAS_THREADS) && defined (ACE_HAS_TLI)
10 ACE_Thread_Manager thr_mgr;
12 void *
13 read_file (void *fd)
15 ACE_TLI_Stream stream;
16 char buf[BUFSIZ];
17 int flags = 0;
18 ssize_t n;
20 // Cast the arg to a long, first, because a pointer is the same size
21 // as a long on all current ACE platforms.
22 stream.set_handle ((int) (long) fd);
24 ACE_DEBUG((LM_DEBUG, "start (tid = %t, fd = %d)\n",
25 stream.get_handle ()));
27 while ((n = stream.recv (buf, sizeof buf, &flags)) > 0)
28 continue;
30 ACE_UNUSED_ARG (n);
32 ACE_DEBUG ((LM_DEBUG,"finish (tid = %t, fd = %d)\n",
33 stream.get_handle ()));
35 if (stream.close () == -1)
36 ACE_OS::t_error ("stream.close error");
38 return 0;
41 int
42 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
44 u_short port = argc > 1 ? ACE_OS::atoi (argv[1]) : ACE_DEFAULT_SERVER_PORT;
45 ACE_TLI_Acceptor server;
46 ACE_TLI_Stream new_stream;
48 // Open the server and reuse the address if in use...
49 if (server.open (ACE_INET_Addr (port), 1) == -1)
50 ACE_OS::t_error ("server.open"), ACE_OS::exit (1);
52 // Wait for a connection from a client. This is an example of a
53 // concurrent server.
55 for (int count = 1; ; count++)
57 ACE_DEBUG ((LM_DEBUG,
58 "thread %t, blocking for accept #%d\n",
59 count));
61 if (server.accept (new_stream) == -1)
62 ACE_OS::t_error ("server.accept error");
64 else if (thr_mgr.spawn (ACE_THR_FUNC (read_file),
65 (void *) new_stream.get_handle (),
66 THR_DETACHED | THR_BOUND) == -1)
67 ACE_OS::perror ("can't create worker thread\n");
70 ACE_NOTREACHED (return 0);
72 #else
73 #include <stdio.h>
74 int ACE_TMAIN (int, ACE_TCHAR *[])
76 ACE_ERROR_RETURN ((LM_ERROR,
77 "your platform isn't configured to support TLI\n"),
78 1);
80 #endif /* ACE_HAS_THREADS */