1 #include "ace/OS_main.h"
2 #include "ace/ATM_Acceptor.h"
3 #include "ace/ATM_Addr.h"
4 #include "ace/High_Res_Timer.h"
5 #include "ace/Log_Msg.h"
8 #if defined (ACE_HAS_ATM)
12 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
14 ACE_Time_Value
timeout (ACE_DEFAULT_TIMEOUT
);
16 //unsigned char selector = ACE_ATM_Addr::DEFAULT_SELECTOR;
17 //int selector_specified = 0;
20 ACE_ERROR_RETURN ((LM_ERROR
,
21 "Usage: %s [selector]\n",
25 // Create a server address.
27 //if (selector_specified)
28 unsigned char selector
= ( argc
== 2 ) ? ACE_OS::atoi( argv
[ 1 ]) : ACE_ATM_Addr::DEFAULT_SELECTOR
;
29 addr
.set_selector( selector
);
30 ACE_OS::printf( "ATM_Server: selector changed to %d\n", addr
.get_selector());
33 // Create a server, reuse the addr.
34 ACE_ATM_Acceptor peer_acceptor
;
35 ACE_ATM_Params params
;
37 // Not sure why but reuse_addr set to true/1 causes problems for
38 // FORE/XTI/ATM - this is now handled in ACE_ATM_Acceptor::open()
40 ACE_HANDLE ret
= peer_acceptor
.open (addr
, 5, params
);
41 if ( ret
== ACE_INVALID_HANDLE
)
42 ACE_ERROR_RETURN ((LM_ERROR
,
47 ACE_ATM_Stream new_stream
;
48 ACE_ATM_Addr local_addr
;
50 local_addr
.set_selector( selector
);
51 peer_acceptor
.get_local_addr( local_addr
);
54 "starting server at address %s\n",
55 local_addr
.addr_to_string ()));
57 // Performs the iterative server activities
59 ACE_High_Res_Timer timer
;
67 // Create a new ACE_ATM_Stream endpoint (note automatic restart
68 // if errno == EINTR).
69 ACE_OS::printf( "ATM_Server: expecting clients\n" );
71 if (peer_acceptor
.accept (new_stream
,
81 ACE_OS::printf( "ATM_Server: got a connection\n" );
85 // This has problem on PMP connections on NT
86 //new_stream.get_vpi_vci(vpi, vci);
88 "connected to VPI %d VCI %d\n",
91 ACE_OS::printf( "ATM_Server: connection accepted\n" );
94 "client %s connected\n",
95 addr
.addr_to_string ()));
97 "client %s connected to host\n",
98 new_stream
.get_peer_name ()));
100 // Read data from client (terminate on error).
110 (r_bytes
= new_stream
.recv (buf
, sizeof buf
, 0)) > 0; )
112 // ACE_OS::printf( "ATM_Server: received %dB\n", r_bytes );
114 // if (ACE_OS::write (ACE_STDOUT,
116 // r_bytes) != r_bytes)
117 // ACE_ERROR ((LM_ERROR,
122 if ( total
> 10000000 )
127 timer
.elapsed_time_incr( tv
);
128 real_time
= tv
.sec() * ACE_ONE_SECOND_IN_USECS
+ tv
.usec();
130 actual_rate
= ( double )recvd
* ( double )8 / real_time
;
132 ACE_DEBUG ((LM_DEBUG
,
133 ACE_TEXT ("(%t) bytes = %d, usec = %f, rate = %0.00f Mbps\n"),
136 actual_rate
< 0 ? 0 : actual_rate
));
139 // Close new endpoint (listening endpoint stays open).
140 if (new_stream
.close () == -1)
141 ACE_ERROR ((LM_ERROR
,
150 int ACE_TMAIN (int, ACE_TCHAR
*[])
152 ACE_ERROR_RETURN ((LM_ERROR
,
153 "your platform isn't configured to support ATM\n"),
156 #endif /* ACE_HAS_ATM */