Skip to content

Commit 39d584b

Browse files
committed
Migration move stuff
Signed-off-by: Salil Chandra <[email protected]>
1 parent 96f8dc2 commit 39d584b

File tree

1 file changed

+82
-77
lines changed

1 file changed

+82
-77
lines changed

cdb2api/cdb2api.c

Lines changed: 82 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,16 @@ static int _MACHINE_ID; /* ONE-TIME */
230230
static char *_ARGV0; /* ONE-TIME */
231231
#define DB_TZNAME_DEFAULT "America/New_York"
232232

233+
static pthread_mutex_t cdb2_event_mutex = PTHREAD_MUTEX_INITIALIZER;
234+
static cdb2_event cdb2_gbl_events;
235+
static int cdb2_gbl_event_version;
236+
static cdb2_event *cdb2_next_callback(cdb2_hndl_tp *, cdb2_event_type, cdb2_event *);
237+
static void *cdb2_invoke_callback(cdb2_hndl_tp *, cdb2_event *, int, ...);
238+
static int refresh_gbl_events_on_hndl(cdb2_hndl_tp *);
239+
240+
static pthread_once_t init_once = PTHREAD_ONCE_INIT;
241+
static int log_calls = 0; /* ONE-TIME */
242+
233243
static pthread_mutex_t cdb2_ssl_sess_lock = PTHREAD_MUTEX_INITIALIZER;
234244

235245
static cdb2_ssl_sess *cdb2_get_ssl_sessions(cdb2_hndl_tp *hndl);
@@ -244,19 +254,8 @@ pthread_mutex_t cdb2_sockpool_mutex = PTHREAD_MUTEX_INITIALIZER;
244254

245255
#include <netdb.h>
246256

247-
static pthread_once_t init_once = PTHREAD_ONCE_INIT;
248-
static int log_calls = 0; /* ONE-TIME */
249-
250257
static void reset_sockpool(void);
251258

