1 //=============================================================================
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.
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"
22 const int UDP_PORT
= 3000;
23 const int SEC_TO_KEEP_SOCKET_OPEN
= 2;
25 #if defined (ACE_HAS_THREADS)
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
));
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));
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 *)
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
,
67 ACE_TEXT ("spawn_n ()")), -1);
69 ACE_Thread_Manager::instance ()->wait ();