CUBRID Engine  latest
cas_common.h
Go to the documentation of this file.
1 /*
2  * Copyright 2008 Search Solution Corporation
3  * Copyright 2016 CUBRID Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 
20 /*
21  * cas_common.h -
22  */
23 
24 #ifndef _CAS_COMMON_H_
25 #define _CAS_COMMON_H_
26 
27 #ident "$Id$"
28 
29 #if !defined(WINDOWS)
30 #include <sys/types.h>
31 #include <sys/socket.h>
32 #endif
33 
34 #include "porting.h"
35 #define makestring1(x) #x
36 #define makestring(x) makestring1(x)
37 
38 #define MAX_SERVER_H_ID 256
39 #define MAX_BIND_VALUE 10240
40 #define MAX_QUERY_LEN 100000
41 #define CAS_RUNNER_CONF "cas_runner.conf"
42 #define CAS_RUNNER_CONF_ENV "CAS_RUNNER_CONF"
43 #define CAS_USE_DEFAULT_DB_PARAM -2
44 
45 #define ON 1
46 #define OFF 0
47 
48 #define TRUE 1
49 #define FALSE 0
50 
51 #define INT_STR_LEN 16
52 
53 #define MALLOC(SIZE) malloc(SIZE)
54 #define REALLOC(PTR, SIZE) \
55  ((PTR == NULL) ? malloc(SIZE) : realloc(PTR, SIZE))
56 #define FREE(PTR) free(PTR)
57 
58 #define FREE_MEM(PTR) \
59  do { \
60  if (PTR) { \
61  FREE(PTR); \
62  PTR = 0; \
63  } \
64  } while (0)
65 
66 #define ALLOC_COPY(PTR, STR) \
67  do { \
68  if (STR == NULL) \
69  PTR = NULL; \
70  else { \
71  PTR = (char *) MALLOC(strlen(STR) + 1); \
72  if (PTR) { \
73  strcpy(PTR, STR); \
74  } \
75  } \
76  } while (0)
77 
78 #if defined(WINDOWS)
79 #define CLOSE_SOCKET(X) \
80  do { \
81  if (!IS_INVALID_SOCKET(X)) closesocket(X); \
82  (X) = INVALID_SOCKET; \
83  } while (0)
84 #else
85 #define CLOSE_SOCKET(X) \
86  do { \
87  if (!IS_INVALID_SOCKET(X)) close(X); \
88  (X) = INVALID_SOCKET; \
89  } while (0)
90 #endif
91 
92 #define ALLOC_N_COPY(PTR, STR, SIZE) \
93  do { \
94  if (STR == NULL) \
95  PTR = NULL; \
96  else { \
97  PTR = MALLOC(SIZE); \
98  if (PTR) { \
99  strncpy(PTR, STR, SIZE); \
100  PTR[SIZE - 1] = '\0'; \
101  } \
102  } \
103  } while (0)
104 
105 #if defined(WINDOWS)
106 #define SLEEP_SEC(X) Sleep((X) * 1000)
107 #define SLEEP_MILISEC(SEC, MSEC) Sleep((SEC) * 1000 + (MSEC))
108 #else
109 #define SLEEP_SEC(X) sleep(X)
110 #define SLEEP_MILISEC(sec, msec) \
111  do { \
112  struct timeval sleep_time_val; \
113  sleep_time_val.tv_sec = sec; \
114  sleep_time_val.tv_usec = (msec) * 1000; \
115  select(0, 0, 0, 0, &sleep_time_val); \
116  } while(0)
117 #endif
118 
119 
120 #if defined(WINDOWS)
121 #define THREAD_BEGIN(THR_ID, FUNC, ARG) \
122  do { \
123  THR_ID = (pthread_t) _beginthread(FUNC, 0, (void*) (ARG)); \
124  } while(0)
125 #else
126 #define THREAD_BEGIN(THR_ID, FUNC, ARG) \
127  do { \
128  pthread_attr_t thread_attr; \
129  pthread_attr_init(&thread_attr); \
130  pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED); \
131  pthread_create(&(THR_ID), &thread_attr, FUNC, ARG); \
132  pthread_attr_destroy(&thread_attr); \
133  } while (0)
134 #endif
135 
136 
137 #if defined(WINDOWS)
138 #define READ_FROM_SOCKET(fd, buf, size) recv(fd, buf, size, 0)
139 #define WRITE_TO_SOCKET(fd, buf, size) send(fd, buf, size, 0)
140 #else
141 #define READ_FROM_SOCKET(fd, buf, size) read(fd, buf, size)
142 #define WRITE_TO_SOCKET(fd, buf, size) write(fd, buf, size)
143 #endif
144 
145 #if defined(WINDOWS)
146 #define THREAD_FUNC void
147 #else
148 #define THREAD_FUNC void*
149 #endif
150 
151 #if defined(WINDOWS) || defined(SOLARIS) || defined(HPUX)
152 typedef int T_SOCKLEN;
153 #elif defined(UNIXWARE7)
154 typedef size_t T_SOCKLEN;
155 #else
156 typedef socklen_t T_SOCKLEN;
157 #endif
158 
159 enum
160 {
166 };
167 
168 /* default charset for JDBC : ISO8859-1 */
169 #if !defined(CAS_FOR_ORACLE) && !defined(CAS_FOR_MYSQL)
170 #define CAS_SCHEMA_DEFAULT_CHARSET (lang_charset ())
171 #else
172 #define CAS_SCHEMA_DEFAULT_CHARSET 0
173 #endif
174 
175 
176 extern int uts_key_check_local_host (void);
177 
178 #endif /* _CAS_COMMON_H_ */
socklen_t T_SOCKLEN
Definition: cas_common.h:156
int uts_key_check_local_host(void)