252-
static pthread_mutex_t cdb2_event_mutex = PTHREAD_MUTEX_INITIALIZER;
253-
static cdb2_event cdb2_gbl_events;
254-
static int cdb2_gbl_event_version;
255-
static cdb2_event *cdb2_next_callback(cdb2_hndl_tp *, cdb2_event_type,
256-
cdb2_event *);
257-
static void *cdb2_invoke_callback(cdb2_hndl_tp *, cdb2_event *, int, ...);
258-
static int refresh_gbl_events_on_hndl(cdb2_hndl_tp *);
259-
260259
#define PROCESS_EVENT_CTRL_BEFORE(h, e, rc, callbackrc, ovwrrc) \
261260
do { \
262261
if (e->ctrls & CDB2_OVERWRITE_RETURN_VALUE) { \
@@ -310,6 +309,37 @@ void cdb2_set_install_libs(void (*ptr)(void)) { cdb2_install = ptr; }
310309
void cdb2_set_uninstall_libs(void (*ptr)(void)) { cdb2_uninstall = ptr; }
311310
#endif
312311

312+
pthread_mutex_t cdb2_sockpool_mutex = PTHREAD_MUTEX_INITIALIZER;
313+
#define MAX_SOCKPOOL_FDS 8
314+
315+
#include <netdb.h>
316+
317+
static char *cdb2_type_str(int type)
318+
{
319+
switch (type) {
320+
case CDB2_INTEGER:
321+
return "CDB2_INTEGER";
322+
case CDB2_REAL:
323+
return "CDB2_REAL";
324+
case CDB2_CSTRING:
325+
return "CDB2_CSTRING";
326+
case CDB2_BLOB:
327+
return "CDB2_BLOB";
328+
case CDB2_DATETIME:
329+
return "CDB2_DATETIME";
330+
case CDB2_INTERVALYM:
331+
return "CDB2_INTERVALYM";
332+
case CDB2_INTERVALDS:
333+
return "CDB2_INTERVALDS";
334+
case CDB2_DATETIMEUS:
335+
return "CDB2_DATETIMEUS";
336+
case CDB2_INTERVALDSUS:
337+
return "CDB2_INTERVALDSUS";
338+
default:
339+
return "???";
340+
}
341+
}
342+
313343
#define debugprint(fmt, args...) \
314344
do { \
315345
if (hndl && hndl->debug_trace) \
@@ -1104,14 +1134,6 @@ static int cdb2_do_tcpconnect(struct in_addr in, int port, int myport,
11041134
static void cdb2_init_context_msgs(cdb2_hndl_tp *hndl);
11051135
static int cdb2_free_context_msgs(cdb2_hndl_tp *hndl);
11061136

1107-
/* Make it equal to FSQL header. */
1108-
struct newsqlheader {
1109-
int type;
1110-
int compression;
1111-
int state; /* query state */
1112-
int length;
1113-
};
1114-
11151137
static cdb2_ssl_sess cdb2_ssl_sess_cache;
11161138

11171139
static int cdb2_tcpconnecth_to(cdb2_hndl_tp *hndl, const char *host, int port,
@@ -1148,6 +1170,14 @@ static int cdb2_tcpconnecth_to(cdb2_hndl_tp *hndl, const char *host, int port,
11481170
return rc;
11491171
}
11501172

1173+
/* Make it equal to FSQL header. */
1174+
struct newsqlheader {
1175+
int type;
1176+
int compression;
1177+
int state; /* query state */
1178+
int length;
1179+
};
1180+
11511181
void cdb2_set_min_retries(int min_retries)
11521182
{
11531183
if (min_retries > 0) {
@@ -2023,6 +2053,28 @@ static int sockpool_get_from_pool(void)
20232053
return fd;
20242054
}
20252055

2056+
static void get_host_and_port_from_fd(int fd, char *buf, size_t n, int *port)
2057+
{
2058+
int rc;
2059+
struct sockaddr_in addr;
2060+
socklen_t addr_size = sizeof(struct sockaddr_in);
2061+
2062+
if (!get_hostname_from_sockpool_fd)
2063+
return;
2064+
2065+
if (fd == -1)
2066+
return;
2067+
2068+
rc = getpeername(fd, (struct sockaddr *)&addr, &addr_size);
2069+
if (rc == 0) {
2070+
if (port != NULL)
2071+
*port = addr.sin_port;
2072+
/* Request a short host name. Set buf to empty on error. */
2073+
if (getnameinfo((struct sockaddr *)&addr, addr_size, buf, n, NULL, 0, NI_NOFQDN))
2074+
buf[0] = '\0';
2075+
}
2076+
}
2077+
20262078
/* The sockpool mutex must be locked at this point */
20272079
static int sockpool_place_fd_in_pool(int fd)
20282080
{
@@ -2507,27 +2559,6 @@ static int cdb2portmux_route(cdb2_hndl_tp *hndl, const char *remote_host,
25072559
return fd;
25082560
}
25092561

2510-
static void get_host_and_port_from_fd(int fd, char *buf, size_t n, int *port)
2511-
{
2512-
int rc;
2513-
struct sockaddr_in addr;
2514-
socklen_t addr_size = sizeof(struct sockaddr_in);
2515-
2516-
if (!get_hostname_from_sockpool_fd)
2517-
return;
2518-
2519-
if (fd == -1)
2520-
return;
2521-
2522-
rc = getpeername(fd, (struct sockaddr *)&addr, &addr_size);
2523-
if (rc == 0) {
2524-
*port = addr.sin_port;
2525-
/* Request a short host name. Set buf to empty on error. */
2526-
if (getnameinfo((struct sockaddr *)&addr, addr_size, buf, n, NULL, 0, NI_NOFQDN))
2527-
buf[0] = '\0';
2528-
}
2529-
}
2530-
25312562
static int newsql_connect_via_fd(cdb2_hndl_tp *hndl)
25322563
{
25332564
int rc = 0;
@@ -3856,6 +3887,17 @@ int cdb2_get_effects(cdb2_hndl_tp *hndl, cdb2_effects_tp *effects)
38563887
return rc;
38573888
}
38583889

3890+
/*
3891+
Clear ack flag so cdb2_close will not consume event
3892+
*/
3893+
int cdb2_clear_ack(cdb2_hndl_tp *hndl)
3894+
{
3895+
if (hndl && hndl->ack) {
3896+
hndl->ack = 0;
3897+
}
3898+
return 0;
3899+
}
3900+
38593901
static void free_query_list(struct query_list *head)
38603902
{
38613903
struct cdb2_query *q, *tmp;
@@ -5476,32 +5518,6 @@ static int cdb2_run_statement_typed_int(cdb2_hndl_tp *hndl, const char *sql, int
54765518
PRINT_AND_RETURN(-1);
54775519
}
54785520

5479-
static char *cdb2_type_str(int type)
5480-
{
5481-
switch (type) {
5482-
case CDB2_INTEGER:
5483-
return "CDB2_INTEGER";
5484-
case CDB2_REAL:
5485-
return "CDB2_REAL";
5486-
case CDB2_CSTRING:
5487-
return "CDB2_CSTRING";
5488-
case CDB2_BLOB:
5489-
return "CDB2_BLOB";
5490-
case CDB2_DATETIME:
5491-
return "CDB2_DATETIME";
5492-
case CDB2_INTERVALYM:
5493-
return "CDB2_INTERVALYM";
5494-
case CDB2_INTERVALDS:
5495-
return "CDB2_INTERVALDS";
5496-
case CDB2_DATETIMEUS:
5497-
return "CDB2_DATETIMEUS";
5498-
case CDB2_INTERVALDSUS:
5499-
return "CDB2_INTERVALDSUS";
5500-
default:
5501-
return "???";
5502-
}
5503-
}
5504-
55055521
int cdb2_run_statement_typed(cdb2_hndl_tp *hndl, const char *sql, int ntypes,
55065522
int *types)
55075523
{
@@ -7478,17 +7494,6 @@ int cdb2_clear_contexts(cdb2_hndl_tp *hndl)
74787494
return cdb2_free_context_msgs(hndl);
74797495
}
74807496

7481-
/*
7482-
Clear ack flag so cdb2_close will not consume event
7483-
*/
7484-
int cdb2_clear_ack(cdb2_hndl_tp* hndl)
7485-
{
7486-
if (hndl) {
7487-
hndl->ack = 0;
7488-
}
7489-
return 0;
7490-
}
7491-
74927497
cdb2_event *cdb2_register_event(cdb2_hndl_tp *hndl, cdb2_event_type types,
74937498
cdb2_event_ctrl ctrls, cdb2_event_callback cb,
74947499
void *user_arg, int nargs, ...)

0 commit comments

Comments
 (0)