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
;
15 ACE_TLI_Stream stream
;
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)
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");
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
55 for (int count
= 1; ; count
++)
58 "thread %t, blocking for accept #%d\n",
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);
74 int ACE_TMAIN (int, ACE_TCHAR
*[])
76 ACE_ERROR_RETURN ((LM_ERROR
,
77 "your platform isn't configured to support TLI\n"),
80 #endif /* ACE_HAS_THREADS */