sedna 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/{CHANGES → CHANGES.rdoc} +9 -0
- data/{README → README.rdoc} +23 -25
- data/Rakefile +32 -9
- data/ext/{extconf.rb → sedna/extconf.rb} +33 -21
- data/ext/{sedna.c → sedna/sedna.c} +48 -40
- data/test/sedna_test.rb +9 -9
- data/vendor/sedna/AUTHORS +18 -0
- data/vendor/sedna/COPYRIGHT +90 -0
- data/vendor/sedna/LICENSE +202 -0
- data/vendor/sedna/Makefile.include +423 -0
- data/vendor/sedna/Makefile.platform +31 -0
- data/vendor/sedna/depend.sed +48 -0
- data/vendor/sedna/driver/c/Makefile +98 -0
- data/vendor/sedna/driver/c/libsedna.c +1998 -0
- data/vendor/sedna/driver/c/libsedna.h +199 -0
- data/vendor/sedna/driver/c/sednamt.def +21 -0
- data/vendor/sedna/driver/c/sp_defs.h +186 -0
- data/vendor/sedna/kernel/common/FastXptrHash.cpp +101 -0
- data/vendor/sedna/kernel/common/IntHash.h +314 -0
- data/vendor/sedna/kernel/common/IntList.h +224 -0
- data/vendor/sedna/kernel/common/Makefile +30 -0
- data/vendor/sedna/kernel/common/SSMMsg.cpp +459 -0
- data/vendor/sedna/kernel/common/SSMMsg.h +142 -0
- data/vendor/sedna/kernel/common/XptrHash.h +435 -0
- data/vendor/sedna/kernel/common/argtable.c +972 -0
- data/vendor/sedna/kernel/common/argtable.h +896 -0
- data/vendor/sedna/kernel/common/base.cpp +339 -0
- data/vendor/sedna/kernel/common/base.h +226 -0
- data/vendor/sedna/kernel/common/bit_set.cpp +157 -0
- data/vendor/sedna/kernel/common/bit_set.h +55 -0
- data/vendor/sedna/kernel/common/commutil.h +67 -0
- data/vendor/sedna/kernel/common/config.h +62 -0
- data/vendor/sedna/kernel/common/counted_ptr.h +74 -0
- data/vendor/sedna/kernel/common/errdbg/ErrorCodes.java +1056 -0
- data/vendor/sedna/kernel/common/errdbg/Makefile +34 -0
- data/vendor/sedna/kernel/common/errdbg/assert.c +133 -0
- data/vendor/sedna/kernel/common/errdbg/d_printf.c +150 -0
- data/vendor/sedna/kernel/common/errdbg/d_printf.h +91 -0
- data/vendor/sedna/kernel/common/errdbg/error.codes +1743 -0
- data/vendor/sedna/kernel/common/errdbg/error_codes.c +531 -0
- data/vendor/sedna/kernel/common/errdbg/error_codes.h +549 -0
- data/vendor/sedna/kernel/common/errdbg/error_codes_scm.scm +527 -0
- data/vendor/sedna/kernel/common/errdbg/event_log.c +956 -0
- data/vendor/sedna/kernel/common/errdbg/event_log.h +226 -0
- data/vendor/sedna/kernel/common/errdbg/exceptions.cpp +155 -0
- data/vendor/sedna/kernel/common/errdbg/exceptions.h +559 -0
- data/vendor/sedna/kernel/common/errdbg/gen_error_codes +0 -0
- data/vendor/sedna/kernel/common/errdbg/gen_error_codes.c +345 -0
- data/vendor/sedna/kernel/common/gmm.cpp +192 -0
- data/vendor/sedna/kernel/common/gmm.h +29 -0
- data/vendor/sedna/kernel/common/ipc_ops.cpp +435 -0
- data/vendor/sedna/kernel/common/ipc_ops.h +51 -0
- data/vendor/sedna/kernel/common/lfsGlobals.h +12 -0
- data/vendor/sedna/kernel/common/lm_base.h +90 -0
- data/vendor/sedna/kernel/common/mmgr/Makefile +11 -0
- data/vendor/sedna/kernel/common/mmgr/aset.c +1185 -0
- data/vendor/sedna/kernel/common/mmgr/mcxt.c +741 -0
- data/vendor/sedna/kernel/common/mmgr/memnodes.h +70 -0
- data/vendor/sedna/kernel/common/mmgr/memutils.h +145 -0
- data/vendor/sedna/kernel/common/mmgr/se_alloc.h +321 -0
- data/vendor/sedna/kernel/common/mmgr/track.c +214 -0
- data/vendor/sedna/kernel/common/pping.cpp +672 -0
- data/vendor/sedna/kernel/common/pping.h +119 -0
- data/vendor/sedna/kernel/common/rcv_test.cpp +273 -0
- data/vendor/sedna/kernel/common/rcv_test.h +19 -0
- data/vendor/sedna/kernel/common/sedna.c +128 -0
- data/vendor/sedna/kernel/common/sedna.h +49 -0
- data/vendor/sedna/kernel/common/sedna_ef.h +52 -0
- data/vendor/sedna/kernel/common/sm_vmm_data.h +144 -0
- data/vendor/sedna/kernel/common/sp.c +93 -0
- data/vendor/sedna/kernel/common/sp.h +36 -0
- data/vendor/sedna/kernel/common/st/Makefile +20 -0
- data/vendor/sedna/kernel/common/st/os_linux/stacktrace.c +213 -0
- data/vendor/sedna/kernel/common/st/os_nt/stacktrace.c +338 -0
- data/vendor/sedna/kernel/common/st/os_other/stacktrace.c +39 -0
- data/vendor/sedna/kernel/common/st/stacktrace.h +72 -0
- data/vendor/sedna/kernel/common/st/stacktrfmt.c +64 -0
- data/vendor/sedna/kernel/common/tr_debug.cpp +112 -0
- data/vendor/sedna/kernel/common/tr_debug.h +22 -0
- data/vendor/sedna/kernel/common/u/Makefile +14 -0
- data/vendor/sedna/kernel/common/u/u.c +268 -0
- data/vendor/sedna/kernel/common/u/u.h +715 -0
- data/vendor/sedna/kernel/common/u/uatomic.h +12 -0
- data/vendor/sedna/kernel/common/u/udl.h +31 -0
- data/vendor/sedna/kernel/common/u/uevent.c +406 -0
- data/vendor/sedna/kernel/common/u/uevent.h +71 -0
- data/vendor/sedna/kernel/common/u/ugnames.cpp +330 -0
- data/vendor/sedna/kernel/common/u/ugnames.h +134 -0
- data/vendor/sedna/kernel/common/u/uhash_map.h +77 -0
- data/vendor/sedna/kernel/common/u/uhdd.c +1018 -0
- data/vendor/sedna/kernel/common/u/uhdd.h +206 -0
- data/vendor/sedna/kernel/common/u/ummap.cpp +268 -0
- data/vendor/sedna/kernel/common/u/ummap.h +60 -0
- data/vendor/sedna/kernel/common/u/umutex.c +145 -0
- data/vendor/sedna/kernel/common/u/umutex.h +65 -0
- data/vendor/sedna/kernel/common/u/upipe.cpp +244 -0
- data/vendor/sedna/kernel/common/u/upipe.h +74 -0
- data/vendor/sedna/kernel/common/u/uprocess.c +767 -0
- data/vendor/sedna/kernel/common/u/uprocess.h +91 -0
- data/vendor/sedna/kernel/common/u/usafesync.h +41 -0
- data/vendor/sedna/kernel/common/u/usecurity.c +150 -0
- data/vendor/sedna/kernel/common/u/usecurity.h +55 -0
- data/vendor/sedna/kernel/common/u/usem.c +891 -0
- data/vendor/sedna/kernel/common/u/usem.h +83 -0
- data/vendor/sedna/kernel/common/u/ushm.c +222 -0
- data/vendor/sedna/kernel/common/u/ushm.h +46 -0
- data/vendor/sedna/kernel/common/u/usocket.c +541 -0
- data/vendor/sedna/kernel/common/u/usocket.h +118 -0
- data/vendor/sedna/kernel/common/u/usystem.c +57 -0
- data/vendor/sedna/kernel/common/u/usystem.h +46 -0
- data/vendor/sedna/kernel/common/u/uthread.c +259 -0
- data/vendor/sedna/kernel/common/u/uthread.h +95 -0
- data/vendor/sedna/kernel/common/u/utime.c +65 -0
- data/vendor/sedna/kernel/common/u/utime.h +40 -0
- data/vendor/sedna/kernel/common/u/uutils.c +142 -0
- data/vendor/sedna/kernel/common/u/uutils.h +65 -0
- data/vendor/sedna/kernel/common/ugc.cpp +156 -0
- data/vendor/sedna/kernel/common/ugc.h +15 -0
- data/vendor/sedna/kernel/common/utils.cpp +156 -0
- data/vendor/sedna/kernel/common/utils.h +133 -0
- data/vendor/sedna/kernel/common/version.c +16 -0
- data/vendor/sedna/kernel/common/version.h +21 -0
- data/vendor/sedna/kernel/common/wustructures.h +18 -0
- data/vendor/sedna/kernel/common/wutypes.h +34 -0
- data/vendor/sedna/kernel/common/xptr.cpp +17 -0
- data/vendor/sedna/kernel/common/xptr.h +211 -0
- data/vendor/sedna/ver +1 -0
- metadata +142 -14
@@ -0,0 +1,214 @@
|
|
1
|
+
#include "common/sedna.h"
|
2
|
+
#include "common/errdbg/d_printf.h"
|
3
|
+
#include "stdio.h"
|
4
|
+
|
5
|
+
#ifdef SE_MEMORY_TRACK
|
6
|
+
|
7
|
+
#undef malloc
|
8
|
+
#undef free
|
9
|
+
#undef realloc
|
10
|
+
#undef calloc
|
11
|
+
#undef strdup
|
12
|
+
|
13
|
+
#endif /* SE_MEMORY_TRACK */
|
14
|
+
|
15
|
+
#define SE_MEMORY_TRACK_MAX_PATH 128
|
16
|
+
#define SE_MEMORY_TRACK_MAX_FLAG 128
|
17
|
+
|
18
|
+
/// Comment next string to get unfreed dump on screen.
|
19
|
+
#define SE_MEMORY_DUMP_TO_FILE
|
20
|
+
|
21
|
+
#define SE_MEMORY_TRACK_FILENAME_BU_BASE "MT-"
|
22
|
+
#define SE_MEMORY_TRACK_FILENAME_BU_SUFX ".xml"
|
23
|
+
|
24
|
+
char MT_SEDNA_DATA[U_MAX_PATH + 1];
|
25
|
+
|
26
|
+
|
27
|
+
struct ALLOC_INFO;
|
28
|
+
struct ALLOC_INFO_LIST;
|
29
|
+
|
30
|
+
typedef struct ALLOC_INFO {
|
31
|
+
void* address;
|
32
|
+
struct ALLOC_INFO* next;
|
33
|
+
usize_t size;
|
34
|
+
char file[SE_MEMORY_TRACK_MAX_PATH + 1];
|
35
|
+
char flag[SE_MEMORY_TRACK_MAX_FLAG + 1];
|
36
|
+
int line;
|
37
|
+
} ALLOC_INFO;
|
38
|
+
|
39
|
+
typedef struct ALLOC_INFO_LIST
|
40
|
+
{
|
41
|
+
ALLOC_INFO* top;
|
42
|
+
void (*insert) (struct ALLOC_INFO_LIST* list, ALLOC_INFO* info);
|
43
|
+
void (*remove) (struct ALLOC_INFO_LIST* list, void* ptr);
|
44
|
+
|
45
|
+
} ALLOC_INFO_LIST;
|
46
|
+
|
47
|
+
ALLOC_INFO_LIST *allocList;
|
48
|
+
|
49
|
+
void insert_alloc_list(ALLOC_INFO_LIST* list, ALLOC_INFO* info)
|
50
|
+
{
|
51
|
+
info->next = list->top;
|
52
|
+
list->top = info;
|
53
|
+
}
|
54
|
+
|
55
|
+
void remove_alloc_list(ALLOC_INFO_LIST* list, void* ptr)
|
56
|
+
{
|
57
|
+
ALLOC_INFO* itr = list->top;
|
58
|
+
ALLOC_INFO** ptr_to_next_ptr = &(list->top);
|
59
|
+
while(itr)
|
60
|
+
{
|
61
|
+
if(itr->address == ptr)
|
62
|
+
{
|
63
|
+
ALLOC_INFO* next_cur = itr->next;
|
64
|
+
free(itr);
|
65
|
+
*ptr_to_next_ptr = next_cur;
|
66
|
+
break;
|
67
|
+
}
|
68
|
+
else
|
69
|
+
{
|
70
|
+
ptr_to_next_ptr = &(itr->next);
|
71
|
+
itr = itr->next;
|
72
|
+
}
|
73
|
+
}
|
74
|
+
}
|
75
|
+
|
76
|
+
void init_alloc_list(ALLOC_INFO_LIST* list)
|
77
|
+
{
|
78
|
+
list->top = NULL;
|
79
|
+
list->insert = &insert_alloc_list;
|
80
|
+
list->remove = &remove_alloc_list;
|
81
|
+
}
|
82
|
+
|
83
|
+
void AddTrack(void* addr, usize_t asize, const char *fname, int lnum, const char* flag)
|
84
|
+
{
|
85
|
+
ALLOC_INFO *info;
|
86
|
+
|
87
|
+
if(!allocList)
|
88
|
+
{
|
89
|
+
allocList = (ALLOC_INFO_LIST*)malloc(sizeof(ALLOC_INFO_LIST));
|
90
|
+
init_alloc_list(allocList);
|
91
|
+
}
|
92
|
+
|
93
|
+
info = (ALLOC_INFO*)malloc(sizeof(ALLOC_INFO));
|
94
|
+
info->next = NULL;
|
95
|
+
info->address = addr;
|
96
|
+
strncpy(info->file, fname, SE_MEMORY_TRACK_MAX_PATH);
|
97
|
+
info->file[SE_MEMORY_TRACK_MAX_PATH] = '\0';
|
98
|
+
|
99
|
+
if(flag != NULL)
|
100
|
+
{
|
101
|
+
strncpy(info->flag, flag, SE_MEMORY_TRACK_MAX_FLAG);
|
102
|
+
info->flag[SE_MEMORY_TRACK_MAX_FLAG] = '\0';
|
103
|
+
}
|
104
|
+
else
|
105
|
+
{
|
106
|
+
info->flag[0] = '\0';
|
107
|
+
}
|
108
|
+
|
109
|
+
info->line = lnum;
|
110
|
+
info->size = asize;
|
111
|
+
allocList->insert(allocList, info);
|
112
|
+
}
|
113
|
+
|
114
|
+
void RemoveTrack(void* addr)
|
115
|
+
{
|
116
|
+
if(!allocList) return;
|
117
|
+
allocList->remove(allocList, addr);
|
118
|
+
}
|
119
|
+
|
120
|
+
static const char* __get_component_string_name(int component)
|
121
|
+
{
|
122
|
+
switch(component)
|
123
|
+
{
|
124
|
+
case EL_CDB: return "CDB";
|
125
|
+
case EL_DDB: return "DDB";
|
126
|
+
case EL_GOV: return "GOV";
|
127
|
+
case EL_RC: return "RC";
|
128
|
+
case EL_SM: return "SM";
|
129
|
+
case EL_SMSD: return "SMSD";
|
130
|
+
case EL_STOP: return "STOP";
|
131
|
+
case EL_TRN: return "TRN";
|
132
|
+
default: return "UNK";
|
133
|
+
}
|
134
|
+
}
|
135
|
+
|
136
|
+
|
137
|
+
void DumpUnfreed(int component)
|
138
|
+
{
|
139
|
+
int totalSize = 0;
|
140
|
+
ALLOC_INFO* itr = NULL;
|
141
|
+
#ifdef SE_MEMORY_DUMP_TO_FILE
|
142
|
+
FILE *du_ostr = NULL;
|
143
|
+
char dt_buf[32];
|
144
|
+
char buf[U_MAX_PATH + 1 + 128 + 32];
|
145
|
+
struct tm *newtime;
|
146
|
+
time_t aclock;
|
147
|
+
#endif
|
148
|
+
|
149
|
+
if(!allocList) return;
|
150
|
+
itr = allocList->top;
|
151
|
+
|
152
|
+
#ifdef SE_MEMORY_DUMP_TO_FILE
|
153
|
+
time(&aclock); /* Get time in seconds */
|
154
|
+
newtime = localtime(&aclock); /* Convert time to struct tm form */
|
155
|
+
|
156
|
+
sprintf(dt_buf,"%04d-%02d-%02d-%02d-%02d-%02d",
|
157
|
+
newtime->tm_year + 1900, newtime->tm_mon + 1, newtime->tm_mday,
|
158
|
+
newtime->tm_hour, newtime->tm_min, newtime->tm_sec);
|
159
|
+
|
160
|
+
strcpy(buf, MT_SEDNA_DATA);
|
161
|
+
#ifdef _WIN32
|
162
|
+
strcat(buf, "\\data\\");
|
163
|
+
#else
|
164
|
+
strcat(buf, "/data/");
|
165
|
+
#endif
|
166
|
+
strcat(buf, SE_MEMORY_TRACK_FILENAME_BU_BASE);
|
167
|
+
strcat(buf, __get_component_string_name(component));
|
168
|
+
strcat(buf, "-");
|
169
|
+
strcat(buf, dt_buf);
|
170
|
+
strcat(buf, SE_MEMORY_TRACK_FILENAME_BU_SUFX);
|
171
|
+
|
172
|
+
du_ostr = fopen(buf, "w");
|
173
|
+
|
174
|
+
if (!du_ostr)
|
175
|
+
{
|
176
|
+
d_printf1("Memory Tracking Error: Could not create file to dump unfreed!\n");
|
177
|
+
return;
|
178
|
+
}
|
179
|
+
|
180
|
+
fprintf(du_ostr, "<?xml version=\"1.0\" standalone=\"yes\"?>\n");
|
181
|
+
fprintf(du_ostr, "<unfreed>\n");
|
182
|
+
fprintf(du_ostr, "\t<component>%s</component>\n", __get_component_string_name(component));
|
183
|
+
#endif
|
184
|
+
|
185
|
+
while(itr) {
|
186
|
+
|
187
|
+
#ifndef SE_MEMORY_DUMP_TO_FILE
|
188
|
+
d_printf4("%-50s:\t\tLINE %d,\t\tADDRESS %d\t%d unfreed (FLAG: %s)\n", itr->file, itr->line, itr->address, itr->size, itr->flag);
|
189
|
+
#else
|
190
|
+
fprintf(du_ostr, "\t<block>\n");
|
191
|
+
fprintf(du_ostr, "\t\t<file>%s</file>\n", itr->file);
|
192
|
+
fprintf(du_ostr, "\t\t<line>%d</line>\n", itr->line);
|
193
|
+
fprintf(du_ostr, "\t\t<address>%"PRIxPTR"</address>\n", itr->address);
|
194
|
+
fprintf(du_ostr, "\t\t<size>%d</size>\n", itr->size);
|
195
|
+
fprintf(du_ostr, "\t\t<flag>%s</flag>\n", itr->flag);
|
196
|
+
fprintf(du_ostr, "\t</block>\n");
|
197
|
+
#endif
|
198
|
+
|
199
|
+
totalSize += itr->size;
|
200
|
+
itr = itr->next;
|
201
|
+
}
|
202
|
+
|
203
|
+
#ifndef SE_MEMORY_DUMP_TO_FILE
|
204
|
+
d_printf1("-----------------------------------------------------------\n");
|
205
|
+
d_printf2("Total Unfreed: %d bytes\n", totalSize);
|
206
|
+
#else
|
207
|
+
fprintf(du_ostr, "\t<total>%d</total>\n</unfreed>", totalSize);
|
208
|
+
|
209
|
+
fflush(du_ostr);
|
210
|
+
fclose(du_ostr);
|
211
|
+
du_ostr = NULL;
|
212
|
+
#endif
|
213
|
+
|
214
|
+
}
|
@@ -0,0 +1,672 @@
|
|
1
|
+
/*
|
2
|
+
* File: pping.cpp
|
3
|
+
* Copyright (C) 2004 The Institute for System Programming of the Russian Academy of Sciences (ISP RAS)
|
4
|
+
*/
|
5
|
+
|
6
|
+
#include "common/sedna.h"
|
7
|
+
|
8
|
+
#include "common/pping.h"
|
9
|
+
#include "common/errdbg/d_printf.h"
|
10
|
+
#include "common/ipc_ops.h"
|
11
|
+
|
12
|
+
#if (defined(EL_DEBUG) && (EL_DEBUG == 1))
|
13
|
+
#include "common/st/stacktrace.h"
|
14
|
+
#include "common/u/uhdd.h"
|
15
|
+
#ifdef _WIN32
|
16
|
+
#include <dbghelp.h>
|
17
|
+
#include <shellapi.h>
|
18
|
+
#include <shlobj.h>
|
19
|
+
#else
|
20
|
+
#include <string.h>
|
21
|
+
#endif /* _WIN32 */
|
22
|
+
#endif
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
#ifdef _WIN32
|
27
|
+
#define PPING_STACK_SIZE 102400
|
28
|
+
#else
|
29
|
+
#define PPING_STACK_SIZE 102400
|
30
|
+
#endif
|
31
|
+
|
32
|
+
#define PPING_KEEP_ALIVE_MSG 'a'
|
33
|
+
#define PPING_DISCONNECT_MSG 'b'
|
34
|
+
#define PPING_PROC_EXCEPTION_MSG 'e'
|
35
|
+
|
36
|
+
#define PPING_LSTNR_QUEUE_LEN 100
|
37
|
+
|
38
|
+
|
39
|
+
#define SYS_FAILURE_SERVER( message ) { sedna_soft_fault(message, pps->component); \
|
40
|
+
return 0; }
|
41
|
+
|
42
|
+
#define SYS_FAILURE_CLIENT( message ) { sedna_soft_fault(message, ppc->component); \
|
43
|
+
return 0; }
|
44
|
+
|
45
|
+
|
46
|
+
////////////////////////////////////////////////////////////////////////////////
|
47
|
+
/// pping_client
|
48
|
+
////////////////////////////////////////////////////////////////////////////////
|
49
|
+
|
50
|
+
U_THREAD_PROC(pping_client_thread_proc, arg)
|
51
|
+
{
|
52
|
+
if (uThreadBlockAllSignals(NULL) != 0)
|
53
|
+
d_printf1("Failed to block signals for pping_client_thread_proc");
|
54
|
+
|
55
|
+
pping_client *ppc = (pping_client*)arg;
|
56
|
+
char c = PPING_KEEP_ALIVE_MSG;
|
57
|
+
|
58
|
+
while (true)
|
59
|
+
{
|
60
|
+
if (ppc->stop_keep_alive) return 0;
|
61
|
+
|
62
|
+
int res = usend(ppc->sock, &c, sizeof(c), NULL);
|
63
|
+
|
64
|
+
if (res != sizeof(c) && !ppc->stop_keep_alive) {
|
65
|
+
sedna_soft_fault("SEDNA GOVERNOR is down", ppc->component);
|
66
|
+
}
|
67
|
+
|
68
|
+
/* se_stop -hard has been called? */
|
69
|
+
if(ppc->signaled_flag != NULL &&
|
70
|
+
GOV_HEADER_GLOBAL_PTR != NULL &&
|
71
|
+
GOV_HEADER_GLOBAL_PTR -> is_server_stop == SE_STOP_HARD)
|
72
|
+
{
|
73
|
+
*(ppc->signaled_flag) = true;
|
74
|
+
}
|
75
|
+
|
76
|
+
UUnnamedSemaphoreDownTimeout(&(ppc->sem), 1000, NULL);
|
77
|
+
|
78
|
+
if(ppc->timeout)
|
79
|
+
{
|
80
|
+
|
81
|
+
if (!ppc->counter && !ppc->reset_flag) {*(ppc->signaled_flag) = true; ppc->counter = ppc->timeout;}
|
82
|
+
|
83
|
+
if(ppc->reset_flag)
|
84
|
+
{
|
85
|
+
ppc->counter = ppc->timeout;
|
86
|
+
if(ppc->signaled_flag) *(ppc->signaled_flag) = false;
|
87
|
+
ppc->reset_flag = false;
|
88
|
+
}
|
89
|
+
|
90
|
+
(ppc->counter)--;
|
91
|
+
}
|
92
|
+
#if (defined(EL_DEBUG) && (EL_DEBUG == 1))
|
93
|
+
#define SENDVAR(v) if (usend(ppc->sock, (char*)&v, sizeof(v), NULL) != sizeof(v)) continue;
|
94
|
+
#ifdef _WIN32
|
95
|
+
if (ppc->exceptPtrs)
|
96
|
+
{
|
97
|
+
//TODO: do something if usend/urecv fails or get wrong msg
|
98
|
+
char cc = PPING_PROC_EXCEPTION_MSG;
|
99
|
+
DWORD proc_id = GetCurrentProcessId();
|
100
|
+
|
101
|
+
if (usend(ppc->sock, &cc, sizeof(cc), NULL) != sizeof(cc))
|
102
|
+
{ ppc->exceptPtrs = NULL; continue; }
|
103
|
+
|
104
|
+
SENDVAR(proc_id)
|
105
|
+
SENDVAR(ppc->component);
|
106
|
+
SENDVAR(ppc->except_thread_id);
|
107
|
+
SENDVAR(ppc->exceptPtrs);
|
108
|
+
|
109
|
+
if (urecv(ppc->sock, &cc, sizeof(cc), NULL) != sizeof(cc))
|
110
|
+
{ ppc->exceptPtrs = NULL; continue; }
|
111
|
+
if (cc != PPING_PROC_EXCEPTION_MSG)
|
112
|
+
{ ppc->exceptPtrs = NULL; continue; }
|
113
|
+
|
114
|
+
if (ppc->stacktrace_fh != U_INVALID_FD)
|
115
|
+
{
|
116
|
+
if (StackTraceInit() != 0)
|
117
|
+
{
|
118
|
+
StackTraceWriteFd(ppc->exceptPtrs->ContextRecord, (intptr_t)ppc->stacktrace_fh, 9999, 0);
|
119
|
+
|
120
|
+
StackTraceDeinit();
|
121
|
+
}
|
122
|
+
uCloseFile(ppc->stacktrace_fh, NULL);
|
123
|
+
}
|
124
|
+
|
125
|
+
|
126
|
+
ppc->exceptPtrs = NULL;
|
127
|
+
}
|
128
|
+
#endif
|
129
|
+
#undef SENDVAR
|
130
|
+
#endif
|
131
|
+
}
|
132
|
+
return 0;
|
133
|
+
}
|
134
|
+
|
135
|
+
pping_client::pping_client(int _port_, int _component_, const char* _host_)
|
136
|
+
{
|
137
|
+
#ifdef PPING_ON
|
138
|
+
port = _port_;
|
139
|
+
if (_host_ && strlen(_host_) < PPING_MAX_HOSTLEN)
|
140
|
+
strcpy(host, _host_);
|
141
|
+
else
|
142
|
+
strcpy(host, "127.0.0.1");
|
143
|
+
component = _component_;
|
144
|
+
|
145
|
+
stop_keep_alive = false;
|
146
|
+
initialized = false;
|
147
|
+
|
148
|
+
counter = 0;
|
149
|
+
timeout = 0;
|
150
|
+
reset_flag = false;
|
151
|
+
signaled_flag = NULL;
|
152
|
+
|
153
|
+
#if (defined(EL_DEBUG) && (EL_DEBUG == 1))
|
154
|
+
#ifdef _WIN32
|
155
|
+
exceptPtrs = NULL;
|
156
|
+
stacktrace_fh = U_INVALID_FD;
|
157
|
+
#endif
|
158
|
+
#endif
|
159
|
+
#endif
|
160
|
+
}
|
161
|
+
|
162
|
+
pping_client::pping_client(int _port_, int _component_, volatile bool* _signaled_flag_, const char* _host_)
|
163
|
+
{
|
164
|
+
#ifdef PPING_ON
|
165
|
+
port = _port_;
|
166
|
+
if (_host_ && strlen(_host_) < PPING_MAX_HOSTLEN)
|
167
|
+
strcpy(host, _host_);
|
168
|
+
else
|
169
|
+
strcpy(host, "127.0.0.1");
|
170
|
+
component = _component_;
|
171
|
+
|
172
|
+
stop_keep_alive = false;
|
173
|
+
initialized = false;
|
174
|
+
|
175
|
+
counter = 0;
|
176
|
+
timeout = 0;
|
177
|
+
reset_flag = false;
|
178
|
+
signaled_flag = _signaled_flag_;
|
179
|
+
|
180
|
+
#if (defined(EL_DEBUG) && (EL_DEBUG == 1))
|
181
|
+
#ifdef _WIN32
|
182
|
+
exceptPtrs = NULL;
|
183
|
+
stacktrace_fh = U_INVALID_FD;
|
184
|
+
#endif
|
185
|
+
#endif
|
186
|
+
#endif
|
187
|
+
}
|
188
|
+
|
189
|
+
pping_client::~pping_client()
|
190
|
+
{
|
191
|
+
#ifdef PPING_ON
|
192
|
+
#endif
|
193
|
+
}
|
194
|
+
|
195
|
+
void pping_client::startup(SednaUserException& e)
|
196
|
+
{
|
197
|
+
startup(e, false);
|
198
|
+
}
|
199
|
+
|
200
|
+
void pping_client::startup(SednaUserSoftException& e)
|
201
|
+
{
|
202
|
+
startup(e, true);
|
203
|
+
}
|
204
|
+
|
205
|
+
void pping_client::throw_exception(SednaUserException& e, bool is_soft)
|
206
|
+
{
|
207
|
+
if (is_soft) throw dynamic_cast<SednaUserSoftException&>(e);
|
208
|
+
else throw e;
|
209
|
+
}
|
210
|
+
|
211
|
+
void pping_client::startup(SednaUserException& e, bool is_soft)
|
212
|
+
{
|
213
|
+
#ifdef PPING_ON
|
214
|
+
sock = usocket(AF_INET, SOCK_STREAM, 0, __sys_call_error);
|
215
|
+
|
216
|
+
if (sock == U_INVALID_SOCKET) throw USER_ENV_EXCEPTION("Failed to create socket", false);
|
217
|
+
if (uconnect_tcp(sock, port, host, __sys_call_error) == U_SOCKET_ERROR)
|
218
|
+
{
|
219
|
+
if (uclose_socket(sock, NULL) == U_SOCKET_ERROR)
|
220
|
+
throw USER_ENV_EXCEPTION("Failed to close socket", false);
|
221
|
+
throw_exception(e, is_soft);
|
222
|
+
}
|
223
|
+
|
224
|
+
if (UUnnamedSemaphoreCreate(&sem, 0, NULL, __sys_call_error) != 0)
|
225
|
+
throw USER_ENV_EXCEPTION("Failed to create semaphore", false);
|
226
|
+
|
227
|
+
|
228
|
+
uResVal res = uCreateThread(pping_client_thread_proc, this, &client_thread_handle, PPING_STACK_SIZE, NULL, __sys_call_error);
|
229
|
+
if (res != 0) throw USER_ENV_EXCEPTION("Failed to create pping client thread", false);
|
230
|
+
|
231
|
+
initialized = true;
|
232
|
+
#endif
|
233
|
+
}
|
234
|
+
|
235
|
+
void pping_client::shutdown()
|
236
|
+
{
|
237
|
+
#ifdef PPING_ON
|
238
|
+
if (!initialized) return;
|
239
|
+
|
240
|
+
stop_keep_alive = true;
|
241
|
+
if (UUnnamedSemaphoreUp(&sem, NULL) != 0)
|
242
|
+
throw USER_ENV_EXCEPTION("Failed to up semaphore", false);
|
243
|
+
|
244
|
+
if (uThreadJoin(client_thread_handle, NULL) != 0)
|
245
|
+
throw USER_ENV_EXCEPTION("Error waiting for pping client thread to shutdown", false);
|
246
|
+
|
247
|
+
if (uCloseThreadHandle(client_thread_handle, NULL) != 0)
|
248
|
+
throw USER_EXCEPTION2(SE4063, "pping client_thread");
|
249
|
+
|
250
|
+
char c = PPING_DISCONNECT_MSG;
|
251
|
+
if (usend(sock, &c, sizeof(char), NULL) != sizeof(char))
|
252
|
+
throw SYSTEM_EXCEPTION("pping server is down");
|
253
|
+
if (uclose_socket(sock, NULL) == U_SOCKET_ERROR)
|
254
|
+
throw USER_ENV_EXCEPTION("Failed to close socket", false);
|
255
|
+
|
256
|
+
if (UUnnamedSemaphoreRelease(&sem, NULL) != 0)
|
257
|
+
throw USER_ENV_EXCEPTION("Failed to release semaphore", false);
|
258
|
+
|
259
|
+
initialized = false;
|
260
|
+
#endif
|
261
|
+
}
|
262
|
+
|
263
|
+
void pping_client::start_timer(int _timeout_)
|
264
|
+
{
|
265
|
+
#ifdef PPING_ON
|
266
|
+
|
267
|
+
timeout = _timeout_;
|
268
|
+
reset_flag = true;
|
269
|
+
if(signaled_flag) *signaled_flag = false;
|
270
|
+
|
271
|
+
#endif
|
272
|
+
}
|
273
|
+
|
274
|
+
void pping_client::stop_timer()
|
275
|
+
{
|
276
|
+
start_timer(0);
|
277
|
+
}
|
278
|
+
|
279
|
+
|
280
|
+
#if (defined(EL_DEBUG) && (EL_DEBUG == 1))
|
281
|
+
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
282
|
+
/// Exception logging.
|
283
|
+
#ifdef _WIN32
|
284
|
+
void pping_client::WriteStackTraceFile(LPEXCEPTION_POINTERS exceptPtrs)
|
285
|
+
{
|
286
|
+
if (exceptPtrs != NULL)
|
287
|
+
{
|
288
|
+
int wait = 60;
|
289
|
+
this->except_thread_id = GetCurrentThreadId();
|
290
|
+
this->stacktrace_fh = sedna_soft_fault_log_fh(this->component, "-st");
|
291
|
+
this->exceptPtrs = exceptPtrs;
|
292
|
+
while (this->exceptPtrs != NULL && wait > 0)
|
293
|
+
{
|
294
|
+
if (UUnnamedSemaphoreUp(&sem, NULL) != 0)
|
295
|
+
return;
|
296
|
+
uSleep(1, NULL);
|
297
|
+
wait--;
|
298
|
+
}
|
299
|
+
}
|
300
|
+
}
|
301
|
+
#endif
|
302
|
+
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
303
|
+
#endif
|
304
|
+
|
305
|
+
|
306
|
+
////////////////////////////////////////////////////////////////////////////////
|
307
|
+
/// pping_server
|
308
|
+
////////////////////////////////////////////////////////////////////////////////
|
309
|
+
|
310
|
+
struct pping_serv_arg
|
311
|
+
{
|
312
|
+
pping_server *pps;
|
313
|
+
USOCKET sock;
|
314
|
+
int id; // thread_table id
|
315
|
+
};
|
316
|
+
|
317
|
+
inline int
|
318
|
+
client_exception_handler(USOCKET sock,
|
319
|
+
const pping_server *pps)
|
320
|
+
{
|
321
|
+
#if (defined(EL_DEBUG) && (EL_DEBUG == 1))
|
322
|
+
#ifdef _WIN32
|
323
|
+
char cc = PPING_PROC_EXCEPTION_MSG;
|
324
|
+
HANDLE proc_h;
|
325
|
+
DWORD proc_id;
|
326
|
+
DWORD except_thread_id;
|
327
|
+
PEXCEPTION_POINTERS client_exceptPtrs;
|
328
|
+
MINIDUMP_EXCEPTION_INFORMATION ExpParam;
|
329
|
+
int component;
|
330
|
+
UFile fh;
|
331
|
+
|
332
|
+
#define GETVAR(v) if (urecv(sock, (char*)&v, sizeof(v), NULL) != sizeof(v)) \
|
333
|
+
SYS_FAILURE_SERVER("Failure in pping server (cannot receive exception parameter from the client).");
|
334
|
+
GETVAR(proc_id)
|
335
|
+
GETVAR(component);
|
336
|
+
GETVAR(except_thread_id);
|
337
|
+
GETVAR(client_exceptPtrs);
|
338
|
+
#undef GETVAR
|
339
|
+
|
340
|
+
proc_h = OpenProcess(PROCESS_ALL_ACCESS, FALSE, proc_id);
|
341
|
+
if (proc_h == NULL)
|
342
|
+
d_printf2("Failed to open process handle, GetLastError=%u\n", GetLastError());
|
343
|
+
|
344
|
+
ExpParam.ThreadId = except_thread_id;
|
345
|
+
ExpParam.ExceptionPointers = client_exceptPtrs;
|
346
|
+
ExpParam.ClientPointers = TRUE;
|
347
|
+
|
348
|
+
fh = sedna_soft_fault_log_fh(component, "-dump");
|
349
|
+
|
350
|
+
if (!MiniDumpWriteDump(proc_h, proc_id, fh, MiniDumpWithDataSegs, &ExpParam, NULL, NULL))
|
351
|
+
d_printf2("Failed to save minidump, GetLastError=%u\n", GetLastError());
|
352
|
+
|
353
|
+
uCloseFile(fh, NULL);
|
354
|
+
|
355
|
+
if (usend(sock, &cc, sizeof(cc), NULL) != sizeof(cc))
|
356
|
+
SYS_FAILURE_SERVER("Failure in pping server (cannot send exception ack to the client).");
|
357
|
+
|
358
|
+
#endif /* _WIN32 */
|
359
|
+
#endif /* EL_DEBUG */
|
360
|
+
|
361
|
+
return 1;
|
362
|
+
}
|
363
|
+
|
364
|
+
|
365
|
+
U_THREAD_PROC(pping_server_cli_thread_proc, arg)
|
366
|
+
{
|
367
|
+
if (uThreadBlockAllSignals(NULL) != 0)
|
368
|
+
d_printf1("Failed to block signals for SSMMsg_server_proc");
|
369
|
+
|
370
|
+
pping_server *pps = ((pping_serv_arg*)arg)->pps;
|
371
|
+
USOCKET sock = ((pping_serv_arg*)arg)->sock;
|
372
|
+
int id = ((pping_serv_arg*)arg)->id;
|
373
|
+
int component = ((pping_serv_arg*)arg)->pps->component;
|
374
|
+
delete ((pping_serv_arg*)arg);
|
375
|
+
|
376
|
+
char c = PPING_DISCONNECT_MSG;
|
377
|
+
while (true)
|
378
|
+
{
|
379
|
+
if (urecv(sock, &c, sizeof(c), NULL) != sizeof(c)) goto sys_failure;
|
380
|
+
if (c == PPING_DISCONNECT_MSG) break;
|
381
|
+
#if (defined(EL_DEBUG) && (EL_DEBUG == 1))
|
382
|
+
if (c == PPING_PROC_EXCEPTION_MSG)
|
383
|
+
{
|
384
|
+
if (client_exception_handler(sock, pps) != 1) return 0;
|
385
|
+
continue;
|
386
|
+
}
|
387
|
+
#endif
|
388
|
+
if (c != PPING_KEEP_ALIVE_MSG) goto sys_failure;
|
389
|
+
}
|
390
|
+
|
391
|
+
//d_printf1("pping_server's client is closed\n");
|
392
|
+
if (uclose_socket(sock, NULL) == U_SOCKET_ERROR) goto sys_failure;
|
393
|
+
|
394
|
+
pps->thread_table[id].is_running = false;
|
395
|
+
return 0;
|
396
|
+
|
397
|
+
sys_failure:
|
398
|
+
sedna_soft_fault("One of SEDNA processes is down", component);
|
399
|
+
|
400
|
+
return 0;
|
401
|
+
}
|
402
|
+
|
403
|
+
/* Multi threaded pping server version.
|
404
|
+
* It's obsolete now. Use pping_server_lstn_thread_proc_st
|
405
|
+
* instead.
|
406
|
+
*/
|
407
|
+
U_THREAD_PROC(pping_server_lstn_thread_proc_mt, arg)
|
408
|
+
{
|
409
|
+
if (uThreadBlockAllSignals(NULL) != 0)
|
410
|
+
d_printf1("Failed to block signals for SSMMsg_server_proc");
|
411
|
+
|
412
|
+
pping_server *pps = (pping_server*)arg;
|
413
|
+
int i = 0;
|
414
|
+
|
415
|
+
while (true)
|
416
|
+
{
|
417
|
+
pping_serv_arg *pps_arg = se_new pping_serv_arg;
|
418
|
+
|
419
|
+
//accept a call from a client
|
420
|
+
pps_arg->pps = pps;
|
421
|
+
pps_arg->id = -1;
|
422
|
+
pps_arg->sock = uaccept(pps->sock, NULL);
|
423
|
+
|
424
|
+
if (pps_arg->sock == U_INVALID_SOCKET || pps->close_lstn_thread)
|
425
|
+
{
|
426
|
+
if (pps->close_lstn_thread)
|
427
|
+
{
|
428
|
+
for (i = 0; i < PPING_SERVER_THREAD_TABLE_SIZE; ++i)
|
429
|
+
{
|
430
|
+
if (!(pps->thread_table[i].is_empty))
|
431
|
+
{
|
432
|
+
if (uThreadJoin(pps->thread_table[i].handle, NULL) != 0)
|
433
|
+
goto sys_failure;
|
434
|
+
if (uCloseThreadHandle(pps->thread_table[i].handle, NULL) != 0)
|
435
|
+
goto sys_failure;
|
436
|
+
|
437
|
+
pps->thread_table[i].handle = (UTHANDLE)0;
|
438
|
+
pps->thread_table[i].is_running = true;
|
439
|
+
pps->thread_table[i].is_empty = true;
|
440
|
+
}
|
441
|
+
}
|
442
|
+
|
443
|
+
return 0;
|
444
|
+
}
|
445
|
+
else
|
446
|
+
goto sys_failure;
|
447
|
+
}
|
448
|
+
|
449
|
+
if (uNotInheritDescriptor(UHANDLE(pps_arg->sock), __sys_call_error) != 0) throw USER_EXCEPTION(SE4080);
|
450
|
+
|
451
|
+
for (i = 0; i < PPING_SERVER_THREAD_TABLE_SIZE; ++i)
|
452
|
+
{
|
453
|
+
if (!(pps->thread_table[i].is_empty) &&
|
454
|
+
!(pps->thread_table[i].is_running))
|
455
|
+
{
|
456
|
+
if (uThreadJoin(pps->thread_table[i].handle, NULL) != 0)
|
457
|
+
goto sys_failure;
|
458
|
+
if (uCloseThreadHandle(pps->thread_table[i].handle, NULL) != 0)
|
459
|
+
goto sys_failure;
|
460
|
+
|
461
|
+
pps->thread_table[i].handle = (UTHANDLE)0;
|
462
|
+
pps->thread_table[i].is_running = true;
|
463
|
+
pps->thread_table[i].is_empty = true;
|
464
|
+
}
|
465
|
+
|
466
|
+
if (pps_arg->id == -1 && pps->thread_table[i].is_empty)
|
467
|
+
pps_arg->id = i;
|
468
|
+
}
|
469
|
+
|
470
|
+
pps->thread_table[pps_arg->id].is_running = true;
|
471
|
+
pps->thread_table[pps_arg->id].is_empty = false;
|
472
|
+
uResVal res = uCreateThread(pping_server_cli_thread_proc,
|
473
|
+
pps_arg,
|
474
|
+
&(pps->thread_table[pps_arg->id].handle),
|
475
|
+
PPING_STACK_SIZE,
|
476
|
+
NULL,
|
477
|
+
NULL);
|
478
|
+
if (res != 0)
|
479
|
+
{
|
480
|
+
goto sys_failure;
|
481
|
+
}
|
482
|
+
}
|
483
|
+
return 0;
|
484
|
+
|
485
|
+
sys_failure:
|
486
|
+
sedna_soft_fault("Malfunction in SEDNA GOVERNOR", pps->component);
|
487
|
+
|
488
|
+
return 0;
|
489
|
+
}
|
490
|
+
|
491
|
+
|
492
|
+
/* Single threaded version of pping server.
|
493
|
+
* Uses select() to create connections and serve
|
494
|
+
* previously created as well.
|
495
|
+
*
|
496
|
+
* TODO: read all buffer at once
|
497
|
+
* TODO: better failures diagnostric
|
498
|
+
* TODO: place accept+uNotInherit into a critical section to prevent
|
499
|
+
* descriptors inheritance on fork
|
500
|
+
*
|
501
|
+
*/
|
502
|
+
U_THREAD_PROC(pping_server_lstn_thread_proc_st, arg)
|
503
|
+
{
|
504
|
+
if (uThreadBlockAllSignals(NULL) != 0)
|
505
|
+
d_printf1("Failed to block signals for pping server thread.");
|
506
|
+
|
507
|
+
U_SSET allset, rset;
|
508
|
+
pping_server *pps = (pping_server*)arg;
|
509
|
+
int i, maxfd, client_sock, res;
|
510
|
+
char c = PPING_DISCONNECT_MSG;
|
511
|
+
bool maxfd_valid = true;
|
512
|
+
|
513
|
+
U_SSET_ZERO(&allset);
|
514
|
+
U_SSET_SET(pps->sock, &allset);
|
515
|
+
maxfd = pps->sock + 1;
|
516
|
+
|
517
|
+
while (true)
|
518
|
+
{
|
519
|
+
rset = allset;
|
520
|
+
res = uselect_read_arr(&rset, maxfd, NULL, NULL);
|
521
|
+
if (res == U_SOCKET_ERROR) {
|
522
|
+
SYS_FAILURE_SERVER("Failure in pping server (select() call failed).");
|
523
|
+
}
|
524
|
+
|
525
|
+
/* Iterate through ready to read client descriptors */
|
526
|
+
for (i = 0; i < maxfd; i++)
|
527
|
+
{
|
528
|
+
if(U_SSET_ISSET(i, &rset) && i != pps->sock)
|
529
|
+
{
|
530
|
+
res = urecv(i, &c, sizeof(c), NULL);
|
531
|
+
if( res != sizeof(c) ) {
|
532
|
+
SYS_FAILURE_SERVER("Failure in pping server (recv() call failed, one of the clients may be down).");
|
533
|
+
}
|
534
|
+
if (c == PPING_DISCONNECT_MSG)
|
535
|
+
{
|
536
|
+
U_SSET_CLR(i, &allset);
|
537
|
+
if(uclose_socket(i, NULL) == U_SOCKET_ERROR)
|
538
|
+
SYS_FAILURE_SERVER("Failure in pping server (cannot close a socket descriptor on disconnect).");
|
539
|
+
if ( maxfd-1 == i )
|
540
|
+
maxfd_valid = false;
|
541
|
+
}
|
542
|
+
#if (defined(EL_DEBUG) && (EL_DEBUG == 1))
|
543
|
+
else if (c == PPING_PROC_EXCEPTION_MSG) {
|
544
|
+
if (client_exception_handler(i, pps) != 1) return 0;
|
545
|
+
}
|
546
|
+
#endif
|
547
|
+
else if (c != PPING_KEEP_ALIVE_MSG)
|
548
|
+
SYS_FAILURE_SERVER("Failure in pping server (unexpected message from client).");
|
549
|
+
}
|
550
|
+
}
|
551
|
+
|
552
|
+
/* Renew maximum descriptor number */
|
553
|
+
if( !maxfd_valid )
|
554
|
+
{
|
555
|
+
for (i = maxfd-1; i >= 0; i--)
|
556
|
+
{
|
557
|
+
if(U_SSET_ISSET(i, &allset))
|
558
|
+
{
|
559
|
+
maxfd = i + 1;
|
560
|
+
maxfd_valid = true;
|
561
|
+
break;
|
562
|
+
}
|
563
|
+
}
|
564
|
+
}
|
565
|
+
|
566
|
+
/* Create a new connection */
|
567
|
+
if (U_SSET_ISSET(pps->sock, &rset))
|
568
|
+
{
|
569
|
+
client_sock = uaccept(pps->sock, NULL);
|
570
|
+
|
571
|
+
if(client_sock == U_INVALID_SOCKET)
|
572
|
+
SYS_FAILURE_SERVER("Failure in pping server (accept() call failed).");
|
573
|
+
|
574
|
+
U_SSET_SET(client_sock, &allset);
|
575
|
+
if (client_sock > maxfd-1) {
|
576
|
+
maxfd = client_sock + 1;
|
577
|
+
}
|
578
|
+
|
579
|
+
/* Check if governor wants to shutdown us */
|
580
|
+
if (pps->close_lstn_thread)
|
581
|
+
{
|
582
|
+
for (i = 0; i < maxfd; i++)
|
583
|
+
{
|
584
|
+
if(U_SSET_ISSET(i, &allset) &&
|
585
|
+
i != pps->sock &&
|
586
|
+
uclose_socket(i, NULL) == U_SOCKET_ERROR)
|
587
|
+
SYS_FAILURE_SERVER("Failure in pping server (cannot close a socket descriptor).");
|
588
|
+
}
|
589
|
+
break;
|
590
|
+
}
|
591
|
+
|
592
|
+
/* Make the client descriptor unheritable */
|
593
|
+
if (uNotInheritDescriptor(UHANDLE(client_sock), NULL) != 0)
|
594
|
+
SYS_FAILURE_SERVER("Failure in pping server (cannot make a socket descriptor unheritable).");
|
595
|
+
}
|
596
|
+
}
|
597
|
+
return 0;
|
598
|
+
}
|
599
|
+
|
600
|
+
|
601
|
+
pping_server::pping_server(int _port_, int _component_)
|
602
|
+
{
|
603
|
+
#ifdef PPING_ON
|
604
|
+
port = _port_;
|
605
|
+
component = _component_;
|
606
|
+
close_lstn_thread = false;
|
607
|
+
initialized = false;
|
608
|
+
|
609
|
+
for (int i = 0; i < PPING_SERVER_THREAD_TABLE_SIZE; ++i)
|
610
|
+
{
|
611
|
+
thread_table[i].handle = (UTHANDLE)0;
|
612
|
+
thread_table[i].is_running = true;
|
613
|
+
thread_table[i].is_empty = true;
|
614
|
+
}
|
615
|
+
#endif
|
616
|
+
}
|
617
|
+
|
618
|
+
pping_server::~pping_server()
|
619
|
+
{
|
620
|
+
#ifdef PPING_ON
|
621
|
+
#endif
|
622
|
+
}
|
623
|
+
|
624
|
+
void pping_server::startup()
|
625
|
+
{
|
626
|
+
#ifdef PPING_ON
|
627
|
+
sock = usocket(AF_INET, SOCK_STREAM, 0, __sys_call_error);
|
628
|
+
if (sock == U_INVALID_SOCKET) throw USER_ENV_EXCEPTION("Failed to create socket", false);
|
629
|
+
|
630
|
+
if (uNotInheritDescriptor(UHANDLE(sock), __sys_call_error) != 0) throw USER_EXCEPTION(SE4080);
|
631
|
+
|
632
|
+
if (ubind_tcp(sock, port, __sys_call_error) == U_SOCKET_ERROR) throw USER_ENV_EXCEPTION2("Failed to bind socket", usocket_error_translator(), false);
|
633
|
+
|
634
|
+
if (ulisten(sock, PPING_LSTNR_QUEUE_LEN, __sys_call_error) == U_SOCKET_ERROR) throw USER_ENV_EXCEPTION("Failed to listen socket", false);
|
635
|
+
|
636
|
+
uResVal res = uCreateThread(pping_server_lstn_thread_proc_st, this, &server_lstn_thread_handle, PPING_STACK_SIZE, NULL, __sys_call_error);
|
637
|
+
if (res != 0) throw USER_ENV_EXCEPTION("Failed to create pping server thread", false);
|
638
|
+
initialized = true;
|
639
|
+
#endif
|
640
|
+
}
|
641
|
+
|
642
|
+
void pping_server::shutdown()
|
643
|
+
{
|
644
|
+
#ifdef PPING_ON
|
645
|
+
if (!initialized) return;
|
646
|
+
|
647
|
+
close_lstn_thread = true;
|
648
|
+
|
649
|
+
USOCKET s = usocket(AF_INET, SOCK_STREAM, 0, NULL);
|
650
|
+
if (s == U_INVALID_SOCKET)
|
651
|
+
throw USER_ENV_EXCEPTION("Failed to create socket", false);
|
652
|
+
|
653
|
+
if (uconnect_tcp(s, port, "127.0.0.1", NULL) == U_SOCKET_ERROR)
|
654
|
+
throw USER_ENV_EXCEPTION("Failed to create TCP connection", false);
|
655
|
+
|
656
|
+
char c = PPING_KEEP_ALIVE_MSG;
|
657
|
+
usend(s, &c, sizeof(c), NULL);
|
658
|
+
|
659
|
+
if (uThreadJoin(server_lstn_thread_handle, NULL) != 0)
|
660
|
+
throw USER_ENV_EXCEPTION("Error waiting for pping server_lstn thread to shutdown", false);
|
661
|
+
|
662
|
+
if (uclose_socket(s, NULL) != 0)
|
663
|
+
throw USER_ENV_EXCEPTION("Failed to close socket", false);
|
664
|
+
|
665
|
+
if (uclose_socket(sock, NULL) != 0)
|
666
|
+
throw USER_ENV_EXCEPTION("Failed to close socket", false);
|
667
|
+
|
668
|
+
if (uCloseThreadHandle(server_lstn_thread_handle, NULL) != 0)
|
669
|
+
throw USER_EXCEPTION2(SE4063, "pping server_lstn_thread");
|
670
|
+
#endif
|
671
|
+
}
|
672
|
+
|