1 /*
2     This file is part of libmicrospdy
3     Copyright Copyright (C) 2013 Andrey Uzunov
4 
5     This program is free software: you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation, either version 3 of the License, or
8     (at your option) any later version.
9 
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14 
15     You should have received a copy of the GNU General Public License
16     along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 /**
20  * @file common.c
21  * @brief  Common functions used by the tests.
22  * @author Andrey Uzunov
23  */
24 
25 
26 #include "common.h"
27 #include <sys/time.h>
28 
29 #ifdef __GNUC__
30 #define FUNC_CONSTRUCTOR(f) static void __attribute__ ((constructor)) f
31 #define FUNC_DESTRUCTOR(f) static void __attribute__ ((destructor)) f
32 #else  // !__GNUC__
33 #define FUNC_CONSTRUCTOR(f) _MHD_EXTERN void f
34 #define FUNC_DESTRUCTOR(f) _MHD_EXTERN void f
35 #endif  // __GNUC__
36 
FUNC_CONSTRUCTOR(constructor)37 FUNC_CONSTRUCTOR (constructor)()
38 {
39 	printf("\nTEST START -------------------------------------------------------\n");
40 }
41 
FUNC_DESTRUCTOR(destructor)42 FUNC_DESTRUCTOR (destructor)()
43 {
44 	printf("------------------------------------------------------- TEST END\n");
45 }
46 
47 uint16_t
get_port(uint16_t min)48 get_port(uint16_t min)
49 {
50 	struct timeval tv;
51 	gettimeofday(&tv, NULL);
52 	if(2 > min) min=2;
53 	uint16_t port =  min + (tv.tv_usec+10) % ((1 << 16)  - min);
54 
55 	//port = 12345;
56 	printf("Port used: %i\n", port);
57 
58 	return port;
59 }
60