Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / ACE / tests / Bug_4189_Regression_Test.cpp
blob1ccd0e1a76872c72d9f3fcf5110bb35bfb79778a
1 //=============================================================================
2 /**
3 * @file Bug_4189_Regression_Test.cpp
5 * This test shows the reuse address issue on broadcast sockets.
6 * Start two process instances of this test on the same host within x sec.
7 * For broadcast sockets it should be possible to open the same port more than
8 * once at the time on a host.
9 */
10 //=============================================================================
12 #include "test_config.h"
13 #include "ace/OS_NS_string.h"
14 #include "ace/OS_NS_unistd.h"
15 #include "ace/OS_NS_sys_time.h"
16 #include "ace/Log_Msg.h"
17 #include "ace/SOCK_Dgram_Bcast.h"
18 #include "ace/Thread_Manager.h"
20 int result = 0;
22 const int UDP_PORT = 3000;
23 const int SEC_TO_KEEP_SOCKET_OPEN = 2;
25 #if defined (ACE_HAS_THREADS)
27 int reuseAddr_test ()
29 # if defined ACE_WIN32 || !defined ACE_LACKS_IOCTL
30 ACE_SOCK_Dgram_Bcast sock1;
31 if (sock1.open(ACE_INET_Addr(UDP_PORT),PF_INET,0,1) != 0)
33 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Could not open socket for broadcast on port %d\n"), UDP_PORT ));
34 ++result;
36 else
38 // Keep the socket open for some time
39 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Opened socket on port %d and keep it open for %d sec\n"), UDP_PORT, SEC_TO_KEEP_SOCKET_OPEN));
41 ACE_OS::sleep(ACE_Time_Value(SEC_TO_KEEP_SOCKET_OPEN,0));
43 sock1.close();
45 # endif
46 return result;
49 /* \brief Thread main function to run run_receiver function
50 \note run_receiver return valu is stored in receiver_exit_code global variable
52 static ACE_THR_FUNC_RETURN run_thread_receiver (void *)
54 reuseAddr_test ();
55 return 0;
57 #endif /* defined (ACE_HAS_THREADS) */
59 int run_main (int, ACE_TCHAR *[])
61 ACE_START_TEST (ACE_TEXT ("Bug_4189_Regression_Test"));
63 #if defined (ACE_HAS_THREADS)
64 if (ACE_Thread_Manager::instance ()->spawn_n (2, run_thread_receiver) == -1)
65 ACE_ERROR_RETURN ((LM_ERROR,
66 ACE_TEXT ("%p\n"),
67 ACE_TEXT ("spawn_n ()")), -1);
69 ACE_Thread_Manager::instance ()->wait ();
70 #endif
72 ACE_END_TEST;
73 return result;