CUBRID Engine  latest
network_cl.c
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  * network_cl.c - client side support functions.
21  */
22 
23 #ident "$Id$"
24 
25 #include "config.h"
26 
27 #include <stdio.h>
28 #include <string.h>
29 #include <assert.h>
30 
31 /* for performance metering */
32 #if !defined(WINDOWS)
33 #include <sys/time.h>
34 #include <sys/resource.h>
35 #endif /* !WINDDOWS */
36 
37 #include "network.h"
38 #include "network_interface_cl.h"
39 #include "chartype.h"
40 #include "connection_cl.h"
41 #include "server_interface.h"
42 #include "memory_alloc.h"
43 #include "databases_file.h"
44 #include "error_manager.h"
45 #include "system_parameter.h"
46 #include "environment_variable.h"
47 #include "boot_cl.h"
48 #include "query_method.h"
49 #include "method_def.hpp"
50 #include "release_string.h"
51 #include "log_comm.h"
52 #include "file_io.h"
53 #include "locator.h"
54 #include "db.h"
55 #include "client_support.h"
56 #include "perf_monitor.h"
57 #include "log_writer.h"
58 #include "object_representation.h"
59 
60 /*
61  * To check for errors from the comm system. Note that if we get any error
62  * other than RECORD_TRUNCATED or CANT_ALLOC_BUFFER, we will call it a
63  * SERVER_CRASHED error. Also note that CANT_ALLOC_BUFFER allows the
64  * calling function to continue whereas other errors disconnect and escape
65  * the function.
66  */
67 
68 #define COMPARE_SIZE_AND_BUFFER(replysize, size, replybuf, buf) \
69  compare_size_and_buffer((replysize), (size), (replybuf), (buf), \
70  __FILE__, __LINE__)
71 
72 #define COMPARE_AND_FREE_BUFFER(queued, reply) \
73  do { \
74  if (((reply) != NULL) && ((reply) != (queued))) { \
75  free_and_init ((reply)); \
76  } \
77  (reply) = NULL; \
78  } while (0)
79 
80 /*
81  * Add instrumentation to the client side to get histogram of network
82  * requests
83  */
84 
86 {
87  const char *name;
92 };
94 
95 static int net_Histo_setup = 0;
96 static int net_Histo_setup_mnt = 0;
97 static int net_Histo_call_count = 0;
98 static INT64 net_Histo_last_call_time = 0;
99 static INT64 net_Histo_total_server_time = 0;
100 
101 #if defined(CS_MODE)
102 unsigned short method_request_id;
103 #endif /* CS_MODE */
104 
105 /* Contains the name of the current sever host machine. */
106 static char net_Server_host[CUB_MAXHOSTNAMELEN + 1] = "";
107 
108 /* Contains the name of the current server name. */
110 
111 static void return_error_to_server (char *host, unsigned int eid);
112 static int client_capabilities (void);
113 static int check_server_capabilities (int server_cap, int client_type, int rel_compare,
114  REL_COMPATIBILITY * compatibility, const char *server_host, int opt_cap);
115 static int net_set_alloc_err_if_not_set (int err, const char *file, const int line);
116 static void net_consume_expected_packets (int rc, int num_packets);
117 static int compare_size_and_buffer (int *replysize, int size, char **replybuf, char *buf, const char *file,
118  const int line);
119 static int net_client_request_internal (int request, char *argbuf, int argsize, char *replybuf, int replysize,
120  char *databuf, int datasize, char *replydata, int replydatasize);
121 static int set_server_error (int error);
122 
123 static void net_histo_setup_names (void);
124 static void net_histo_add_entry (int request, int data_sent);
125 static void net_histo_request_finished (int request, int data_received);
126 
127 static const char *get_capability_string (int cap, int cap_type);
128 
129 /*
130  * Shouldn't know about db_Connect_status at this level, must set this
131  * to disable all db_ functions
132  */
133 
134 /*
135  * set_server_error -
136  *
137  * return:
138  * error(in):
139  *
140  * Note:
141  */
142 
143 static int
145 {
146  int server_error;
147 
148  switch (error)
149  {
150  case CANT_ALLOC_BUFFER:
151  server_error = ER_NET_CANT_ALLOC_BUFFER;
152  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, server_error, 0);
153  break;
154  case RECORD_TRUNCATED:
155  server_error = ER_NET_DATA_TRUNCATED;
156  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, server_error, 0);
157  break;
158  case REQUEST_REFUSED:
159  assert (er_errid () != NO_ERROR);
160  server_error = er_errid ();
161  break;
162  case SERVER_ABORTED:
163  /* server error may not be set when SERVER_ABORTED is given. server may send ABORT_TYPE for some cases and the
164  * server error will not be delivered for the case. */
165  server_error = er_errid ();
166  /* those errors are generated by the net_server_request() so that do not fall to server crash handling */
167  switch (server_error)
168  {
170  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, server_error, 0);
171  return server_error;
172  case ER_AU_DBA_ONLY:
173  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, server_error, 1, "");
174  return server_error;
175  }
176  /* FALLTHRU */
177  default:
178  server_error = ER_NET_SERVER_CRASHED;
180  break;
181  }
182 
183  er_log_debug (ARG_FILE_LINE, "set_server_error(%d) server_error %d\n", error, server_error);
184 
186 
187  if (net_Server_name[0] != '\0')
188  {
189  net_Server_name[0] = '\0';
190  net_Server_host[0] = '\0';
192  }
193 
194  return server_error;
195 }
196 
197 /*
198  * return_error_to_server -
199  *
200  * return:
201  *
202  * host(in):
203  * eid(in):
204  *
205  * Note:
206  */
207 static void
208 return_error_to_server (char *host, unsigned int eid)
209 {
210  char *area;
211  OR_ALIGNED_BUF (1024) a_buffer;
212  char *buffer;
213  int length = 1024;
214 
215  buffer = OR_ALIGNED_BUF_START (a_buffer);
216 
217  area = er_get_area_error (buffer, &length);
218  if (area != NULL)
219  {
220  css_send_error_to_server (host, eid, area, length);
221  }
222 }
223 
224 /*
225  * client_capabilities -
226  *
227  * return:
228  */
229 static int
231 {
232  int capabilities = 0;
233 
234  capabilities |= NET_CAP_INTERRUPT_ENABLED;
235  if (db_Disable_modifications > 0)
236  {
237  capabilities |= NET_CAP_UPDATE_DISABLED;
238  }
239 
241  {
242  capabilities |= NET_CAP_HA_IGNORE_REPL_DELAY;
243  }
244 
245  return capabilities;
246 }
247 
248 /*
249  * get_capability_string - for the purpose of error logging,
250  * it translate cap into a word
251  *
252  * return:
253  */
254 static const char *
255 get_capability_string (int cap, int cap_type)
256 {
257  switch (cap_type)
258  {
260  if (cap & NET_CAP_INTERRUPT_ENABLED)
261  {
262  return "enabled";
263  }
264  return "disabled";
266  if (cap & NET_CAP_UPDATE_DISABLED)
267  {
268  return "read only";
269  }
270  return "read/write";
271  default:
272  return "-";
273  }
274 }
275 
276 /*
277  * check_server_capabilities -
278  *
279  * return:
280  */
281 static int
282 check_server_capabilities (int server_cap, int client_type, int rel_compare, REL_COMPATIBILITY * compatibility,
283  const char *server_host, int opt_cap)
284 {
285  int client_cap;
286 
287  assert (compatibility != NULL);
288 
289  client_cap = client_capabilities ();
290  client_cap |= opt_cap;
291 
292  /* interrupt-ability should be same */
293  if ((client_cap ^ server_cap) & NET_CAP_INTERRUPT_ENABLED)
294  {
296  get_capability_string (client_cap, NET_CAP_INTERRUPT_ENABLED),
297  get_capability_string (server_cap, NET_CAP_INTERRUPT_ENABLED));
298  server_cap ^= NET_CAP_INTERRUPT_ENABLED;
299  }
300 
301  /* replica only client should check whether the server is replica */
302  if (BOOT_REPLICA_ONLY_BROKER_CLIENT_TYPE (client_type))
303  {
304  if (~server_cap & NET_CAP_HA_REPLICA)
305  {
307  server_cap ^= NET_CAP_HA_REPLICA;
308  }
309  }
310  else
311  {
312  /* update-ability should be same */
313  if ((client_cap ^ server_cap) & NET_CAP_UPDATE_DISABLED)
314  {
316  get_capability_string (client_cap, NET_CAP_UPDATE_DISABLED),
317  get_capability_string (server_cap, NET_CAP_UPDATE_DISABLED));
318  server_cap ^= NET_CAP_UPDATE_DISABLED;
319 
321  }
322  }
323 
324  /*
325  * check HA replication delay
326  * if client_cap is on, it checks the server delay status
327  * else, it ignores the delay status.
328  */
329  if (client_cap & NET_CAP_HA_REPL_DELAY & server_cap)
330  {
332  server_cap ^= NET_CAP_HA_REPL_DELAY;
333 
335  }
336 
337  /* network protocol compatibility */
338  if (*compatibility == REL_NOT_COMPATIBLE)
339  {
340  if (rel_compare < 0 && ((server_cap & NET_CAP_BACKWARD_COMPATIBLE) || (client_cap & NET_CAP_FORWARD_COMPATIBLE)))
341  {
342  /*
343  * The client is older than the server but the server has a backward
344  * compatible capability or the client has a forward compatible
345  * capability.
346  */
347  *compatibility = REL_FORWARD_COMPATIBLE;
348  }
349  if (rel_compare > 0 && ((server_cap & NET_CAP_FORWARD_COMPATIBLE) || (client_cap & NET_CAP_BACKWARD_COMPATIBLE)))
350  {
351  /*
352  * The client is newer than the server but the server has a forward
353  * compatible capability or the client has a backward compatible
354  * capability.
355  */
356  *compatibility = REL_BACKWARD_COMPATIBLE;
357  }
358  }
359 
360  /* remote connection capability */
361  if ((server_cap & NET_CAP_REMOTE_DISABLED)
362  && !BOOT_IS_ALLOWED_CLIENT_TYPE_IN_MT_MODE (server_host, boot_Host_name, client_type))
363  {
365  server_cap ^= NET_CAP_REMOTE_DISABLED;
366  }
367 
368  return server_cap;
369 }
370 
371 /*
372  * net_set_alloc_err_if_not_set
373  *
374  * return:
375  *
376  * err(in):
377  * file(in):
378  * line(in):
379  *
380  */
381 static int
382 net_set_alloc_err_if_not_set (int err, const char *file, const int line)
383 {
384  /* don't set error if there already is one */
385  if (err == NO_ERROR)
386  {
388  er_set (ER_ERROR_SEVERITY, file, line, err, 0);
389  }
390 
391  return err;
392 }
393 
394 static void
395 net_consume_expected_packets (int rc, int num_packets)
396 {
397  char *reply = NULL;
398  int i, size = 0;
399 
400  for (i = 0; i < num_packets; i++)
401  {
402  css_receive_data_from_server (rc, &reply, &size);
403  if (reply != NULL)
404  {
405  free_and_init (reply);
406  }
407  }
408 }
409 
410 /*
411  * compare_size_and_buffer -
412  *
413  * return:
414  *
415  * replysize(in):
416  * size(in):
417  * replybuf(in):
418  * buf(in):
419  * file(in):
420  * line(in):
421  *
422  * Note:
423  * Compares sizes and buffers that have been queued with the actual
424  * received values after a data read. Called by macro of the same name.
425  */
426 static int
427 compare_size_and_buffer (int *replysize, int size, char **replybuf, char *buf, const char *file, const int line)
428 {
429  int err = NO_ERROR;
430 
431  if (size <= 0)
432  {
433  return NO_ERROR;
434  }
435 
436  if (size != *replysize)
437  {
439  er_set (ER_ERROR_SEVERITY, file, line, err, 2, *replysize, size);
440  *replysize = size;
441  }
442 
443  if (buf != *replybuf)
444  {
445  err = ER_NET_UNUSED_BUFFER;
446  er_set (ER_ERROR_SEVERITY, file, line, err, 0);
447  /* free it ? */
448  *replybuf = buf;
449  }
450 
451  return err;
452 }
453 
454 /*
455  * net_histo_setup_names -
456  *
457  * return:
458  *
459  * Note:
460  */
461 static void
463 {
464  unsigned int i;
465 
466  for (i = 0; i < DIM (net_Req_buffer); i++)
467  {
468  net_Req_buffer[i].name = "";
473  }
474 
475  net_Req_buffer[NET_SERVER_BO_INIT_SERVER].name = "NET_SERVER_BO_INIT_SERVER";
476  net_Req_buffer[NET_SERVER_BO_REGISTER_CLIENT].name = "NET_SERVER_BO_REGISTER_CLIENT";
477  net_Req_buffer[NET_SERVER_BO_UNREGISTER_CLIENT].name = "NET_SERVER_BO_UNREGISTER_CLIENT";
478  net_Req_buffer[NET_SERVER_BO_BACKUP].name = "NET_SERVER_BO_BACKUP";
479  net_Req_buffer[NET_SERVER_BO_ADD_VOLEXT].name = "NET_SERVER_BO_ADD_VOLEXT";
480  net_Req_buffer[NET_SERVER_BO_CHECK_DBCONSISTENCY].name = "NET_SERVER_BO_CHECK_DBCONSISTENCY";
481  net_Req_buffer[NET_SERVER_BO_FIND_NPERM_VOLS].name = "NET_SERVER_BO_FIND_NPERM_VOLS";
482  net_Req_buffer[NET_SERVER_BO_FIND_NTEMP_VOLS].name = "NET_SERVER_BO_FIND_NTEMP_VOLS";
483  net_Req_buffer[NET_SERVER_BO_FIND_LAST_PERM].name = "NET_SERVER_BO_FIND_LAST_PERM";
484  net_Req_buffer[NET_SERVER_BO_FIND_LAST_TEMP].name = "NET_SERVER_BO_FIND_LAST_TEMP";
485  net_Req_buffer[NET_SERVER_BO_CHANGE_HA_MODE].name = "NET_SERVER_BO_CHANGE_HA_MODE";
486  net_Req_buffer[NET_SERVER_BO_NOTIFY_HA_LOG_APPLIER_STATE].name = "NET_SERVER_BO_NOTIFY_HA_LOG_APPLIER_STATE";
487  net_Req_buffer[NET_SERVER_BO_COMPACT_DB].name = "NET_SERVER_BO_COMPACT_DB";
488  net_Req_buffer[NET_SERVER_BO_HEAP_COMPACT].name = "NET_SERVER_BO_HEAP_COMPACT";
489  net_Req_buffer[NET_SERVER_BO_COMPACT_DB_START].name = "NET_SERVER_BO_COMPACT_DB_START";
490  net_Req_buffer[NET_SERVER_BO_COMPACT_DB_STOP].name = "NET_SERVER_BO_COMPACT_DB_STOP";
491  net_Req_buffer[NET_SERVER_BO_GET_LOCALES_INFO].name = "NET_SERVER_BO_GET_LOCALES_INFO";
492 
493  net_Req_buffer[NET_SERVER_TM_SERVER_COMMIT].name = "NET_SERVER_TM_SERVER_COMMIT";
494  net_Req_buffer[NET_SERVER_TM_SERVER_ABORT].name = "NET_SERVER_TM_SERVER_ABORT";
495  net_Req_buffer[NET_SERVER_TM_SERVER_START_TOPOP].name = "NET_SERVER_TM_SERVER_START_TOPOP";
496  net_Req_buffer[NET_SERVER_TM_SERVER_END_TOPOP].name = "NET_SERVER_TM_SERVER_END_TOPOP";
497  net_Req_buffer[NET_SERVER_TM_SERVER_SAVEPOINT].name = "NET_SERVER_TM_SERVER_SAVEPOINT";
498  net_Req_buffer[NET_SERVER_TM_SERVER_PARTIAL_ABORT].name = "NET_SERVER_TM_SERVER_PARTIAL_ABORT";
499  net_Req_buffer[NET_SERVER_TM_SERVER_HAS_UPDATED].name = "NET_SERVER_TM_SERVER_HAS_UPDATED";
500  net_Req_buffer[NET_SERVER_TM_SERVER_ISACTIVE_AND_HAS_UPDATED].name = "NET_SERVER_TM_SERVER_ISACTIVE_AND_HAS_UPDATED";
501  net_Req_buffer[NET_SERVER_TM_ISBLOCKED].name = "NET_SERVER_TM_ISBLOCKED";
502  net_Req_buffer[NET_SERVER_TM_WAIT_SERVER_ACTIVE_TRANS].name = "NET_SERVER_TM_WAIT_SERVER_ACTIVE_TRANS";
503  net_Req_buffer[NET_SERVER_TM_SERVER_GET_GTRINFO].name = "NET_SERVER_TM_SERVER_GET_GTRINFO";
504  net_Req_buffer[NET_SERVER_TM_SERVER_SET_GTRINFO].name = "NET_SERVER_TM_SERVER_SET_GTRINFO";
505  net_Req_buffer[NET_SERVER_TM_SERVER_2PC_START].name = "NET_SERVER_TM_SERVER_2PC_START";
506  net_Req_buffer[NET_SERVER_TM_SERVER_2PC_PREPARE].name = "NET_SERVER_TM_SERVER_2PC_PREPARE";
507  net_Req_buffer[NET_SERVER_TM_SERVER_2PC_RECOVERY_PREPARED].name = "NET_SERVER_TM_SERVER_2PC_RECOVERY_PREPARED";
508  net_Req_buffer[NET_SERVER_TM_SERVER_2PC_ATTACH_GT].name = "NET_SERVER_TM_SERVER_2PC_ATTACH_GT";
509  net_Req_buffer[NET_SERVER_TM_SERVER_2PC_PREPARE_GT].name = "NET_SERVER_TM_SERVER_2PC_PREPARE_GT";
510  net_Req_buffer[NET_SERVER_TM_LOCAL_TRANSACTION_ID].name = "NET_SERVER_TM_LOCAL_TRANSACTION_ID";
511  net_Req_buffer[NET_SERVER_LOG_CHECKPOINT].name = "NET_SERVER_LOG_CHECKPOINT";
512 
513  net_Req_buffer[NET_SERVER_LC_FETCH].name = "NET_SERVER_LC_FETCH";
514  net_Req_buffer[NET_SERVER_LC_FETCHALL].name = "NET_SERVER_LC_FETCHALL";
515  net_Req_buffer[NET_SERVER_LC_FETCH_LOCKSET].name = "NET_SERVER_LC_FETCH_LOCKSET";
516  net_Req_buffer[NET_SERVER_LC_FETCH_ALLREFS_LOCKSET].name = "NET_SERVER_LC_FETCH_ALLREFS_LOCKSET";
517  net_Req_buffer[NET_SERVER_LC_GET_CLASS].name = "NET_SERVER_LC_GET_CLASS";
518  net_Req_buffer[NET_SERVER_LC_FIND_CLASSOID].name = "NET_SERVER_LC_FIND_CLASSOID";
519  net_Req_buffer[NET_SERVER_LC_DOESEXIST].name = "NET_SERVER_LC_DOESEXIST";
520  net_Req_buffer[NET_SERVER_LC_FORCE].name = "NET_SERVER_LC_FORCE";
521  net_Req_buffer[NET_SERVER_LC_RESERVE_CLASSNAME].name = "NET_SERVER_LC_RESERVE_CLASSNAME";
522  net_Req_buffer[NET_SERVER_LC_RESERVE_CLASSNAME_GET_OID].name = "NET_SERVER_LC_RESERVE_CLASSNAME_GET_OID";
523  net_Req_buffer[NET_SERVER_LC_DELETE_CLASSNAME].name = "NET_SERVER_LC_DELETE_CLASSNAME";
524  net_Req_buffer[NET_SERVER_LC_RENAME_CLASSNAME].name = "NET_SERVER_LC_RENAME_CLASSNAME";
525  net_Req_buffer[NET_SERVER_LC_ASSIGN_OID].name = "NET_SERVER_LC_ASSIGN_OID";
526  net_Req_buffer[NET_SERVER_LC_NOTIFY_ISOLATION_INCONS].name = "NET_SERVER_LC_NOTIFY_ISOLATION_INCONS";
527  net_Req_buffer[NET_SERVER_LC_FIND_LOCKHINT_CLASSOIDS].name = "NET_SERVER_LC_FIND_LOCKHINT_CLASSOIDS";
528  net_Req_buffer[NET_SERVER_LC_FETCH_LOCKHINT_CLASSES].name = "NET_SERVER_LC_FETCH_LOCKHINT_CLASSES";
529  net_Req_buffer[NET_SERVER_LC_ASSIGN_OID_BATCH].name = "NET_SERVER_LC_ASSIGN_OID_BATCH";
530  net_Req_buffer[NET_SERVER_LC_CHECK_FK_VALIDITY].name = "NET_SERVER_LC_CHECK_FK_VALIDITY";
531  net_Req_buffer[NET_SERVER_LC_REM_CLASS_FROM_INDEX].name = "NET_SERVER_LC_REM_CLASS_FROM_INDEX";
532  net_Req_buffer[NET_SERVER_LC_DEMOTE_CLASS_LOCK].name = "NET_SERVER_LC_DEMOTE_CLASS_LOCK";
533 
534  net_Req_buffer[NET_SERVER_HEAP_CREATE].name = "NET_SERVER_HEAP_CREATE";
535  net_Req_buffer[NET_SERVER_HEAP_DESTROY].name = "NET_SERVER_HEAP_DESTROY";
536  net_Req_buffer[NET_SERVER_HEAP_DESTROY_WHEN_NEW].name = "NET_SERVER_HEAP_DESTROY_WHEN_NEW";
537  net_Req_buffer[NET_SERVER_HEAP_GET_CLASS_NOBJS_AND_NPAGES].name = "NET_SERVER_HEAP_GET_CLASS_NOBJS_AND_NPAGES";
538  net_Req_buffer[NET_SERVER_HEAP_HAS_INSTANCE].name = "NET_SERVER_HEAP_HAS_INSTANCE";
539  net_Req_buffer[NET_SERVER_HEAP_RECLAIM_ADDRESSES].name = "NET_SERVER_HEAP_RECLAIM_ADDRESSES";
540 
541  net_Req_buffer[NET_SERVER_FILE_APPLY_TDE_TO_CLASS_FILES].name = "NET_SERVER_FILE_APPLY_TDE_TO_CLASS_FILES";
542 
543  net_Req_buffer[NET_SERVER_TDE_GET_DATA_KEYS].name = "NET_SERVER_TDE_GET_DATA_KEYS";
544  net_Req_buffer[NET_SERVER_TDE_GET_MK_FILE_PATH].name = "NET_SERVER_TDE_GET_MK_FILE_PATH";
545  net_Req_buffer[NET_SERVER_TDE_GET_MK_INFO].name = "NET_SERVER_TDE_GET_MK_INFO";
546  net_Req_buffer[NET_SERVER_TDE_CHANGE_MK_ON_SERVER].name = "NET_SERVER_TDE_CHANGE_MK_ON_SERVER";
547 
548  net_Req_buffer[NET_SERVER_LOG_RESET_WAIT_MSECS].name = "NET_SERVER_LOG_RESET_WAIT_MSECS";
549  net_Req_buffer[NET_SERVER_LOG_RESET_ISOLATION].name = "NET_SERVER_LOG_RESET_ISOLATION";
550  net_Req_buffer[NET_SERVER_LOG_SET_INTERRUPT].name = "NET_SERVER_LOG_SET_INTERRUPT";
551  net_Req_buffer[NET_SERVER_LOG_DUMP_STAT].name = "NET_SERVER_LOG_DUMP_STAT";
552  net_Req_buffer[NET_SERVER_LOG_GETPACK_TRANTB].name = "NET_SERVER_LOG_GETPACK_TRANTB";
553  net_Req_buffer[NET_SERVER_LOG_DUMP_TRANTB].name = "NET_SERVER_LOG_DUMP_TRANTB";
555  "NET_SERVER_LOG_SET_SUPPRESS_REPL_ON_TRANSACTION";
556 
557  net_Req_buffer[NET_SERVER_LOG_FIND_LOB_LOCATOR].name = "NET_SERVER_LOG_FIND_LOB_LOCATOR";
558  net_Req_buffer[NET_SERVER_LOG_ADD_LOB_LOCATOR].name = "NET_SERVER_LOG_ADD_LOB_LOCATOR";
559  net_Req_buffer[NET_SERVER_LOG_CHANGE_STATE_OF_LOCATOR].name = "NET_SERVER_LOG_CHANGE_STATE_OF_LOCATOR";
560  net_Req_buffer[NET_SERVER_LOG_DROP_LOB_LOCATOR].name = "NET_SERVER_LOG_DROP_LOB_LOCATOR";
561 
562  net_Req_buffer[NET_SERVER_LK_DUMP].name = "NET_SERVER_LK_DUMP";
563 
564  net_Req_buffer[NET_SERVER_BTREE_ADDINDEX].name = "NET_SERVER_BTREE_ADDINDEX";
565  net_Req_buffer[NET_SERVER_BTREE_DELINDEX].name = "NET_SERVER_BTREE_DELINDEX";
566  net_Req_buffer[NET_SERVER_BTREE_LOADINDEX].name = "NET_SERVER_BTREE_LOADINDEX";
567  net_Req_buffer[NET_SERVER_BTREE_FIND_UNIQUE].name = "NET_SERVER_BTREE_FIND_UNIQUE";
568  net_Req_buffer[NET_SERVER_BTREE_CLASS_UNIQUE_TEST].name = "NET_SERVER_BTREE_CLASS_UNIQUE_TEST";
569  net_Req_buffer[NET_SERVER_BTREE_GET_STATISTICS].name = "NET_SERVER_BTREE_GET_STATISTICS";
570  net_Req_buffer[NET_SERVER_BTREE_GET_KEY_TYPE].name = "NET_SERVER_BTREE_GET_KEY_TYPE";
571 
572  net_Req_buffer[NET_SERVER_DISK_TOTALPGS].name = "NET_SERVER_DISK_TOTALPGS";
573  net_Req_buffer[NET_SERVER_DISK_FREEPGS].name = "NET_SERVER_DISK_FREEPGS";
574  net_Req_buffer[NET_SERVER_DISK_REMARKS].name = "NET_SERVER_DISK_REMARKS";
575  net_Req_buffer[NET_SERVER_DISK_VLABEL].name = "NET_SERVER_DISK_VLABEL";
576 
577  net_Req_buffer[NET_SERVER_QST_GET_STATISTICS].name = "NET_SERVER_QST_GET_STATISTICS";
578  net_Req_buffer[NET_SERVER_QST_UPDATE_STATISTICS].name = "NET_SERVER_QST_UPDATE_STATISTICS";
579  net_Req_buffer[NET_SERVER_QST_UPDATE_ALL_STATISTICS].name = "NET_SERVER_QST_UPDATE_ALL_STATISTICS";
580 
581  net_Req_buffer[NET_SERVER_QM_QUERY_PREPARE].name = "NET_SERVER_QM_QUERY_PREPARE";
582  net_Req_buffer[NET_SERVER_QM_QUERY_EXECUTE].name = "NET_SERVER_QM_QUERY_EXECUTE";
583  net_Req_buffer[NET_SERVER_QM_QUERY_PREPARE_AND_EXECUTE].name = "NET_SERVER_QM_QUERY_PREPARE_AND_EXECUTE";
584  net_Req_buffer[NET_SERVER_QM_QUERY_END].name = "NET_SERVER_QM_QUERY_END";
585  net_Req_buffer[NET_SERVER_QM_QUERY_DROP_ALL_PLANS].name = "NET_SERVER_QM_QUERY_DROP_ALL_PLANS";
586  net_Req_buffer[NET_SERVER_QM_QUERY_DUMP_PLANS].name = "NET_SERVER_QM_QUERY_DUMP_PLANS";
587  net_Req_buffer[NET_SERVER_QM_QUERY_DUMP_CACHE].name = "NET_SERVER_QM_QUERY_DUMP_CACHE";
588 
589  net_Req_buffer[NET_SERVER_LS_GET_LIST_FILE_PAGE].name = "NET_SERVER_LS_GET_LIST_FILE_PAGE";
590 
591  net_Req_buffer[NET_SERVER_MNT_SERVER_START_STATS].name = "NET_SERVER_MNT_SERVER_START_STATS";
592  net_Req_buffer[NET_SERVER_MNT_SERVER_STOP_STATS].name = "NET_SERVER_MNT_SERVER_STOP_STATS";
593  net_Req_buffer[NET_SERVER_MNT_SERVER_COPY_STATS].name = "NET_SERVER_MNT_SERVER_COPY_STATS";
594 
595  net_Req_buffer[NET_SERVER_CT_CHECK_REP_DIR].name = "NET_SERVER_CT_CHECK_REP_DIR";
596 
597  net_Req_buffer[NET_SERVER_CSS_KILL_TRANSACTION].name = "NET_SERVER_CSS_KILL_TRANSACTION";
598  net_Req_buffer[NET_SERVER_CSS_DUMP_CS_STAT].name = "NET_SERVER_CSS_DUMP_CS_STAT";
599 
600  net_Req_buffer[NET_SERVER_QPROC_GET_SYS_TIMESTAMP].name = "NET_SERVER_QPROC_GET_SYS_TIMESTAMP";
601  net_Req_buffer[NET_SERVER_QPROC_GET_CURRENT_VALUE].name = "NET_SERVER_QPROC_GET_CURRENT_VALUE";
602  net_Req_buffer[NET_SERVER_QPROC_GET_NEXT_VALUE].name = "NET_SERVER_QPROC_GET_NEXT_VALUE";
603  net_Req_buffer[NET_SERVER_QPROC_GET_SERVER_INFO].name = "NET_SERVER_QPROC_GET_SERVER_INFO";
604  net_Req_buffer[NET_SERVER_SERIAL_DECACHE].name = "NET_SERVER_SERIAL_DECACHE";
605 
606  net_Req_buffer[NET_SERVER_PRM_SET_PARAMETERS].name = "NET_SERVER_PRM_SET_PARAMETERS";
607  net_Req_buffer[NET_SERVER_PRM_GET_PARAMETERS].name = "NET_SERVER_PRM_GET_PARAMETERS";
608  net_Req_buffer[NET_SERVER_PRM_GET_PARAMETERS].name = "NET_SERVER_PRM_GET_FORCE_PARAMETERS";
609  net_Req_buffer[NET_SERVER_PRM_DUMP_PARAMETERS].name = "NET_SERVER_PRM_DUMP_PARAMETERS";
610 
611  net_Req_buffer[NET_SERVER_JSP_GET_SERVER_PORT].name = "NET_SERVER_JSP_GET_SERVER_PORT";
612 
613  net_Req_buffer[NET_SERVER_REPL_INFO].name = "NET_SERVER_REPL_INFO";
614  net_Req_buffer[NET_SERVER_REPL_LOG_GET_APPEND_LSA].name = "NET_SERVER_REPL_LOG_GET_APPEND_LSA";
615 
616  net_Req_buffer[NET_SERVER_LOGWR_GET_LOG_PAGES].name = "NET_SERVER_LOGWR_GET_LOG_PAGES";
617 
618  net_Req_buffer[NET_SERVER_ES_CREATE_FILE].name = "NET_SERVER_ES_CREATE_FILE";
619  net_Req_buffer[NET_SERVER_ES_WRITE_FILE].name = "NET_SERVER_ES_WRITE_FILE";
620  net_Req_buffer[NET_SERVER_ES_READ_FILE].name = "NET_SERVER_ES_READ_FILE";
621  net_Req_buffer[NET_SERVER_ES_DELETE_FILE].name = "NET_SERVER_ES_DELETE_FILE";
622  net_Req_buffer[NET_SERVER_ES_COPY_FILE].name = "NET_SERVER_ES_COPY_FILE";
623  net_Req_buffer[NET_SERVER_ES_RENAME_FILE].name = "NET_SERVER_ES_RENAME_FILE";
624  net_Req_buffer[NET_SERVER_ES_GET_FILE_SIZE].name = "NET_SERVER_ES_GET_FILE_SIZE";
625 
626  net_Req_buffer[NET_SERVER_SHUTDOWN].name = "NET_SERVER_SHUTDOWN";
627 
628  net_Req_buffer[NET_SERVER_LC_UPGRADE_INSTANCES_DOMAIN].name = "NET_SERVER_LC_UPGRADE_INSTANCES_DOMAIN";
629 
630  net_Req_buffer[NET_SERVER_SES_CHECK_SESSION].name = "NET_SERVER_SES_CHECK_SESSION";
631  net_Req_buffer[NET_SERVER_SES_END_SESSION].name = "NET_SERVER_END_SESSION";
632  net_Req_buffer[NET_SERVER_SES_SET_ROW_COUNT].name = "NET_SERVER_SES_SET_ROW_COUNT";
633  net_Req_buffer[NET_SERVER_SES_GET_ROW_COUNT].name = "NET_SERVER_GET_ROW_COUNT";
634  net_Req_buffer[NET_SERVER_SES_GET_LAST_INSERT_ID].name = "NET_SERVER_SES_GET_LAST_INSERT_ID";
635  net_Req_buffer[NET_SERVER_SES_RESET_CUR_INSERT_ID].name = "NET_SERVER_SES_RESET_CUR_INSERT_ID";
636  net_Req_buffer[NET_SERVER_SES_CREATE_PREPARED_STATEMENT].name = "NET_SERVER_SES_CREATE_PREPARED_STATEMENT";
637  net_Req_buffer[NET_SERVER_SES_GET_PREPARED_STATEMENT].name = "NET_SERVER_SES_GET_PREPARED_STATEMENT";
638  net_Req_buffer[NET_SERVER_SES_DELETE_PREPARED_STATEMENT].name = "NET_SERVER_SES_DELETE_PREPARED_STATEMENT";
639  net_Req_buffer[NET_SERVER_SES_SET_SESSION_VARIABLES].name = "NET_SERVER_SES_SET_SESSION_VARIABLES";
640  net_Req_buffer[NET_SERVER_SES_GET_SESSION_VARIABLE].name = "NET_SERVER_SES_GET_SESSION_VARIABLE";
641  net_Req_buffer[NET_SERVER_SES_DROP_SESSION_VARIABLES].name = "NET_SERVER_SES_DROP_SESSION_VARIABLES";
642  net_Req_buffer[NET_SERVER_BTREE_FIND_MULTI_UNIQUES].name = "NET_SERVER_FIND_MULTI_UNIQUES";
643  net_Req_buffer[NET_SERVER_VACUUM].name = "NET_SERVER_VACUUM";
644  net_Req_buffer[NET_SERVER_GET_MVCC_SNAPSHOT].name = "NET_SERVER_GET_MVCC_SNAPSHOT";
645  net_Req_buffer[NET_SERVER_LOCK_RR].name = "NET_SERVER_LOCK_RR";
646  net_Req_buffer[NET_SERVER_TZ_GET_CHECKSUM].name = "NET_SERVER_TZ_GET_CHECKSUM";
647  net_Req_buffer[NET_SERVER_SPACEDB].name = "NET_SERVER_SPACEDB";
648 
649  net_Req_buffer[NET_SERVER_LD_INIT].name = "NET_SERVER_LD_INIT";
650  net_Req_buffer[NET_SERVER_LD_INSTALL_CLASS].name = "NET_SERVER_LD_INSTALL_CLASS";
651  net_Req_buffer[NET_SERVER_LD_LOAD_BATCH].name = "NET_SERVER_LD_LOAD_BATCH";
652  net_Req_buffer[NET_SERVER_LD_DESTROY].name = "NET_SERVER_LD_DESTROY";
653  net_Req_buffer[NET_SERVER_LD_INTERRUPT].name = "NET_SERVER_LD_INTERRUPT";
654  net_Req_buffer[NET_SERVER_LD_UPDATE_STATS].name = "NET_SERVER_LD_UPDATE_STATS";
655  net_Req_buffer[NET_SERVER_VACUUM_DUMP].name = "NET_SERVER_VACUUM_DUMP";
656 }
657 
658 /*
659  * net_histo_clear -
660  *
661  * return:
662  *
663  * NOTE:
664  */
665 void
667 {
668  unsigned int i;
669 
671  {
672  perfmon_reset_stats ();
673  }
674 
678  for (i = 0; i < DIM (net_Req_buffer); i++)
679  {
684  }
685 }
686 
687 /*
688  * net_histo_print -
689  *
690  * return:
691  *
692  * Note:
693  */
694 int
695 net_histo_print (FILE * stream)
696 {
697  unsigned int i;
698  int found = 0, total_requests = 0, total_size_sent = 0;
699  int total_size_received = 0;
700  float server_time, total_server_time = 0;
701  float avg_response_time, avg_client_time;
702  int err = NO_ERROR;
703 
704  if (stream == NULL)
705  {
706  stream = stdout;
707  }
708 
709  fprintf (stream, "\nHistogram of client requests:\n");
710  fprintf (stream, "%-31s %6s %10s %10s , %10s \n", "Name", "Rcount", "Sent size", "Recv size", "Server time");
711  for (i = 0; i < DIM (net_Req_buffer); i++)
712  {
714  {
715  found = 1;
716  server_time = ((float) net_Req_buffer[i].elapsed_time / 1000000 / (float) (net_Req_buffer[i].request_count));
717  fprintf (stream, "%-29s %6d X %10d+%10d b, %10.6f s\n", net_Req_buffer[i].name,
718  net_Req_buffer[i].request_count, net_Req_buffer[i].total_size_sent,
719  net_Req_buffer[i].total_size_received, server_time);
720  total_requests += net_Req_buffer[i].request_count;
721  total_size_sent += net_Req_buffer[i].total_size_sent;
722  total_size_received += net_Req_buffer[i].total_size_received;
723  total_server_time += (server_time * net_Req_buffer[i].request_count);
724  }
725  }
726  if (!found)
727  {
728  fprintf (stream, " No server requests made\n");
729  }
730  else
731  {
732  fprintf (stream, "-------------------------------------------------------------" "--------------\n");
733  fprintf (stream, "Totals: %6d X %10d+%10d b " "%10.6f s\n", total_requests,
734  total_size_sent, total_size_received, total_server_time);
735  avg_response_time = total_server_time / total_requests;
736  avg_client_time = 0.0;
737  fprintf (stream,
738  "\n Average server response time = %6.6f secs \n"
739  " Average time between client requests = %6.6f secs \n", avg_response_time, avg_client_time);
740  }
742  {
743  err = perfmon_print_stats (stream);
744  }
745  return err;
746 }
747 
748 /*
749  * net_histo_print_global_stats -
750  *
751  * return:
752  *
753  * Note:
754  */
755 int
756 net_histo_print_global_stats (FILE * stream, bool cumulative, const char *substr)
757 {
758  int err = NO_ERROR;
759 
761  {
762  err = perfmon_print_global_stats (stream, cumulative, substr);
763  }
764  return err;
765 }
766 
767 /*
768  * net_histo_start -
769  *
770  * return: NO_ERROR or ER_FAILED
771  *
772  * Note:
773  */
774 int
775 net_histo_start (bool for_all_trans)
776 {
777  if (net_Histo_setup == 0)
778  {
779  net_histo_clear ();
781  net_Histo_setup = 1;
782  }
783 
784  if (net_Histo_setup_mnt == 0)
785  {
786  if (perfmon_start_stats (for_all_trans) != NO_ERROR)
787  {
788  return ER_FAILED;
789  }
791  }
792 
793  return NO_ERROR;
794 }
795 
796 /*
797  * net_histo_stop -
798  *
799  * return: NO_ERROR or ER_FAILED
800  *
801  * Note:
802  */
803 int
805 {
806  int err = NO_ERROR;
807 
808  if (net_Histo_setup_mnt == 1)
809  {
810  err = perfmon_stop_stats ();
812  }
813 
814  if (net_Histo_setup == 1)
815  {
816  net_Histo_setup = 0;
817  }
818 
819  return err;
820 }
821 
822 /*
823  * net_histo_add_entry -
824  *
825  * return:
826  *
827  * request(in):
828  * data_sent(in):
829  *
830  * Note:
831  */
832 static void
833 net_histo_add_entry (int request, int data_sent)
834 {
835 #if !defined(WINDOWS)
836  struct timeval tp;
837 #endif /* WINDOWS */
838 
839  if (request <= NET_SERVER_REQUEST_START || request >= NET_SERVER_REQUEST_END)
840  {
841  return;
842  }
843 
844  net_Req_buffer[request].request_count++;
845  net_Req_buffer[request].total_size_sent += data_sent;
846 #if !defined(WINDOWS)
847  if (gettimeofday (&tp, NULL) == 0)
848  {
849  net_Histo_last_call_time = tp.tv_sec * 1000000LL + tp.tv_usec;
850  }
851 #endif /* !WINDOWS */
853 }
854 
855 /*
856  * net_histo_request_finished -
857  *
858  * return:
859  *
860  * request(in):
861  * data_received(in):
862  *
863  * Note:
864  */
865 static void
866 net_histo_request_finished (int request, int data_received)
867 {
868 #if !defined(WINDOWS)
869  struct timeval tp;
870  INT64 current_time;
871 #endif /* !WINDOWS */
872 
873  net_Req_buffer[request].total_size_received += data_received;
874 
875 #if !defined(WINDOWS)
876  if (gettimeofday (&tp, NULL) == 0)
877  {
878  current_time = tp.tv_sec * 1000000LL + tp.tv_usec;
881  }
882 #endif /* !WINDOWS */
883 }
884 
885 /*
886  * net_client_request_no_reply -
887  *
888  * return:
889  *
890  * request(in): server request id
891  * argbuf(in): argument buffer (small)
892  * argsize(in): byte size of argbuf
893  *
894  */
895 int
896 net_client_request_no_reply (int request, char *argbuf, int argsize)
897 {
898  unsigned int rc;
899  int error;
900 
901  error = NO_ERROR;
902 
904 
905  if (net_Server_name[0] == '\0')
906  {
907  /* need to have a more appropriate "unexpected disconnect" message */
909  error = -1;
910  return error;
911  }
912 
913 #if defined(HISTO)
914  if (net_Histo_setup)
915  {
916  net_histo_add_entry (request, argsize);
917  }
918 #endif /* HISTO */
919 
920  rc = css_send_req_to_server_no_reply (net_Server_host, request, argbuf, argsize);
921  if (rc == 0)
922  {
923  error = css_Errno;
924  return set_server_error (error);
925  }
926 
927  return error;
928 }
929 
930 /*
931  * net_client_get_server_host () - the name of the current sever host machine
932  *
933  * return: string
934  */
935 char *
937 {
938  return net_Server_host;
939 }
940 
941 /*
942  * net_client_request_internal -
943  *
944  * return: error status
945  *
946  * request(in): server request id
947  * argbuf(in): argument buffer (small)
948  * argsize(in): byte size of argbuf
949  * replybuf(in): reply argument buffer (small)
950  * replysize(in): size of reply argument buffer
951  * databuf(in): data buffer to send (large)
952  * datasize(in): size of data buffer
953  * replydata(in): receive data buffer (large)
954  * replydatasize(in): size of expected reply data
955  *
956  * Note: This is one of two functions that is called to perform a server
957  * request. All network interface routines will call either this
958  * function or net_client_request2.
959  */
960 static int
961 net_client_request_internal (int request, char *argbuf, int argsize, char *replybuf, int replysize, char *databuf,
962  int datasize, char *replydata, int replydatasize)
963 {
964  unsigned int rc;
965  int size;
966  int error;
967  char *reply = NULL;
968 
969  error = 0;
970 
971  if (net_Server_name[0] == '\0')
972  {
973  /* need to have a more appropriate "unexpected disconnect" message */
975  error = -1;
976  return error;
977  }
978 
979 #if defined(HISTO)
980  if (net_Histo_setup)
981  {
982  net_histo_add_entry (request, argsize + datasize);
983  }
984 #endif /* HISTO */
985 
986  rc = css_send_req_to_server (net_Server_host, request, argbuf, argsize, databuf, datasize, replybuf, replysize);
987  if (rc == 0)
988  {
989  error = css_Errno;
990  return set_server_error (error);
991  }
992 
993  if (rc)
994  {
995  if (replydata != NULL)
996  {
997  css_queue_receive_data_buffer (rc, replydata, replydatasize);
998  }
999  error = css_receive_data_from_server (rc, &reply, &size);
1000  if (error != NO_ERROR)
1001  {
1002  COMPARE_AND_FREE_BUFFER (replybuf, reply);
1003  return set_server_error (error);
1004  }
1005  else
1006  {
1007  error = COMPARE_SIZE_AND_BUFFER (&replysize, size, &replybuf, reply);
1008  }
1009 
1010  if (replydata != NULL)
1011  {
1012  error = css_receive_data_from_server (rc, &reply, &size);
1013  if (error != NO_ERROR)
1014  {
1015  COMPARE_AND_FREE_BUFFER (replydata, reply);
1016  return set_server_error (error);
1017  }
1018  else
1019  {
1020  error = COMPARE_SIZE_AND_BUFFER (&replydatasize, size, &replydata, reply);
1021  }
1022  }
1023  }
1024 #if defined(HISTO)
1025  if (net_Histo_setup)
1026  {
1027  net_histo_request_finished (request, replysize + replydatasize);
1028  }
1029 #endif /* HISTO */
1030  return error;
1031 }
1032 
1033 /*
1034  * net_client_request -
1035  *
1036  * return: error status
1037  *
1038  * request(in): server request id
1039  * argbuf(in): argument buffer (small)
1040  * argsize(in): byte size of argbuf
1041  * replybuf(in): reply argument buffer (small)
1042  * replysize(in): size of reply argument buffer
1043  * databuf(in): data buffer to send (large)
1044  * datasize(in): size of data buffer
1045  * replydata(in): receive data buffer (large)
1046  * replydatasize(in): size of expected reply data
1047  *
1048  * Note: This is one of two functions that is called to perform a server
1049  * request. All network interface routines will call either this
1050  * function or net_client_request2.
1051  */
1052 int
1053 net_client_request (int request, char *argbuf, int argsize, char *replybuf, int replysize, char *databuf, int datasize,
1054  char *replydata, int replydatasize)
1055 {
1056  return (net_client_request_internal (request, argbuf, argsize, replybuf, replysize, databuf, datasize, replydata,
1057  replydatasize));
1058 }
1059 
1060 #if defined(ENABLE_UNUSED_FUNCTION)
1061 /*
1062  * net_client_request_send_large_data -
1063  *
1064  * return: error status
1065  *
1066  * request(in): server request id
1067  * argbuf(in): argument buffer (small)
1068  * argsize(in): byte size of argbuf
1069  * replybuf(in): reply argument buffer (small)
1070  * replysize(in): size of reply argument buffer
1071  * databuf(in): data buffer to send (large)
1072  * datasize(in): size of data buffer
1073  * replydata(in): receive data buffer (large)
1074  * replydatasize(in): size of expected reply data
1075  *
1076  * Note: This is one of two functions that is called to perform a server
1077  * request. All network interface routines will call either this
1078  * function or net_client_request2.
1079  */
1080 int
1081 net_client_request_send_large_data (int request, char *argbuf, int argsize, char *replybuf, int replysize,
1082  char *databuf, INT64 datasize, char *replydata, int replydatasize)
1083 {
1084  unsigned int rc;
1085  int size;
1086  int error;
1087  char *reply = NULL;
1088 
1089  error = 0;
1090 
1091  if (net_Server_name[0] == '\0')
1092  {
1093  /* need to have a more appropriate "unexpected disconnect" message */
1095  error = -1;
1096  return error;
1097  }
1098 
1099 #if defined(HISTO)
1100  if (net_Histo_setup)
1101  {
1102  net_histo_add_entry (request, argsize + datasize);
1103  }
1104 #endif /* HISTO */
1105 
1106  rc = css_send_req_to_server_with_large_data (net_Server_host, request, argbuf, argsize, databuf, datasize, replybuf,
1107  replysize);
1108 
1109  if (rc == 0)
1110  {
1111  error = css_Errno;
1112  return set_server_error (error);
1113  }
1114 
1115  if (rc)
1116  {
1117  if (replydata != NULL)
1118  {
1119  css_queue_receive_data_buffer (rc, replydata, replydatasize);
1120  }
1121  error = css_receive_data_from_server (rc, &reply, &size);
1122  if (error != NO_ERROR)
1123  {
1124  COMPARE_AND_FREE_BUFFER (replybuf, reply);
1125  return set_server_error (error);
1126  }
1127  else
1128  {
1129  error = COMPARE_SIZE_AND_BUFFER (&replysize, size, &replybuf, reply);
1130  }
1131 
1132  if (replydata != NULL)
1133  {
1134  error = css_receive_data_from_server (rc, &reply, &size);
1135  if (error != NO_ERROR)
1136  {
1137  COMPARE_AND_FREE_BUFFER (replydata, reply);
1138  return set_server_error (error);
1139  }
1140  else
1141  {
1142  error = COMPARE_SIZE_AND_BUFFER (&replydatasize, size, &replydata, reply);
1143  }
1144  }
1145  }
1146 #if defined(HISTO)
1147  if (net_Histo_setup)
1148  {
1149  net_histo_request_finished (request, replysize + replydatasize);
1150  }
1151 #endif /* HISTO */
1152  return error;
1153 }
1154 
1155 /*
1156  * net_client_request_recv_large_data -
1157  *
1158  * return: error status
1159  *
1160  * request(in): server request id
1161  * argbuf(in): argument buffer (small)
1162  * argsize(in): byte size of argbuf
1163  * replybuf(in): reply argument buffer (small)
1164  * replysize(in): size of reply argument buffer
1165  * databuf(in): data buffer to send (large)
1166  * datasize(in): size of data buffer
1167  * replydata(in): receive data buffer (large)
1168  * replydatasize_ptr(in): size of expected reply data
1169  *
1170  * Note:
1171  */
1172 int
1173 net_client_request_recv_large_data (int request, char *argbuf, int argsize, char *replybuf, int replysize,
1174  char *databuf, int datasize, char *replydata, INT64 * replydatasize_ptr)
1175 {
1176  unsigned int rc;
1177  int size;
1178  int error;
1179  INT64 reply_datasize;
1180  int num_data;
1181  char *reply = NULL, *ptr, *packed_desc;
1182  int i, packed_desc_size;
1183 
1184  error = 0;
1185  *replydatasize_ptr = 0;
1186 
1187  if (net_Server_name[0] == '\0')
1188  {
1189  /* need to have a more appropriate "unexpected disconnect" message */
1191  error = -1;
1192  }
1193  else
1194  {
1195 #if defined(HISTO)
1196  if (net_Histo_setup)
1197  {
1198  net_histo_add_entry (request, argsize + datasize);
1199  }
1200 #endif /* HISTO */
1201  rc = css_send_req_to_server (net_Server_host, request, argbuf, argsize, databuf, datasize, replybuf, replysize);
1202  if (rc == 0)
1203  {
1204  return set_server_error (css_Errno);
1205  }
1206 
1207  error = css_receive_data_from_server (rc, &reply, &size);
1208 
1209  if (error != NO_ERROR || reply == NULL)
1210  {
1211  COMPARE_AND_FREE_BUFFER (replybuf, reply);
1212  return set_server_error (error);
1213  }
1214  else
1215  {
1216  error = COMPARE_SIZE_AND_BUFFER (&replysize, size, &replybuf, reply);
1217  }
1218 
1219  /* here we assume that the first integer in the reply is the length of the following data block */
1220  ptr = or_unpack_int64 (reply, &reply_datasize);
1221  num_data = (int) (reply_datasize / INT_MAX + 1);
1222 
1223  if (reply_datasize)
1224  {
1225  for (i = 0; i < num_data; i++)
1226  {
1227  packed_desc_size = MIN ((int) reply_datasize, INT_MAX);
1228 
1229  packed_desc = (char *) malloc (packed_desc_size);
1230  if (packed_desc == NULL)
1231  {
1233  }
1234  css_queue_receive_data_buffer (rc, packed_desc, packed_desc_size);
1235  error = css_receive_data_from_server (rc, &reply, &size);
1236  if (error != NO_ERROR || reply == NULL)
1237  {
1238  COMPARE_AND_FREE_BUFFER (packed_desc, reply);
1239  free_and_init (packed_desc);
1240  return set_server_error (error);
1241  }
1242  else
1243  {
1244  memcpy (replydata, reply, size);
1245  COMPARE_AND_FREE_BUFFER (packed_desc, reply);
1246  free_and_init (packed_desc);
1247  }
1248  *replydatasize_ptr += size;
1249  reply_datasize -= size;
1250  replydata += size;
1251  }
1252  }
1253 
1254 #if defined(HISTO)
1255  if (net_Histo_setup)
1256  {
1257  net_histo_request_finished (request, replysize + *replydatasize_ptr);
1258  }
1259 #endif /* HISTO */
1260  }
1261  return error;
1262 }
1263 #endif /* ENABLE_UNUSED_FUNCTION */
1264 
1265 /*
1266  * net_client_request2 -
1267  *
1268  * return: error status
1269  *
1270  * request(in): server request id
1271  * argbuf(in): argument buffer (small)
1272  * argsize(in): byte size of argbuf
1273  * replybuf(in): reply argument buffer (small)
1274  * replysize(in): size of reply argument buffer
1275  * databuf(in): data buffer to send (large)
1276  * datasize(in): size of data buffer
1277  * replydata_ptr(in): receive data buffer (large)
1278  * replydatasize_ptr(in): size of expected reply data
1279  *
1280  * Note: This is one of two functions that is called to perform a server
1281  * request. All network interface routines will call either this
1282  * functino or net_client_request.
1283  * This is similar to net_client_request but the size of the reply
1284  * data buffer is not known and must be determined from the first
1285  * field in the reply argument buffer.
1286  */
1287 int
1288 net_client_request2 (int request, char *argbuf, int argsize, char *replybuf, int replysize, char *databuf, int datasize,
1289  char **replydata_ptr, int *replydatasize_ptr)
1290 {
1291  unsigned int rc;
1292  int size;
1293  int reply_datasize, error;
1294  char *reply = NULL, *replydata;
1295 
1296  error = 0;
1297  *replydata_ptr = NULL;
1298  *replydatasize_ptr = 0;
1299 
1300  if (net_Server_name[0] == '\0')
1301  {
1302  /* need to have a more appropriate "unexpected disconnect" message */
1304  error = -1;
1305  return error;
1306  }
1307 #if defined(HISTO)
1308  if (net_Histo_setup)
1309  {
1310  net_histo_add_entry (request, argsize + datasize);
1311  }
1312 #endif /* HISTO */
1313  rc = css_send_req_to_server (net_Server_host, request, argbuf, argsize, databuf, datasize, replybuf, replysize);
1314  if (rc == 0)
1315  {
1316  error = css_Errno;
1317  return set_server_error (error);
1318  }
1319 
1320  error = css_receive_data_from_server (rc, &reply, &size);
1321 
1322  if (error != NO_ERROR || reply == NULL)
1323  {
1324  COMPARE_AND_FREE_BUFFER (replybuf, reply);
1325  return set_server_error (error);
1326  }
1327  else
1328  {
1329  error = COMPARE_SIZE_AND_BUFFER (&replysize, size, &replybuf, reply);
1330  }
1331 
1332  /* here we assume that the first integer in the reply is the length of the following data block */
1333  or_unpack_int (reply, &reply_datasize);
1334 
1335  if (reply_datasize)
1336  {
1337  if ((error == NO_ERROR) && (replydata = (char *) malloc (reply_datasize)) != NULL)
1338  {
1339  css_queue_receive_data_buffer (rc, replydata, reply_datasize);
1340  error = css_receive_data_from_server (rc, &reply, &size);
1341 
1342  if (error != NO_ERROR)
1343  {
1344  COMPARE_AND_FREE_BUFFER (replydata, reply);
1345  free_and_init (replydata);
1346  return set_server_error (error);
1347  }
1348  else
1349  {
1350  error = COMPARE_SIZE_AND_BUFFER (&reply_datasize, size, &replydata, reply);
1351  }
1352  *replydata_ptr = reply;
1353  *replydatasize_ptr = size;
1354  }
1355  else
1356  {
1358 
1360  }
1361  }
1362 
1363 #if defined(HISTO)
1364  if (net_Histo_setup)
1365  {
1366  net_histo_request_finished (request, replysize + *replydatasize_ptr);
1367  }
1368 #endif /* HISTO */
1369  return error;
1370 }
1371 
1372 /*
1373  * net_client_request2_no_malloc -
1374  *
1375  * return: error status
1376  *
1377  * request(in): server request id
1378  * argbuf(in): argument buffer (small)
1379  * argsize(in): byte size of argbuf
1380  * replybuf(in): reply argument buffer (small)
1381  * replysize(in): size of reply argument buffer
1382  * databuf(in): data buffer to send (large)
1383  * datasize(in): size of data buffer
1384  * replydata(in): receive data buffer (large)
1385  * replydatasize_ptr(in): size of expected reply data
1386  *
1387  * Note: This is one of two functions that is called to perform a server
1388  * request. All network interface routines will call either this
1389  * functino or net_client_request.
1390  * This is similar to net_client_request but the size of the reply
1391  * data buffer is not known and must be determined from the first
1392  * field in the reply argument buffer.
1393  */
1394 int
1395 net_client_request2_no_malloc (int request, char *argbuf, int argsize, char *replybuf, int replysize, char *databuf,
1396  int datasize, char *replydata, int *replydatasize_ptr)
1397 {
1398  unsigned int rc;
1399  int size;
1400  int reply_datasize, error;
1401  char *reply = NULL;
1402 
1403  error = 0;
1404  *replydatasize_ptr = 0;
1405 
1406  if (net_Server_name[0] == '\0')
1407  {
1408  /* need to have a more appropriate "unexpected disconnect" message */
1410  error = -1;
1411  }
1412  else
1413  {
1414 #if defined(HISTO)
1415  if (net_Histo_setup)
1416  {
1417  net_histo_add_entry (request, argsize + datasize);
1418  }
1419 #endif /* HISTO */
1420  rc = css_send_req_to_server (net_Server_host, request, argbuf, argsize, databuf, datasize, replybuf, replysize);
1421  if (rc == 0)
1422  {
1423  return set_server_error (css_Errno);
1424  }
1425 
1426  error = css_receive_data_from_server (rc, &reply, &size);
1427 
1428  if (error != NO_ERROR || reply == NULL)
1429  {
1430  COMPARE_AND_FREE_BUFFER (replybuf, reply);
1431  return set_server_error (error);
1432  }
1433  else
1434  {
1435  error = COMPARE_SIZE_AND_BUFFER (&replysize, size, &replybuf, reply);
1436  }
1437 
1438  /* here we assume that the first integer in the reply is the length of the following data block */
1439  or_unpack_int (reply, &reply_datasize);
1440 
1441  if (reply_datasize > 0)
1442  {
1443  css_queue_receive_data_buffer (rc, replydata, reply_datasize);
1444  error = css_receive_data_from_server (rc, &reply, &size);
1445  if (error != NO_ERROR)
1446  {
1447  COMPARE_AND_FREE_BUFFER (replydata, reply);
1448  return set_server_error (error);
1449  }
1450  else
1451  {
1452  error = COMPARE_SIZE_AND_BUFFER (&reply_datasize, size, &replydata, reply);
1453  }
1454  *replydatasize_ptr = size;
1455  }
1456 #if defined(HISTO)
1457  if (net_Histo_setup)
1458  {
1459  net_histo_request_finished (request, replysize + *replydatasize_ptr);
1460  }
1461 #endif /* HISTO */
1462  }
1463  return error;
1464 }
1465 
1466 /*
1467  * net_client_request_3_data -
1468  *
1469  * return: error status (0 = success, non-zero = error)
1470  *
1471  * request(in): server request id
1472  * argbuf(in): argument buffer (small)
1473  * argsize(in): byte size of argbuf
1474  * databuf1(in): first data buffer to send
1475  * datasize1(in): size of first data buffer
1476  * databuf2(in): second data buffer to send
1477  * datasize2(in): size of second data buffer
1478  * reply0(in): first reply argument buffer (small)
1479  * replysize0(in): size of first reply argument buffer
1480  * reply1(in): second reply argument buffer
1481  * replysize1(in): size of second reply argument buffer
1482  * reply2(in): third reply argument buffer
1483  * replysize2(in): size of third reply argument buffer
1484  *
1485  * Note: This is one of two functions that is called to perform a server
1486  * request. All network interface routines will call either this
1487  * functino or net_client_request2.
1488  */
1489 int
1490 net_client_request_3_data (int request, char *argbuf, int argsize, char *databuf1, int datasize1, char *databuf2,
1491  int datasize2, char *reply0, int replysize0, char *reply1, int replysize1, char *reply2,
1492  int replysize2)
1493 {
1494  unsigned int rid;
1495  int rc;
1496  int size;
1497  int p1_size, p2_size, error;
1498  char *reply = NULL, *ptr = NULL;
1499 
1500  error = rc = 0;
1501 
1502  if (net_Server_name[0] == '\0')
1503  {
1504  /* need to have a more appropriate "unexpected disconnect" message */
1505  rc = ER_NET_SERVER_CRASHED;
1507  }
1508  else
1509  {
1510 #if defined(HISTO)
1511  if (net_Histo_setup)
1512  {
1513  net_histo_add_entry (request, argsize + datasize1 + datasize2);
1514  }
1515 #endif /* HISTO */
1516  rid = css_send_req_to_server_2_data (net_Server_host, request, argbuf, argsize, databuf1, datasize1, databuf2,
1517  datasize2, NULL, 0);
1518  if (rid == 0)
1519  {
1520  return set_server_error (css_Errno);
1521  }
1522 
1523  css_queue_receive_data_buffer (rid, reply0, replysize0);
1524  error = css_receive_data_from_server (rid, &reply, &size);
1525  if (error != NO_ERROR || reply == NULL)
1526  {
1527  COMPARE_AND_FREE_BUFFER (reply0, reply);
1528  return set_server_error (error);
1529  }
1530  else
1531  {
1532  /* Ignore this error status here, since the caller must check it */
1533  ptr = or_unpack_int (reply0, &error);
1534  ptr = or_unpack_int (ptr, &p1_size);
1535  (void) or_unpack_int (ptr, &p2_size);
1536 
1537  if (p1_size == 0)
1538  {
1539  COMPARE_AND_FREE_BUFFER (reply0, reply);
1540  return rc;
1541  }
1542 
1543  css_queue_receive_data_buffer (rid, reply1, p1_size);
1544  if (p2_size > 0)
1545  {
1546  css_queue_receive_data_buffer (rid, reply2, p2_size);
1547  }
1548  error = css_receive_data_from_server (rid, &reply, &size);
1549  if (error != NO_ERROR)
1550  {
1551  COMPARE_AND_FREE_BUFFER (reply1, reply);
1552  return set_server_error (error);
1553  }
1554  else
1555  {
1556  error = COMPARE_SIZE_AND_BUFFER (&replysize1, size, &reply1, reply);
1557  }
1558 
1559  if (p2_size > 0)
1560  {
1561  error = css_receive_data_from_server (rid, &reply, &size);
1562  if (error != NO_ERROR)
1563  {
1564  COMPARE_AND_FREE_BUFFER (reply2, reply);
1565  return set_server_error (error);
1566  }
1567  else
1568  {
1569  error = COMPARE_SIZE_AND_BUFFER (&replysize2, size, &reply2, reply);
1570  }
1571  }
1572  }
1573 #if defined(HISTO)
1574  if (net_Histo_setup)
1575  {
1576  net_histo_request_finished (request, replysize1 + replysize2);
1577  }
1578 #endif /* HISTO */
1579  }
1580  return rc;
1581 }
1582 
1583 /*
1584  * net_client_request_with_callback -
1585  *
1586  * return: error status
1587  *
1588  * request(in): server request id
1589  * argbuf(in): argument buffer (small)
1590  * argsize(in): byte size of argbuf
1591  * replybuf(in): reply argument buffer (small)
1592  * replysize(in): size of reply argument buffer
1593  * databuf1(in): first data buffer to send (large)
1594  * datasize1(in): size of first data buffer
1595  * databuf2(in): second data buffer to send (large)
1596  * datasize2(in): size of second data buffer
1597  * replydata_ptr1(in): first receive data buffer (large)
1598  * replydatasize_ptr1(in): size of first expected reply data
1599  * replydata_ptr2(in): second receive data buffer (large)
1600  * replydatasize_ptr2(in): size of second expected reply data
1601  *
1602  * Note: This is one of the functions that is called to perform a server request.
1603  * This is similar to net_client_request2, but the first
1604  * field in the reply argument buffer is a request code which can
1605  * cause the client to perform actions such as call methods. When
1606  * the actions are completed, a reply is sent to the server. Eventually
1607  * the server responds to the original request with a request code
1608  * that indicates that the request is complete and this routine returns.
1609  */
1610 int
1611 net_client_request_with_callback (int request, char *argbuf, int argsize, char *replybuf, int replysize, char *databuf1,
1612  int datasize1, char *databuf2, int datasize2, char **replydata_listid,
1613  int *replydatasize_listid, char **replydata_page, int *replydatasize_page,
1614  char **replydata_plan, int *replydatasize_plan)
1615 {
1616  unsigned int rc;
1617  int size, error;
1618  int reply_datasize_listid, reply_datasize_page, reply_datasize_plan, remaining_size;
1619  char *reply = NULL, *replydata, *ptr;
1620  QUERY_SERVER_REQUEST server_request;
1621  int server_request_num;
1622 
1623  error = NO_ERROR;
1624  *replydata_listid = NULL;
1625  *replydata_page = NULL;
1626  if (replydata_plan != NULL)
1627  {
1628  *replydata_plan = NULL;
1629  }
1630 
1631  *replydatasize_listid = 0;
1632  *replydatasize_page = 0;
1633 
1634  if (replydatasize_plan != NULL)
1635  {
1636  *replydatasize_plan = 0;
1637  }
1638 
1639  if (net_Server_name[0] == '\0')
1640  {
1641  /* need to have a more appropriate "unexpected disconnect" message */
1643  error = -1;
1644  }
1645  else
1646  {
1647 #if defined(HISTO)
1648  if (net_Histo_setup)
1649  {
1650  net_histo_add_entry (request, argsize + datasize1 + datasize2);
1651  }
1652 #endif /* HISTO */
1653  rc = css_send_req_to_server_2_data (net_Server_host, request, argbuf, argsize, databuf1, datasize1, databuf2,
1654  datasize2, replybuf, replysize);
1655  if (rc == 0)
1656  {
1657  return set_server_error (css_Errno);
1658  }
1659 
1660  do
1661  {
1662  error = css_receive_data_from_server (rc, &reply, &size);
1663  if (error != NO_ERROR || reply == NULL)
1664  {
1665  COMPARE_AND_FREE_BUFFER (replybuf, reply);
1666  return set_server_error (error);
1667  }
1668 #if 0
1669  else
1670  {
1671  error = COMPARE_SIZE_AND_BUFFER (&replysize, size, &replybuf, reply);
1672  }
1673 #endif
1674 
1675  ptr = or_unpack_int (reply, &server_request_num);
1676  server_request = (QUERY_SERVER_REQUEST) server_request_num;
1677 
1678  switch (server_request)
1679  {
1680  case QUERY_END:
1681  /* here we assume that the first integer in the reply is the length of the following data block */
1682  ptr = or_unpack_int (ptr, &reply_datasize_listid);
1683  ptr = or_unpack_int (ptr, &reply_datasize_page);
1684  ptr = or_unpack_int (ptr, &reply_datasize_plan);
1685  COMPARE_AND_FREE_BUFFER (replybuf, reply);
1686 
1687  remaining_size = reply_datasize_listid + reply_datasize_page + reply_datasize_plan;
1688 
1689  // 1. Read list_id
1690  if (0 < remaining_size)
1691  {
1692  if (0 < reply_datasize_listid)
1693  {
1694  if ((error == NO_ERROR) && (replydata = (char *) malloc (reply_datasize_listid)) != NULL)
1695  {
1696  css_queue_receive_data_buffer (rc, replydata, reply_datasize_listid);
1697 
1698  error = css_receive_data_from_server (rc, &reply, &size);
1699  if (error != NO_ERROR)
1700  {
1701  COMPARE_AND_FREE_BUFFER (replydata, reply);
1702  free_and_init (replydata);
1703  return set_server_error (error);
1704  }
1705 
1706  error = COMPARE_SIZE_AND_BUFFER (&reply_datasize_listid, size, &replydata, reply);
1707 
1708  *replydata_listid = reply;
1709  *replydatasize_listid = size;
1710 
1711  reply = NULL;
1712  }
1713  else
1714  {
1716 
1718  }
1719  }
1720  else
1721  {
1722  // Even though its size is 0, it should also be consumed.
1723  assert (reply_datasize_listid == 0);
1725  }
1726 
1727  remaining_size -= reply_datasize_listid;
1728  }
1729 
1730  // 2. Read page if exists
1731  //
1732  // Note that not all list files have a page. list file for insert may not have one.
1733  if (0 < remaining_size)
1734  {
1735  if (0 < reply_datasize_page)
1736  {
1737  if ((error == NO_ERROR) && (replydata = (char *) malloc (DB_PAGESIZE)) != NULL)
1738  {
1739  css_queue_receive_data_buffer (rc, replydata, reply_datasize_page);
1740 
1741  error = css_receive_data_from_server (rc, &reply, &size);
1742  if (error != NO_ERROR)
1743  {
1744  COMPARE_AND_FREE_BUFFER (replydata, reply);
1745  free_and_init (replydata);
1746  return set_server_error (error);
1747  }
1748 
1749  error = COMPARE_SIZE_AND_BUFFER (&reply_datasize_page, size, &replydata, reply);
1750 
1751  *replydata_page = reply;
1752  *replydatasize_page = size;
1753 
1754  reply = NULL;
1755  }
1756  else
1757  {
1759 
1761  }
1762  }
1763  else
1764  {
1765  // Even though its size is 0, it should also be consumed.
1766  assert (reply_datasize_page == 0);
1768  }
1769 
1770  remaining_size -= reply_datasize_page;
1771  }
1772 
1773  // 3. Read plan if exists
1774  if (0 < remaining_size)
1775  {
1776  if (0 < reply_datasize_plan)
1777  {
1778  if ((error == NO_ERROR) && (replydata = (char *) malloc (reply_datasize_plan + 1)) != NULL)
1779  {
1780  css_queue_receive_data_buffer (rc, replydata, reply_datasize_plan);
1781 
1782  error = css_receive_data_from_server (rc, &reply, &size);
1783  if (error != NO_ERROR)
1784  {
1785  COMPARE_AND_FREE_BUFFER (replydata, reply);
1786  free_and_init (replydata);
1787  return set_server_error (error);
1788  }
1789 
1790  error = COMPARE_SIZE_AND_BUFFER (&reply_datasize_plan, size, &replydata, reply);
1791 
1792  if (replydata_plan != NULL)
1793  {
1794  *replydata_plan = reply;
1795  }
1796 
1797  if (replydatasize_plan != NULL)
1798  {
1799  *replydatasize_plan = size;
1800  }
1801 
1802  reply = NULL;
1803  }
1804  else
1805  {
1807 
1809  }
1810  }
1811  else
1812  {
1813  // When you want to append a reply argument,
1814  // you should remove the assertion and handle zero-size case.
1815  assert (0 < reply_datasize_plan);
1816  }
1817 
1818  remaining_size -= reply_datasize_plan;
1819  }
1820 
1821  assert (remaining_size == 0);
1822  break;
1823 
1824  case METHOD_CALL:
1825  {
1826  char *methoddata;
1827  int methoddata_size;
1828  QFILE_LIST_ID *method_call_list_id = (QFILE_LIST_ID *) 0;
1829  METHOD_SIG_LIST *method_call_sig_list = (METHOD_SIG_LIST *) 0;
1830 
1831  er_clear ();
1832  error = NO_ERROR;
1833  /* here we assume that the first integer in the reply is the length of the following data block */
1834  or_unpack_int (ptr, &methoddata_size);
1835  COMPARE_AND_FREE_BUFFER (replybuf, reply);
1836 
1837  methoddata = (char *) malloc (methoddata_size);
1838  if (methoddata != NULL)
1839  {
1840  css_queue_receive_data_buffer (rc, methoddata, methoddata_size);
1841  error = css_receive_data_from_server (rc, &reply, &size);
1842  if (error != NO_ERROR)
1843  {
1844  COMPARE_AND_FREE_BUFFER (methoddata, reply);
1845  free_and_init (methoddata);
1846  return set_server_error (error);
1847  }
1848  else
1849  {
1850 #if defined(CS_MODE)
1851  bool need_to_reset = false;
1852  if (method_request_id == 0)
1853  {
1854  method_request_id = CSS_RID_FROM_EID (rc);
1855  need_to_reset = true;
1856  }
1857 #endif /* CS_MODE */
1858  error = COMPARE_SIZE_AND_BUFFER (&methoddata_size, size, &methoddata, reply);
1859  ptr = or_unpack_unbound_listid (methoddata, (void **) &method_call_list_id);
1860  method_call_list_id->last_pgptr = NULL;
1861  ptr = or_unpack_method_sig_list (ptr, (void **) &method_call_sig_list);
1862 
1863  COMPARE_AND_FREE_BUFFER (methoddata, reply);
1864  free_and_init (methoddata);
1865 
1866  error =
1867  method_invoke_for_server (rc, net_Server_host, net_Server_name, method_call_list_id,
1868  method_call_sig_list);
1869  cursor_free_self_list_id (method_call_list_id);
1870  method_sig_list_freemem (method_call_sig_list);
1871  if (error != NO_ERROR)
1872  {
1873  assert (er_errid () != NO_ERROR);
1874  error = er_errid ();
1875  if (error == NO_ERROR)
1876  {
1878  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, error, 0);
1879  }
1880  }
1881  else
1882  {
1883  error = NO_ERROR;
1884  }
1885 #if defined(CS_MODE)
1886  if (need_to_reset == true)
1887  {
1888  method_request_id = 0;
1889  need_to_reset = false;
1890  }
1891 #endif /* CS_MODE */
1892  }
1893  }
1894  else
1895  {
1897 
1899  }
1900 
1901  if (error != NO_ERROR)
1902  {
1905  }
1906  css_queue_receive_data_buffer (rc, replybuf, replysize);
1907  }
1908  break;
1909 
1910  /*
1911  * A code of END_CALLBACK is followed immediately by an
1912  * integer returning status from the remote call. The second
1913  * integer represents the return value and must be returned
1914  * to the calling function.
1915  */
1916  case END_CALLBACK:
1917  /* The calling function will have to ignore this value in the reply buffer. */
1918  error = NO_ERROR;
1919  break;
1920 
1922  {
1923  FILEIO_REMOTE_PROMPT_TYPE prompt_id;
1924  int length;
1925  char *promptdata = NULL;
1926  char user_response_buffer[FILEIO_MAX_USER_RESPONSE_SIZE + 1];
1927  char *user_response_ptr = user_response_buffer;
1928  int pr_status = ER_FAILED;
1929  int pr_len = 0;
1930  bool response_needed = false;
1931  bool retry_in = true;
1932  int x;
1933  /* The following variables are need to decode the data packet */
1934  char *display_string;
1935  char *prompt = NULL;
1936  char *failure_prompt = NULL;
1937  char *secondary_prompt = NULL;
1938  int range_lower, range_higher;
1939  int reprompt_value;
1940  int error2;
1941  int result = 0;
1942  char *a_ptr;
1943 
1944  ptr = or_unpack_int (ptr, &x);
1945  prompt_id = (FILEIO_REMOTE_PROMPT_TYPE) x;
1946 
1947  ptr = or_unpack_int (ptr, &length);
1948  COMPARE_AND_FREE_BUFFER (replybuf, reply);
1949 
1950  promptdata = (char *) malloc (MAX (length, FILEIO_MAX_USER_RESPONSE_SIZE + OR_INT_SIZE));
1951  if (promptdata != NULL)
1952  {
1953  css_queue_receive_data_buffer (rc, promptdata, length);
1954  error = css_receive_data_from_server (rc, &reply, &length);
1955  if (error != NO_ERROR || reply == NULL)
1956  {
1957  server_request = END_CALLBACK;
1958  COMPARE_AND_FREE_BUFFER (promptdata, reply);
1959  free_and_init (promptdata);
1960  return set_server_error (error);
1961  }
1962  else
1963  {
1964  ptr = or_unpack_string_nocopy (reply, &prompt);
1965  /*
1966  * the following data are used depending on prompt type
1967  * but will always be in the input stream
1968  */
1969  ptr = or_unpack_string_nocopy (ptr, &failure_prompt);
1970  ptr = or_unpack_int (ptr, &range_lower);
1971  ptr = or_unpack_int (ptr, &range_higher);
1972  ptr = or_unpack_string_nocopy (ptr, &secondary_prompt);
1973  ptr = or_unpack_int (ptr, &reprompt_value);
1974  }
1975 
1976  display_string = prompt;
1977 
1978  memset (user_response_buffer, 0, sizeof (user_response_buffer));
1979 
1980  while (error == NO_ERROR && retry_in)
1981  {
1982  /* Display prompt, then get user's input. */
1983  fprintf (stdout, display_string);
1984  pr_status = ER_FAILED;
1985  pr_len = 0;
1986  retry_in = false;
1987 
1988  if (prompt_id != FILEIO_PROMPT_DISPLAY_ONLY)
1989  {
1990  error2 = scanf ("%2000s", user_response_ptr);
1991  if (error2 > 0)
1992  {
1993  /* basic input int validation before we send it back */
1994  switch (prompt_id)
1995  {
1997  /* Numeric range checking */
1998  result = str_to_int32 (&x, &a_ptr, user_response_ptr, 10);
1999  if (result != 0 || x < range_lower || x > range_higher)
2000  {
2001  fprintf (stdout, failure_prompt);
2002  retry_in = true;
2003  }
2004  else
2005  {
2006  response_needed = true;
2007  pr_status = NO_ERROR;
2008  }
2009  break;
2010 
2011  /*
2012  * simply boolean (y, yes, 1, n, no, 0)
2013  * validation
2014  */
2016  if ((char_tolower (*user_response_ptr) == 'y') || (*user_response_ptr == '1')
2017  || (intl_mbs_casecmp (user_response_ptr, "yes") == 0))
2018  {
2019  response_needed = true;
2020  pr_status = NO_ERROR;
2021  /* convert all affirmate answers into '1' */
2022  strcpy (user_response_ptr, "1");
2023  }
2024  else
2025  {
2026  /* assume negative */
2027  response_needed = true;
2028  pr_status = NO_ERROR;
2029  /* convert all negative answers into '0' */
2030  strcpy (user_response_ptr, "0");
2031  }
2032  break;
2033 
2034  /* no validation to do */
2036  response_needed = true;
2037  pr_status = NO_ERROR;
2038  break;
2039 
2040  /* Validate initial prompt, then post secondary prompt */
2042  /* Numeric range checking on the first promp, but user's answer we really want is
2043  * the second prompt */
2044  result = str_to_int32 (&x, &a_ptr, user_response_ptr, 10);
2045  if (result != 0 || x < range_lower || x > range_higher)
2046  {
2047  fprintf (stdout, failure_prompt);
2048  retry_in = true;
2049  }
2050  else if (x == reprompt_value)
2051  {
2052  /* The first answer requires another prompt */
2053  display_string = secondary_prompt;
2054  retry_in = true;
2055  prompt_id = FILEIO_PROMPT_STRING_TYPE;
2056  /* moving the response buffer ptr forward insures that both the first response
2057  * and the second are included in the buffer. (no delimiter or null bytes
2058  * allowed) */
2059  user_response_ptr += strlen (user_response_ptr);
2060  }
2061  else
2062  {
2063  /* This answer was sufficient */
2064  response_needed = true;
2065  pr_status = NO_ERROR;
2066  }
2067  break;
2068 
2069  default:
2070  /* should we treat this as an error? */
2071  response_needed = true;
2072  pr_status = NO_ERROR;
2073  }
2074  }
2075  else if (error2 == 0)
2076  {
2077  retry_in = true;
2078  }
2079  else
2080  {
2081  pr_status = ER_FAILED;
2082  }
2083  }
2084  else
2085  {
2086  response_needed = true;
2087  pr_status = NO_ERROR;
2088  }
2089  } /* while */
2090 
2091  /* Return the user's answer to the server. All of the cases above should get to here after looping
2092  * or whatever is necessary and provide indication of local errors (pr_status), as well as provide
2093  * a string in user_response. We send back to the server an int (status) followed by a string. */
2094  /* check for overflow, could be dangerous */
2095  pr_len = (int) strlen (user_response_buffer);
2096  if (pr_len > FILEIO_MAX_USER_RESPONSE_SIZE)
2097  {
2098  error = ER_NET_DATA_TRUNCATED;
2100  pr_status = ER_FAILED;
2101  }
2102 
2103  if (error)
2104  {
2105  pr_status = ER_FAILED;
2106  }
2107 
2108  /* we already malloced large enough buffer, reuse promptdata */
2109  ptr = or_pack_int (promptdata, pr_status);
2110  if (response_needed)
2111  {
2112  ptr = or_pack_string_with_length (ptr, user_response_buffer, pr_len);
2113  }
2114  error2 = net_client_send_data (net_Server_host, rc, promptdata, CAST_STRLEN (ptr - promptdata));
2115  if (error2 != NO_ERROR)
2116  {
2117  /* the error should have already been generated */
2118  server_request = END_CALLBACK;
2119  }
2120  if (error == NO_ERROR && error2 != NO_ERROR)
2121  {
2122  error = error2;
2123  }
2124 
2125  if (error != NO_ERROR)
2126  {
2127  server_request = END_CALLBACK;
2128  /* Do we need to tell the server about it? */
2130  }
2131 
2132  COMPARE_AND_FREE_BUFFER (promptdata, reply);
2133  free_and_init (promptdata);
2134  }
2135  else
2136  {
2137  /* send back some kind of error to server */
2139 
2141 
2142  /* Do we need to tell the server? */
2143  server_request = END_CALLBACK; /* force a stop */
2145  }
2146  }
2147  /* expecting another reply */
2148  css_queue_receive_data_buffer (rc, replybuf, replysize);
2149 
2150  break;
2151 
2152  case CONSOLE_OUTPUT:
2153  {
2154  int length;
2155  char *print_data, *print_str;
2156 
2157  ptr = or_unpack_int (ptr, &length);
2158  ptr = or_unpack_int (ptr, &length);
2159  COMPARE_AND_FREE_BUFFER (replybuf, reply);
2160 
2161  print_data = (char *) malloc (length);
2162  if (print_data != NULL)
2163  {
2164  css_queue_receive_data_buffer (rc, print_data, length);
2165  error = css_receive_data_from_server (rc, &reply, &length);
2166  if (error != NO_ERROR || reply == NULL)
2167  {
2168  server_request = END_CALLBACK;
2169  COMPARE_AND_FREE_BUFFER (print_data, reply);
2170  free_and_init (print_data);
2171  return set_server_error (error);
2172  }
2173  else
2174  {
2175  ptr = or_unpack_string_nocopy (reply, &print_str);
2176  fprintf (stdout, print_str);
2177  fflush (stdout);
2178  }
2179  free_and_init (print_data);
2180  }
2181  }
2182 
2183  /* expecting another reply */
2184  css_queue_receive_data_buffer (rc, replybuf, replysize);
2185 
2186  error = NO_ERROR;
2187  break;
2188 
2189  default:
2191  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, error, 0);
2192  server_request = QUERY_END;
2193  break;
2194  }
2195  }
2196  while (server_request != END_CALLBACK && server_request != QUERY_END);
2197 
2198 #if defined(HISTO)
2199  if (net_Histo_setup)
2200  {
2201  net_histo_request_finished (request,
2202  replysize + *replydatasize_listid + *replydatasize_page + *replaydatasize_plan);
2203  }
2204 #endif /* HISTO */
2205  }
2206  return error;
2207 }
2208 
2209 /*
2210  * net_client_check_log_header -
2211  *
2212  * return:
2213  * Note:
2214  */
2215 int
2216 net_client_check_log_header (LOGWR_CONTEXT * ctx_ptr, char *argbuf, int argsize, char *replybuf, int replysize,
2217  char **logpg_area_buf, bool verbose)
2218 {
2219  unsigned int rc;
2220  char *reply = NULL;
2221  char *ptr;
2222  int error = NO_ERROR;
2223  int size;
2224  int fillsize;
2225  int request = NET_SERVER_LOGWR_GET_LOG_PAGES;
2226  QUERY_SERVER_REQUEST server_request;
2227  int server_request_num;
2228 
2229  if (net_Server_name[0] == '\0')
2230  {
2232  error = ER_NET_SERVER_CRASHED;
2233  }
2234  else
2235  {
2236  if (ctx_ptr->rc == -1)
2237  {
2238  /* HEADER PAGE REQUEST */
2239  rc = css_send_req_to_server_2_data (net_Server_host, request, argbuf, argsize, NULL, 0, NULL, 0, replybuf,
2240  replysize);
2241  if (rc == 0)
2242  {
2243  return set_server_error (css_Errno);
2244  }
2245  ctx_ptr->rc = rc;
2246  }
2247  else
2248  {
2249  /* END PROTOCOL */
2250  rc = ctx_ptr->rc;
2251  error = net_client_send_data (net_Server_host, rc, argbuf, argsize);
2252  if (error != NO_ERROR)
2253  {
2254  return error;
2255  }
2256  (void) css_queue_receive_data_buffer (rc, replybuf, replysize);
2257  }
2258 
2259  error = css_receive_data_from_server (rc, &reply, &size);
2260  if (error != NO_ERROR || reply == NULL)
2261  {
2262  COMPARE_AND_FREE_BUFFER (replybuf, reply);
2263  return set_server_error (error);
2264  }
2265  else
2266  {
2267  error = COMPARE_SIZE_AND_BUFFER (&replysize, size, &replybuf, reply);
2268  if (error != NO_ERROR)
2269  {
2270  return error;
2271  }
2272  }
2273 
2274  ptr = or_unpack_int (reply, &server_request_num);
2275  server_request = (QUERY_SERVER_REQUEST) server_request_num;
2276 
2277  switch (server_request)
2278  {
2279  case GET_NEXT_LOG_PAGES:
2280  {
2281  int length;
2282  char *logpg_area;
2283  char *reply_logpg = NULL;
2284  ptr = or_unpack_int (ptr, (int *) (&length));
2285  if (length <= 0)
2286  {
2288  error = ER_NET_SERVER_CRASHED;
2289  }
2290 
2291  logpg_area = (char *) malloc (length);
2292  if (logpg_area == NULL)
2293  {
2295  error = ER_OUT_OF_VIRTUAL_MEMORY;
2296  }
2297  css_queue_receive_data_buffer (rc, logpg_area, length);
2298  error = css_receive_data_from_server (rc, &reply_logpg, &fillsize);
2299  if (error != NO_ERROR)
2300  {
2301  COMPARE_AND_FREE_BUFFER (logpg_area, reply_logpg);
2302  return set_server_error (error);
2303  }
2304  else
2305  {
2306  *logpg_area_buf = logpg_area;
2307  }
2308  }
2309  break;
2310  case END_CALLBACK:
2311  error = NO_ERROR;
2312  break;
2313  default:
2315  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, error, 0);
2316  break;
2317  }
2318  }
2319  return error;
2320 }
2321 
2322 /*
2323  * net_client_request_with_logwr_context -
2324  *
2325  * return:
2326  * Note:
2327  */
2328 int
2329 net_client_request_with_logwr_context (LOGWR_CONTEXT * ctx_ptr, int request, char *argbuf, int argsize, char *replybuf,
2330  int replysize, char *databuf1, int datasize1, char *databuf2, int datasize2,
2331  char **replydata_ptr1, int *replydatasize_ptr1, char **replydata_ptr2,
2332  int *replydatasize_ptr2)
2333 {
2334  unsigned int rc;
2335  int size;
2336  int error;
2337  int request_error;
2338  char *reply = NULL, *ptr;
2339  QUERY_SERVER_REQUEST server_request;
2340  int server_request_num;
2341  bool do_read;
2342 
2343  error = 0;
2344  *replydata_ptr1 = NULL;
2345  *replydata_ptr2 = NULL;
2346  *replydatasize_ptr1 = 0;
2347  *replydatasize_ptr2 = 0;
2348 
2349  if (net_Server_name[0] == '\0')
2350  {
2352  error = ER_NET_SERVER_CRASHED;
2353  }
2354  else
2355  {
2356 #if defined (HISTO)
2357  if (net_Histo_setup)
2358  {
2359  net_histo_add_entry (request, argsize + datasize1 + datasize2);
2360  }
2361 #endif /* HISTO */
2362  if (ctx_ptr->rc == -1)
2363  {
2364  /* It sends a new request */
2365  rc =
2366  css_send_req_to_server_2_data (net_Server_host, request, argbuf, argsize, databuf1, datasize1, databuf2,
2367  datasize2, replybuf, replysize);
2368  if (rc == 0)
2369  {
2370  return set_server_error (css_Errno);
2371  }
2372  ctx_ptr->rc = rc;
2373  }
2374  else
2375  {
2376  /* It sends the same request with new arguments */
2377  rc = ctx_ptr->rc;
2378  error = net_client_send_data (net_Server_host, rc, argbuf, argsize);
2379  if (error != NO_ERROR)
2380  {
2381  return error;
2382  }
2383  (void) css_queue_receive_data_buffer (rc, replybuf, replysize);
2384  }
2385 
2386  do
2387  {
2388  do_read = false;
2389 #ifndef WINDOWS
2390  if (logwr_Gl.mode == LOGWR_MODE_SEMISYNC)
2391  {
2392  error = css_receive_data_from_server_with_timeout (rc, &reply, &size, 1000);
2393  }
2394  else
2395 #endif
2396  error = css_receive_data_from_server (rc, &reply, &size);
2397  if (error != NO_ERROR || reply == NULL)
2398  {
2399  COMPARE_AND_FREE_BUFFER (replybuf, reply);
2400  return set_server_error (error);
2401  }
2402  else
2403  {
2404  error = COMPARE_SIZE_AND_BUFFER (&replysize, size, &replybuf, reply);
2405  if (error != NO_ERROR)
2406  {
2407  return error;
2408  }
2409  }
2410 
2411  ptr = or_unpack_int (reply, &server_request_num);
2412  server_request = (QUERY_SERVER_REQUEST) server_request_num;
2413 
2414  switch (server_request)
2415  {
2416  case GET_NEXT_LOG_PAGES:
2417  {
2418  int length;
2419  ptr = or_unpack_int (ptr, (int *) (&length));
2420  error = net_client_get_next_log_pages (rc, replybuf, replysize, length);
2421  }
2422  break;
2423  case END_CALLBACK:
2424  if (logwr_Gl.mode == LOGWR_MODE_SEMISYNC)
2425  {
2426  logwr_Gl.force_flush = true;
2427  error = logwr_set_hdr_and_flush_info ();
2428  if (error == NO_ERROR)
2429  {
2430  error = logwr_write_log_pages ();
2431  }
2432  logwr_Gl.action = (LOGWR_ACTION) (logwr_Gl.action & LOGWR_ACTION_DELAYED_WRITE);
2433  }
2434 
2435  ptr = or_unpack_int (ptr, &request_error);
2436  if (request_error != ctx_ptr->last_error)
2437  {
2438  /* By server error or shutdown */
2439  error = request_error;
2440  if (error != ER_HA_LW_FAILED_GET_LOG_PAGE)
2441  {
2442  error = ER_NET_SERVER_CRASHED;
2443  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, error, 0);
2444  }
2445  }
2446 
2447  ctx_ptr->shutdown = true;
2448  break;
2449  default:
2450  /* TODO: handle the unknown request as an error */
2451  if (logwr_Gl.mode == LOGWR_MODE_SEMISYNC)
2452  {
2453  logwr_Gl.force_flush = true;
2454  error = logwr_set_hdr_and_flush_info ();
2455  if (error == NO_ERROR)
2456  {
2457  error = logwr_write_log_pages ();
2458  }
2459  logwr_Gl.action = (LOGWR_ACTION) (logwr_Gl.action & LOGWR_ACTION_DELAYED_WRITE);
2460  }
2461 
2463  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, error, 0);
2464 
2465  ctx_ptr->shutdown = true;
2466  break;
2467  }
2468  }
2469  while (do_read /* server_request != END_CALLBACK */ );
2470 #if defined(HISTO)
2471  if (net_Histo_setup)
2472  {
2473  net_histo_request_finished (request, replysize + *replydatasize_ptr1 + *replydatasize_ptr2);
2474  }
2475 #endif /* HISTO */
2476  }
2477  return error;
2478 }
2479 
2480 /*
2481  * net_client_logwr_send_end_msg
2482  *
2483  * return:
2484  * note:
2485  */
2486 void
2488 {
2489  OR_ALIGNED_BUF (OR_INT_SIZE * 2 + OR_INT64_SIZE) a_request;
2490  char *request;
2491  char *ptr;
2492 
2493  request = OR_ALIGNED_BUF_START (a_request);
2494 
2495  /* END REQUEST */
2496  ptr = or_pack_int64 (request, LOGPB_HEADER_PAGE_ID);
2497  ptr = or_pack_int (ptr, LOGWR_MODE_ASYNC);
2498  ptr = or_pack_int (ptr, error);
2499 
2500  net_client_send_data (net_Server_host, rc, request, OR_ALIGNED_BUF_SIZE (a_request));
2501 
2502  return;
2503 }
2504 
2505 /*
2506  * net_client_get_next_log_pages -
2507  *
2508  * return:
2509  *
2510  * rc(in): pre-allocated data buffer
2511  * replybuf(in): reply argument buffer
2512  * replysize(in): reply argument buffer size
2513  * ptr(in): pre-allocated data buffer
2514  *
2515  * Note:
2516  */
2517 int
2518 net_client_get_next_log_pages (int rc, char *replybuf, int replysize, int length)
2519 {
2520  char *reply = NULL;
2521  int error;
2522 
2523  if (logwr_Gl.logpg_area_size < length)
2524  {
2525  /*
2526  * It means log_buffer_size/log_page_size are different between master
2527  * and slave.
2528  * In this case, we have to disconnect from server and try to reconnect.
2529  */
2531  return ER_NET_SERVER_CRASHED;
2532  }
2533 
2534  (void) css_queue_receive_data_buffer (rc, logwr_Gl.logpg_area, logwr_Gl.logpg_area_size);
2535  error = css_receive_data_from_server (rc, &reply, &logwr_Gl.logpg_fill_size);
2536  if (error != NO_ERROR)
2537  {
2538  COMPARE_AND_FREE_BUFFER (logwr_Gl.logpg_area, reply);
2539  return set_server_error (error);
2540  }
2541  else
2542  {
2543  error = logwr_set_hdr_and_flush_info ();
2544  if (error != NO_ERROR)
2545  {
2546  COMPARE_AND_FREE_BUFFER (logwr_Gl.logpg_area, reply);
2547  return error;
2548  }
2549 
2550  switch (logwr_Gl.mode)
2551  {
2552  case LOGWR_MODE_SYNC:
2553  case LOGWR_MODE_SEMISYNC:
2554  error = logwr_write_log_pages ();
2555  break;
2556  case LOGWR_MODE_ASYNC:
2557  logwr_Gl.action = (LOGWR_ACTION) (logwr_Gl.action | LOGWR_ACTION_ASYNC_WRITE);
2558  break;
2559  default:
2560  break;
2561  }
2562  }
2563 
2564  COMPARE_AND_FREE_BUFFER (logwr_Gl.logpg_area, reply);
2565  return error;
2566 }
2567 
2568 /*
2569  * net_client_request_recv_copyarea -
2570  *
2571  * return:
2572  *
2573  * request(in):
2574  * argbuf(in):
2575  * argsize(in):
2576  * replybuf(in):
2577  * replysize(in):
2578  * reply_copy_area(in):
2579  *
2580  * Note:
2581  */
2582 int
2583 net_client_request_recv_copyarea (int request, char *argbuf, int argsize, char *replybuf, int replysize,
2584  LC_COPYAREA ** reply_copy_area)
2585 {
2586  unsigned int rc;
2587  int size;
2588  int error;
2589  char *reply = NULL;
2590  int content_size;
2591  char *content_ptr = NULL;
2592  int num_objs;
2593  char *packed_desc = NULL;
2594  int packed_desc_size;
2595 
2596  error = NO_ERROR;
2597  if (net_Server_name[0] == '\0')
2598  {
2599  /* need to have a more appropriate "unexpected disconnect" message */
2601  return ER_FAILED;
2602  }
2603 
2604 #if defined(HISTO)
2605  if (net_Histo_setup)
2606  {
2607  net_histo_add_entry (request, argsize);
2608  }
2609 #endif /* HISTO */
2610 
2611  rc = css_send_req_to_server (net_Server_host, request, argbuf, argsize, NULL, 0, replybuf, replysize);
2612  if (rc == 0)
2613  {
2614  return set_server_error (css_Errno);
2615  }
2616 
2617  /*
2618  * Receive replybuf
2619  */
2620 
2621  error = css_receive_data_from_server (rc, &reply, &size);
2622  if (error != NO_ERROR || reply == NULL)
2623  {
2624  COMPARE_AND_FREE_BUFFER (replybuf, reply);
2625  return set_server_error (error);
2626  }
2627 
2628  error = COMPARE_SIZE_AND_BUFFER (&replysize, size, &replybuf, reply);
2629 
2630  /*
2631  * Receive copyarea
2632  * Here assume that the next two integers in the reply are the lengths of
2633  * the copy descriptor and content descriptor
2634  */
2635 
2636  reply = or_unpack_int (reply, &num_objs);
2637  reply = or_unpack_int (reply, &packed_desc_size);
2638  reply = or_unpack_int (reply, &content_size);
2639 
2640  if (packed_desc_size == 0 && content_size == 0)
2641  {
2642  return error;
2643  }
2644 
2645  if (error == NO_ERROR && reply_copy_area != NULL)
2646  {
2647  *reply_copy_area = locator_recv_allocate_copyarea (num_objs, &packed_desc, packed_desc_size, &content_ptr,
2648  content_size);
2649  if (*reply_copy_area != NULL)
2650  {
2651  if (packed_desc != NULL && packed_desc_size > 0)
2652  {
2653  css_queue_receive_data_buffer (rc, packed_desc, packed_desc_size);
2654  error = css_receive_data_from_server (rc, &reply, &size);
2655  if (error != NO_ERROR)
2656  {
2657  COMPARE_AND_FREE_BUFFER (packed_desc, reply);
2658  free_and_init (packed_desc);
2659  locator_free_copy_area (*reply_copy_area);
2660  *reply_copy_area = NULL;
2661  return set_server_error (error);
2662  }
2663  else
2664  {
2665  locator_unpack_copy_area_descriptor (num_objs, *reply_copy_area, packed_desc);
2666  COMPARE_AND_FREE_BUFFER (packed_desc, reply);
2667  free_and_init (packed_desc);
2668  }
2669  }
2670 
2671  if (content_size > 0)
2672  {
2673  error = css_queue_receive_data_buffer (rc, content_ptr, content_size);
2674  if (error != NO_ERROR)
2675  {
2677  }
2678  else
2679  {
2680  error = css_receive_data_from_server (rc, &reply, &size);
2681  }
2682 
2683  COMPARE_AND_FREE_BUFFER (content_ptr, reply);
2684 
2685  if (error != NO_ERROR)
2686  {
2687  if (packed_desc != NULL)
2688  {
2689  free_and_init (packed_desc);
2690  }
2691  locator_free_copy_area (*reply_copy_area);
2692  *reply_copy_area = NULL;
2693  return set_server_error (error);
2694  }
2695  }
2696  }
2697  else
2698  {
2699  int num_packets = 0;
2700 
2701  ASSERT_ERROR_AND_SET (error);
2702 
2703  if (packed_desc_size > 0)
2704  {
2705  num_packets++;
2706  }
2707  if (content_size > 0)
2708  {
2709  num_packets++;
2710  }
2711  net_consume_expected_packets (rc, num_packets);
2712  }
2713 
2714  if (packed_desc != NULL)
2715  {
2716  free_and_init (packed_desc);
2717  }
2718  }
2719  else
2720  {
2721  int num_packets = 0;
2722 
2723  if (error == NO_ERROR)
2724  {
2725  error = ER_FAILED;
2726  }
2727 
2728  if (packed_desc_size > 0)
2729  {
2730  num_packets++;
2731  }
2732  if (content_size > 0)
2733  {
2734  num_packets++;
2735  }
2736  net_consume_expected_packets (rc, num_packets);
2737  }
2738 
2739 #if defined(HISTO)
2740  if (net_Histo_setup)
2741  {
2742  net_histo_request_finished (request, replysize + content_size + packed_desc_size);
2743  }
2744 #endif /* HISTO */
2745 
2746  return error;
2747 }
2748 
2749 /*
2750  * net_client_request_2recv_copyarea -
2751  *
2752  * return:
2753  *
2754  * request(in):
2755  * argbuf(in):
2756  * argsize(in):
2757  * replybuf(in):
2758  * replysize(in):
2759  * databuf(in):
2760  * datasize(in):
2761  * recvbuffer(in):
2762  * recvbuffer_size(in):
2763  * reply_copy_area(in):
2764  * eid(in):
2765  *
2766  * Note:
2767  */
2768 int
2769 net_client_request_2recv_copyarea (int request, char *argbuf, int argsize, char *replybuf, int replysize, char *databuf,
2770  int datasize, char *recvbuffer, int recvbuffer_size, LC_COPYAREA ** reply_copy_area,
2771  int *eid)
2772 {
2773  unsigned int rc;
2774  int size;
2775  int p_size, error;
2776  char *reply = NULL;
2777  int content_size;
2778  char *content_ptr = NULL;
2779  int num_objs;
2780  char *packed_desc = NULL;
2781  int packed_desc_size;
2782 
2783  error = NO_ERROR;
2784  if (net_Server_name[0] == '\0')
2785  {
2786  /* need to have a more appropriate "unexpected disconnect" message */
2788  return ER_FAILED;
2789  }
2790 
2791 #if defined(HISTO)
2792  if (net_Histo_setup)
2793  {
2794  net_histo_add_entry (request, argsize + datasize);
2795  }
2796 #endif /* HISTO */
2797 
2798  rc = css_send_req_to_server (net_Server_host, request, argbuf, argsize, databuf, datasize, replybuf, replysize);
2799  if (rc == 0)
2800  {
2801  return set_server_error (css_Errno);
2802  }
2803 
2804  *eid = rc;
2805 
2806  /*
2807  * Receive replybuf
2808  */
2809 
2810  error = css_receive_data_from_server (rc, &reply, &size);
2811  if (error != NO_ERROR)
2812  {
2813  COMPARE_AND_FREE_BUFFER (replybuf, reply);
2814  return set_server_error (error);
2815  }
2816  else
2817  {
2818  error = COMPARE_SIZE_AND_BUFFER (&replysize, size, &replybuf, reply);
2819  }
2820 
2821  /*
2822  * Receive recvbuffer
2823  * Here we assume that the first integer in the reply is the length
2824  * of the following data block
2825  */
2826 
2827  replybuf = or_unpack_int (replybuf, &p_size);
2828 
2829  if (recvbuffer_size < p_size)
2830  {
2831  /* too big for what we allocated */
2833  }
2834 
2835  if (p_size > 0)
2836  {
2837  if (error)
2838  {
2839  /* maintain error status. If we continued without checking this, error could become NO_ERROR and caller
2840  * would never know. */
2841  css_receive_data_from_server (rc, &reply, &size);
2842  if (reply != NULL)
2843  {
2844  free_and_init (reply);
2845  }
2846  }
2847  else
2848  {
2849  css_queue_receive_data_buffer (rc, recvbuffer, p_size);
2850  error = css_receive_data_from_server (rc, &reply, &size);
2851  if (error != NO_ERROR)
2852  {
2853  COMPARE_AND_FREE_BUFFER (recvbuffer, reply);
2854  return set_server_error (error);
2855  }
2856  else
2857  {
2858  /* we expect that the sizes won't match, but we must be sure that the we can accomodate the data in our
2859  * buffer. So, don't use COMPARE_SIZE_AND_BUFFER() here. */
2860  if (recvbuffer_size < size)
2861  {
2862  error = ER_NET_DATASIZE_MISMATCH;
2863  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, error, 2, recvbuffer_size, size);
2864  }
2865  else
2866  {
2867  recvbuffer_size = size;
2868  }
2869 
2870  if (reply != recvbuffer)
2871  {
2872  error = ER_NET_UNUSED_BUFFER;
2873  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, error, 0);
2874  free_and_init (reply);
2875  }
2876  }
2877  }
2878  }
2879 
2880  /*
2881  * Receive copyarea
2882  * Here assume that the next two integers in the reply are the lengths of
2883  * the copy descriptor and content descriptor
2884  */
2885 
2886  replybuf = or_unpack_int (replybuf, &num_objs);
2887  replybuf = or_unpack_int (replybuf, &packed_desc_size);
2888  replybuf = or_unpack_int (replybuf, &content_size);
2889 
2890  /* allocate the copyarea */
2891  *reply_copy_area = NULL;
2892  if (packed_desc_size == 0 && content_size == 0)
2893  {
2894  return error;
2895  }
2896 
2897  if (error == NO_ERROR)
2898  {
2899  *reply_copy_area = locator_recv_allocate_copyarea (num_objs, &packed_desc, packed_desc_size, &content_ptr,
2900  content_size);
2901  if (*reply_copy_area != NULL)
2902  {
2903  if (packed_desc != NULL && packed_desc_size > 0)
2904  {
2905  css_queue_receive_data_buffer (rc, packed_desc, packed_desc_size);
2906  error = css_receive_data_from_server (rc, &reply, &size);
2907  if (error != NO_ERROR)
2908  {
2909  COMPARE_AND_FREE_BUFFER (packed_desc, reply);
2910  free_and_init (packed_desc);
2911  return set_server_error (error);
2912  }
2913  else
2914  {
2915  locator_unpack_copy_area_descriptor (num_objs, *reply_copy_area, packed_desc);
2916  COMPARE_AND_FREE_BUFFER (packed_desc, reply);
2917  free_and_init (packed_desc);
2918  }
2919  }
2920 
2921  if (content_size > 0)
2922  {
2923  css_queue_receive_data_buffer (rc, content_ptr, content_size);
2924  error = css_receive_data_from_server (rc, &reply, &size);
2925  COMPARE_AND_FREE_BUFFER (content_ptr, reply);
2926  if (error != NO_ERROR)
2927  {
2928  if (packed_desc != NULL)
2929  {
2930  free_and_init (packed_desc);
2931  }
2932  return set_server_error (error);
2933  }
2934  }
2935  }
2936  else
2937  {
2938  int num_packets = 0;
2939 
2940  ASSERT_ERROR_AND_SET (error);
2941 
2942  if (packed_desc_size > 0)
2943  {
2944  num_packets++;
2945  }
2946  if (content_size > 0)
2947  {
2948  num_packets++;
2949  }
2950  net_consume_expected_packets (rc, num_packets);
2951  }
2952 
2953  if (packed_desc != NULL)
2954  {
2955  free_and_init (packed_desc);
2956  }
2957  }
2958  else
2959  {
2960  int num_packets = 0;
2961 
2962  assert (error != NO_ERROR);
2963 
2964  if (packed_desc_size > 0)
2965  {
2966  num_packets++;
2967  }
2968  if (content_size > 0)
2969  {
2970  num_packets++;
2971  }
2972  net_consume_expected_packets (rc, num_packets);
2973  }
2974 
2975 #if defined(HISTO)
2976  if (net_Histo_setup)
2977  {
2978  net_histo_request_finished (request, replysize + recvbuffer_size + content_size + packed_desc_size);
2979  }
2980 #endif /* HISTO */
2981 
2982  return error;
2983 }
2984 
2985 /*
2986  * net_client_request_3_data_recv_copyarea -
2987  *
2988  * return:
2989  *
2990  * request(in):
2991  * argbuf(in):
2992  * argsize(in):
2993  * databuf1(in):
2994  * datasize1(in):
2995  * databuf2(in):
2996  * datasize2(in):
2997  * replybuf(in):
2998  * replysize(in):
2999  * reply_copy_area(out): copy area sent by server
3000  *
3001  * Note:
3002  */
3003 int
3004 net_client_request_3_data_recv_copyarea (int request, char *argbuf, int argsize, char *databuf1, int datasize1,
3005  char *databuf2, int datasize2, char *replybuf, int replysize,
3006  LC_COPYAREA ** reply_copy_area)
3007 {
3008  unsigned int rid;
3009  int size;
3010  int error;
3011  char *reply = NULL;
3012  int content_size;
3013  char *content_ptr = NULL;
3014  int num_objs;
3015  char *packed_desc = NULL;
3016  int packed_desc_size;
3017  // test code
3018  int success;
3019 
3020  error = NO_ERROR;
3021  if (net_Server_name[0] == '\0')
3022  {
3023  /* need to have a more appropriate "unexpected disconnect" message */
3025  return ER_FAILED;
3026  }
3027 
3028 #if defined(HISTO)
3029  if (net_Histo_setup)
3030  {
3031  net_histo_add_entry (request, argsize + datasize);
3032  }
3033 #endif /* HISTO */
3034 
3035  rid =
3036  css_send_req_to_server_2_data (net_Server_host, request, argbuf, argsize, databuf1, datasize1, databuf2, datasize2,
3037  replybuf, replysize);
3038  if (rid == 0)
3039  {
3040  return set_server_error (css_Errno);
3041  }
3042 
3043  error = css_receive_data_from_server (rid, &reply, &size);
3044  if (error != NO_ERROR || reply == NULL)
3045  {
3046  COMPARE_AND_FREE_BUFFER (replybuf, reply);
3047  return set_server_error (error);
3048  }
3049  else
3050  {
3051  error = COMPARE_SIZE_AND_BUFFER (&replysize, size, &replybuf, reply);
3052  }
3053 
3054  replybuf = or_unpack_int (replybuf, &num_objs);
3055  replybuf = or_unpack_int (replybuf, &packed_desc_size);
3056  replybuf = or_unpack_int (replybuf, &content_size);
3057  replybuf = or_unpack_int (replybuf, &success);
3058 
3059  *reply_copy_area = NULL;
3060  if (packed_desc_size == 0 && content_size == 0)
3061  {
3062  return error;
3063  }
3064 
3065  if (error == NO_ERROR)
3066  {
3067  *reply_copy_area = locator_recv_allocate_copyarea (num_objs, &packed_desc, packed_desc_size, &content_ptr,
3068  content_size);
3069  if (*reply_copy_area != NULL)
3070  {
3071  if (packed_desc != NULL && packed_desc_size > 0)
3072  {
3073  css_queue_receive_data_buffer (rid, packed_desc, packed_desc_size);
3074  error = css_receive_data_from_server (rid, &reply, &size);
3075  if (error != NO_ERROR)
3076  {
3077  COMPARE_AND_FREE_BUFFER (packed_desc, reply);
3078  free_and_init (packed_desc);
3079  return set_server_error (error);
3080  }
3081  else
3082  {
3083  locator_unpack_copy_area_descriptor (num_objs, *reply_copy_area, packed_desc);
3084  COMPARE_AND_FREE_BUFFER (packed_desc, reply);
3085  free_and_init (packed_desc);
3086  }
3087  }
3088 
3089  if (content_size > 0)
3090  {
3091  css_queue_receive_data_buffer (rid, content_ptr, content_size);
3092  error = css_receive_data_from_server (rid, &reply, &size);
3093  COMPARE_AND_FREE_BUFFER (content_ptr, reply);
3094  if (error != NO_ERROR)
3095  {
3096  if (packed_desc != NULL)
3097  {
3098  free_and_init (packed_desc);
3099  }
3100  return set_server_error (error);
3101  }
3102  }
3103  }
3104  else
3105  {
3106  int num_packets = 0;
3107 
3108  ASSERT_ERROR_AND_SET (error);
3109 
3110  if (packed_desc_size > 0)
3111  {
3112  num_packets++;
3113  }
3114  if (content_size > 0)
3115  {
3116  num_packets++;
3117  }
3118  net_consume_expected_packets (rid, num_packets);
3119  }
3120 
3121  if (packed_desc != NULL)
3122  {
3123  free_and_init (packed_desc);
3124  }
3125  }
3126  else
3127  {
3128  int num_packets = 0;
3129 
3130  assert (error != NO_ERROR);
3131 
3132  if (packed_desc_size > 0)
3133  {
3134  num_packets++;
3135  }
3136  if (content_size > 0)
3137  {
3138  num_packets++;
3139  }
3140  net_consume_expected_packets (rid, num_packets);
3141  }
3142 
3143 #if defined(HISTO)
3144  if (net_Histo_setup)
3145  {
3146  net_histo_request_finished (request, replysize + recvbuffer_size + content_size + packed_desc_size);
3147  }
3148 #endif /* HISTO */
3149 
3150  return error;
3151 }
3152 
3153 /*
3154  * net_client_recv_copyarea -
3155  *
3156  * return:
3157  *
3158  * request(in):
3159  * replybuf(in):
3160  * replysize(in):
3161  * recvbuffer(in):
3162  * recvbuffer_size(in):
3163  * reply_copy_area(in):
3164  * rc(in):
3165  *
3166  * Note:
3167  */
3168 int
3169 net_client_recv_copyarea (int request, char *replybuf, int replysize, char *recvbuffer, int recvbuffer_size,
3170  LC_COPYAREA ** reply_copy_area, int rc)
3171 {
3172  int size;
3173  int error, p_size;
3174  char *reply = NULL;
3175  int content_size;
3176  char *content_ptr = NULL;
3177  int num_objs;
3178  char *packed_desc = NULL;
3179  int packed_desc_size;
3180 
3181  error = NO_ERROR;
3182  if (net_Server_name[0] == '\0')
3183  {
3184  /* need to have a more appropriate "unexpected disconnect" message */
3186  return ER_FAILED;
3187  }
3188 
3189 #if defined(HISTO)
3190  if (net_Histo_setup)
3191  {
3192  net_histo_add_entry (request, 0);
3193  }
3194 #endif /* HISTO */
3195 
3196  /*
3197  * Receive replybuf
3198  */
3199 
3200  css_queue_receive_data_buffer (rc, replybuf, replysize);
3201  error = css_receive_data_from_server (rc, &reply, &size);
3202  if (error != NO_ERROR)
3203  {
3204  COMPARE_AND_FREE_BUFFER (replybuf, reply);
3205  return set_server_error (error);
3206  }
3207  else
3208  {
3209  error = COMPARE_SIZE_AND_BUFFER (&replysize, size, &replybuf, reply);
3210  }
3211 
3212  /*
3213  * Receive recvbuffer
3214  * Here we assume that the first integer in the reply is the length
3215  * of the following data block
3216  */
3217 
3218  replybuf = or_unpack_int (replybuf, &p_size);
3219 
3220  if (recvbuffer_size < p_size)
3221  {
3223  }
3224 
3225  if (p_size > 0)
3226  {
3227  if (error)
3228  {
3229  /* maintain error status. If we continued without checking this, error could become NO_ERROR and caller
3230  * would never know. */
3231  css_receive_data_from_server (rc, &reply, &size);
3232  if (reply != NULL)
3233  {
3234  free_and_init (reply);
3235  }
3236  }
3237  else
3238  {
3239  css_queue_receive_data_buffer (rc, recvbuffer, p_size);
3240 
3241  error = css_receive_data_from_server (rc, &reply, &size);
3242  if (error != NO_ERROR)
3243  {
3244  COMPARE_AND_FREE_BUFFER (recvbuffer, reply);
3245  return set_server_error (error);
3246  }
3247 
3248  if (recvbuffer_size < size)
3249  {
3250  /* we expect that the sizes won't match, but we must be sure that the we can accomodate the data in
3251  * our buffer. So, don't use COMPARE_SIZE_AND_BUFFER() here. */
3252  error = ER_NET_DATASIZE_MISMATCH;
3253  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, error, 2, recvbuffer_size, size);
3254  }
3255  else
3256  {
3257  recvbuffer_size = size;
3258  }
3259 
3260  if (reply != recvbuffer)
3261  {
3262  error = ER_NET_UNUSED_BUFFER;
3263  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, error, 0);
3264  free_and_init (reply);
3265  }
3266  }
3267  }
3268 
3269  /*
3270  * Receive copyarea
3271  * Here assume that the next two integers in the reply are the lengths of
3272  * the copy descriptor and content descriptor
3273  */
3274 
3275  replybuf = or_unpack_int (replybuf, &num_objs);
3276  replybuf = or_unpack_int (replybuf, &packed_desc_size);
3277  replybuf = or_unpack_int (replybuf, &content_size);
3278 
3279  /* allocate the copyarea */
3280  *reply_copy_area = NULL;
3281  if (packed_desc_size == 0 && content_size == 0)
3282  {
3283  return error;
3284  }
3285 
3286  if (error == NO_ERROR)
3287  {
3288  *reply_copy_area =
3289  locator_recv_allocate_copyarea (num_objs, &packed_desc, packed_desc_size, &content_ptr, content_size);
3290  if (*reply_copy_area != NULL)
3291  {
3292  if (packed_desc != NULL && packed_desc_size > 0)
3293  {
3294  css_queue_receive_data_buffer (rc, packed_desc, packed_desc_size);
3295 
3296  error = css_receive_data_from_server (rc, &reply, &size);
3297  if (error != NO_ERROR)
3298  {
3299  COMPARE_AND_FREE_BUFFER (packed_desc, reply);
3300  free_and_init (packed_desc);
3301  return set_server_error (error);
3302  }
3303 
3304  locator_unpack_copy_area_descriptor (num_objs, *reply_copy_area, packed_desc);
3305  COMPARE_AND_FREE_BUFFER (packed_desc, reply);
3306  free_and_init (packed_desc);
3307  }
3308 
3309  if (content_size > 0)
3310  {
3311  css_queue_receive_data_buffer (rc, content_ptr, content_size);
3312  error = css_receive_data_from_server (rc, &reply, &size);
3313  COMPARE_AND_FREE_BUFFER (content_ptr, reply);
3314  if (error != NO_ERROR)
3315  {
3316  if (packed_desc != NULL)
3317  {
3318  free_and_init (packed_desc);
3319  }
3320  return set_server_error (error);
3321  }
3322  }
3323  }
3324  else
3325  {
3326  int num_packets = 0;
3327 
3328  ASSERT_ERROR_AND_SET (error);
3329 
3330  if (packed_desc_size > 0)
3331  {
3332  num_packets++;
3333  }
3334  if (content_size > 0)
3335  {
3336  num_packets++;
3337  }
3338  net_consume_expected_packets (rc, num_packets);
3339  }
3340 
3341  if (packed_desc != NULL)
3342  {
3343  free_and_init (packed_desc);
3344  }
3345  }
3346  else
3347  {
3348  int num_packets = 0;
3349 
3350  assert (error != NO_ERROR);
3351 
3352  if (packed_desc_size > 0)
3353  {
3354  num_packets++;
3355  }
3356  if (content_size > 0)
3357  {
3358  num_packets++;
3359  }
3360  net_consume_expected_packets (rc, num_packets);
3361  }
3362 
3363 #if defined(HISTO)
3364  if (net_Histo_setup)
3365  {
3366  net_histo_request_finished (request, replysize + recvbuffer_size + content_size + packed_desc_size);
3367  }
3368 #endif /* HISTO */
3369 
3370  return error;
3371 }
3372 
3373 /*
3374  * net_client_request_3recv_copyarea -
3375  *
3376  * return:
3377  *
3378  * request(in):
3379  * argbuf(in):
3380  * argsize(in):
3381  * replybuf(in):
3382  * replysize(in):
3383  * databuf(in):
3384  * datasize(in):
3385  * recvbuffer(in):
3386  * recvbuffer_size(in):
3387  * reply_copy_area(in):
3388  *
3389  * Note:
3390  */
3391 int
3392 net_client_request_3recv_copyarea (int request, char *argbuf, int argsize, char *replybuf, int replysize, char *databuf,
3393  int datasize, char **recvbuffer, int *recvbuffer_size,
3394  LC_COPYAREA ** reply_copy_area)
3395 {
3396  unsigned int rc;
3397  int size;
3398  int p_size, error;
3399  char *reply = NULL;
3400  int content_size;
3401  char *content_ptr = NULL;
3402  int num_objs;
3403  char *packed_desc = NULL;
3404  int packed_desc_size;
3405 
3406  error = NO_ERROR;
3407  *recvbuffer = NULL;
3408  *recvbuffer_size = 0;
3409 
3410  if (net_Server_name[0] == '\0')
3411  {
3412  /* need to have a more appropriate "unexpected disconnect" message */
3414  return ER_FAILED;
3415  }
3416 
3417 #if defined(HISTO)
3418  if (net_Histo_setup)
3419  {
3420  net_histo_add_entry (request, argsize + datasize);
3421  }
3422 #endif /* HISTO */
3423 
3424  rc = css_send_req_to_server (net_Server_host, request, argbuf, argsize, databuf, datasize, replybuf, replysize);
3425  if (rc == 0)
3426  {
3427  return set_server_error (css_Errno);
3428  }
3429 
3430  /*
3431  * Receive replybuf
3432  */
3433  error = css_receive_data_from_server (rc, &reply, &size);
3434  if (error != NO_ERROR)
3435  {
3436  COMPARE_AND_FREE_BUFFER (replybuf, reply);
3437  return set_server_error (error);
3438  }
3439  else
3440  {
3441  error = COMPARE_SIZE_AND_BUFFER (&replysize, size, &replybuf, reply);
3442  }
3443 
3444  /*
3445  * Receive recvbuffer
3446  * Here we assume that the first integer in the reply is the length
3447  * of the following data block
3448  */
3449 
3450  replybuf = or_unpack_int (replybuf, &p_size);
3451 
3452  if (p_size > 0)
3453  {
3454  *recvbuffer_size = p_size;
3455 
3456  if ((error == NO_ERROR) && (*recvbuffer = (char *) malloc (p_size)) != NULL)
3457  {
3458  css_queue_receive_data_buffer (rc, *recvbuffer, p_size);
3459  error = css_receive_data_from_server (rc, &reply, &size);
3460  if (error != NO_ERROR)
3461  {
3462  COMPARE_AND_FREE_BUFFER (*recvbuffer, reply);
3463  free_and_init (*recvbuffer);
3464  return set_server_error (error);
3465  }
3466  else
3467  {
3468  error = COMPARE_SIZE_AND_BUFFER (recvbuffer_size, size, recvbuffer, reply);
3469  }
3470 
3471  COMPARE_AND_FREE_BUFFER (*recvbuffer, reply);
3472  }
3473  else
3474  {
3475  *recvbuffer_size = 0;
3476 
3478 
3480  }
3481  }
3482 
3483  /*
3484  * Receive copyarea
3485  * Here assume that the next two integers in the reply are the lengths of
3486  * the copy descriptor and content descriptor
3487  */
3488 
3489  replybuf = or_unpack_int (replybuf, &num_objs);
3490  replybuf = or_unpack_int (replybuf, &packed_desc_size);
3491  replybuf = or_unpack_int (replybuf, &content_size);
3492 
3493  /* allocate the copyarea */
3494  *reply_copy_area = NULL;
3495  if (packed_desc_size == 0 && content_size == 0)
3496  {
3497  return error;
3498  }
3499 
3500  if ((error == NO_ERROR)
3501  && ((*reply_copy_area = locator_recv_allocate_copyarea (num_objs, &packed_desc, packed_desc_size, &content_ptr,
3502  content_size)) != NULL))
3503  {
3504  if (packed_desc != NULL && packed_desc_size > 0)
3505  {
3506  css_queue_receive_data_buffer (rc, packed_desc, packed_desc_size);
3507  error = css_receive_data_from_server (rc, &reply, &size);
3508  if (error != NO_ERROR)
3509  {
3510  COMPARE_AND_FREE_BUFFER (packed_desc, reply);
3511  free_and_init (packed_desc);
3512  return set_server_error (error);
3513  }
3514 
3515  locator_unpack_copy_area_descriptor (num_objs, *reply_copy_area, packed_desc);
3516  COMPARE_AND_FREE_BUFFER (packed_desc, reply);
3517  free_and_init (packed_desc);
3518  }
3519 
3520  if (content_size > 0)
3521  {
3522  css_queue_receive_data_buffer (rc, content_ptr, content_size);
3523  error = css_receive_data_from_server (rc, &reply, &size);
3524  COMPARE_AND_FREE_BUFFER (content_ptr, reply);
3525  if (error != NO_ERROR)
3526  {
3527  if (packed_desc != NULL)
3528  {
3529  free_and_init (packed_desc);
3530  }
3531  return set_server_error (error);
3532  }
3533  }
3534 
3535  if (packed_desc != NULL)
3536  {
3537  free_and_init (packed_desc);
3538  }
3539  }
3540  else
3541  {
3542  int num_packets = 0;
3543 
3544  if (error == NO_ERROR)
3545  {
3546  ASSERT_ERROR_AND_SET (error);
3547  }
3548 
3549  if (packed_desc_size > 0)
3550  {
3551  num_packets++;
3552  }
3553  if (content_size > 0)
3554  {
3555  num_packets++;
3556  }
3557  net_consume_expected_packets (rc, num_packets);
3558  }
3559 
3560 #if defined(HISTO)
3561  if (net_Histo_setup)
3562  {
3563  net_histo_request_finished (request, replysize + *recvbuffer_size + content_size + packed_desc_size);
3564  }
3565 #endif /* HISTO */
3566 
3567  return error;
3568 }
3569 
3570 /*
3571  * net_client_request_recv_stream -
3572  *
3573  * return:
3574  *
3575  * request(in):
3576  * argbuf(in):
3577  * argsize(in):
3578  * replybuf(in):
3579  * replybuf_size(in):
3580  * databuf(in):
3581  * datasize(in):
3582  * outfp(in):
3583  *
3584  * Note:
3585  */
3586 int
3587 net_client_request_recv_stream (int request, char *argbuf, int argsize, char *replybuf, int replybuf_size,
3588  char *databuf, int datasize, FILE * outfp)
3589 {
3590  unsigned int rc;
3591  int size;
3592  int error;
3593  char *reply = NULL;
3594  char *send_argbuffer;
3595  int send_argsize;
3596  char *recv_replybuf;
3597  int recv_replybuf_size;
3598  char reply_streamdata[100];
3599  int reply_streamdata_size = 100;
3600  int file_size;
3601 
3602  error = NO_ERROR;
3603 
3604  send_argsize = argsize + OR_INT_SIZE;
3605  recv_replybuf_size = replybuf_size + OR_INT_SIZE;
3606 
3607  send_argbuffer = (char *) malloc (send_argsize);
3608  if (send_argbuffer == NULL)
3609  {
3610  error = ER_NET_CANT_ALLOC_BUFFER;
3611  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, error, 0);
3612  return error;
3613  }
3614 
3615  or_pack_int (send_argbuffer, reply_streamdata_size);
3616 
3617  if (argsize > 0)
3618  {
3619  memcpy (send_argbuffer + OR_INT_SIZE, argbuf, argsize);
3620  }
3621 
3622  recv_replybuf = (char *) malloc (recv_replybuf_size);
3623  if (recv_replybuf == NULL)
3624  {
3625  free_and_init (send_argbuffer);
3626  error = ER_NET_CANT_ALLOC_BUFFER;
3627  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, error, 0);
3628  return error;
3629  }
3630 
3631  if (net_Server_name[0] == '\0')
3632  {
3633  /* need to have a more appropriate "unexpected disconnect" message */
3634  free_and_init (send_argbuffer);
3635  free_and_init (recv_replybuf);
3636  error = ER_NET_SERVER_CRASHED;
3637  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, error, 0);
3638  return error;
3639  }
3640 
3641 #if defined(HISTO)
3642  if (net_Histo_setup)
3643  {
3644  net_histo_add_entry (request, send_argsize + datasize);
3645  }
3646 #endif /* HISTO */
3647 
3648  rc = css_send_req_to_server (net_Server_host, request, send_argbuffer, send_argsize, databuf, datasize, recv_replybuf,
3649  recv_replybuf_size);
3650  if (rc == 0)
3651  {
3652  error = set_server_error (css_Errno);
3653  goto end;
3654  }
3655 
3656  error = css_receive_data_from_server (rc, &reply, &size);
3657  if (error != NO_ERROR)
3658  {
3659  COMPARE_AND_FREE_BUFFER (recv_replybuf, reply);
3660  error = set_server_error (error);
3661  goto end;
3662  }
3663  else
3664  {
3665  error = COMPARE_SIZE_AND_BUFFER (&recv_replybuf_size, size, &recv_replybuf, reply);
3666  }
3667 
3668  /* Get total size of file to transfered */
3669  or_unpack_int (recv_replybuf, &file_size);
3670 
3671  if (replybuf)
3672  {
3673  memcpy (replybuf, recv_replybuf + OR_INT_SIZE, recv_replybuf_size - OR_INT_SIZE);
3674  }
3675 
3676 #if defined(HISTO)
3677  if (net_Histo_setup)
3678  {
3679  net_histo_request_finished (request, recv_replybuf_size + file_size);
3680  }
3681 #endif /* HISTO */
3682 
3683  while (file_size > 0)
3684  {
3685  css_queue_receive_data_buffer (rc, reply_streamdata, reply_streamdata_size);
3686 
3687  error = css_receive_data_from_server (rc, &reply, &size);
3688  if (error != NO_ERROR)
3689  {
3690  COMPARE_AND_FREE_BUFFER (reply_streamdata, reply);
3691  error = set_server_error (error);
3692  goto end;
3693  }
3694 
3695  if (reply != reply_streamdata)
3696  {
3697  error = ER_NET_UNUSED_BUFFER;
3698  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, error, 0);
3699  COMPARE_AND_FREE_BUFFER (reply_streamdata, reply);
3700  break;
3701  }
3702  if (size > reply_streamdata_size)
3703  {
3704  error = ER_NET_DATASIZE_MISMATCH;
3705  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, error, 2, reply_streamdata_size, size);
3706  break;
3707  }
3708 
3709  file_size -= size;
3710  fwrite (reply_streamdata, 1, size, outfp);
3711  }
3712 
3713 end:
3714  free_and_init (send_argbuffer);
3715  free_and_init (recv_replybuf);
3716 
3717  return error;
3718 }
3719 
3720 /*
3721  * net_client_ping_server -ping the server
3722  *
3723  * return:
3724  */
3725 
3726 int
3727 net_client_ping_server (int client_val, int *server_val, int timeout)
3728 {
3729  OR_ALIGNED_BUF (OR_INT_SIZE) a_request;
3730  char *request = OR_ALIGNED_BUF_START (a_request);
3731  OR_ALIGNED_BUF (OR_INT_SIZE) a_reply;
3732  char *reply_buf = OR_ALIGNED_BUF_START (a_reply);
3733  char *reply = NULL;
3734  int eid, error, reply_size;
3735 
3736  er_log_debug (ARG_FILE_LINE, "The net_client_ping_server() is calling.");
3737 
3738  error = NO_ERROR;
3739  if (net_Server_host[0] == '\0' || net_Server_name[0] == '\0')
3740  {
3741  error = ER_NET_NO_SERVER_HOST;
3742  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, error, 0);
3743  return error;
3744  }
3745 
3746  /* you can envelope something useful into the request */
3747  or_pack_int (request, client_val);
3749  OR_INT_SIZE);
3750  if (eid == 0)
3751  {
3754  return error;
3755  }
3756 
3757  error = css_receive_data_from_server_with_timeout (eid, &reply, &reply_size, timeout);
3758  if (error || reply == NULL)
3759  {
3760  COMPARE_AND_FREE_BUFFER (reply_buf, reply);
3762  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, error, 0);
3763  return error;
3764  }
3765 
3766  /* you can get something useful from the server */
3767  if (server_val)
3768  {
3769  or_unpack_int (reply, server_val);
3770  }
3771 
3772  COMPARE_AND_FREE_BUFFER (reply_buf, reply);
3773  return error;
3774 }
3775 
3776 /*
3777  * net_client_ping_server_with_handshake -
3778  *
3779  * return:
3780  */
3781 int
3782 net_client_ping_server_with_handshake (int client_type, bool check_capabilities, int opt_cap)
3783 {
3784  const char *client_release;
3785  char *server_release, *server_host, *server_handshake, *ptr;
3786  int error = NO_ERROR;
3788  char *request = OR_ALIGNED_BUF_START (a_request);
3790  char *reply = OR_ALIGNED_BUF_START (a_reply), *reply_ptr;
3791  int reply_size = OR_ALIGNED_BUF_SIZE (a_reply);
3792  int eid, request_size, server_capabilities, server_bit_platform;
3793  int strlen1, strlen2;
3794  REL_COMPATIBILITY compat;
3795 
3796  if (net_Server_host[0] == '\0' || net_Server_name[0] == '\0')
3797  {
3798  error = ER_NET_NO_SERVER_HOST;
3799  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, error, 0);
3800  return error;
3801  }
3802 
3803  client_release = rel_release_string ();
3804 
3805  request_size = (or_packed_string_length (client_release, &strlen1) + (OR_INT_SIZE * 2)
3806  + or_packed_string_length (boot_Host_name, &strlen2));
3807  ptr = or_pack_string_with_length (request, client_release, strlen1);
3808  ptr = or_pack_int (ptr, client_capabilities ());
3809  ptr = or_pack_int (ptr, rel_bit_platform ());
3810  ptr = or_pack_int (ptr, client_type);
3811  ptr = or_pack_string_with_length (ptr, boot_Host_name, strlen2);
3812 
3814  reply, reply_size);
3815  if (eid == 0)
3816  {
3819  return error;
3820  }
3821 
3822  reply_ptr = reply;
3823  error = css_receive_data_from_server (eid, &reply_ptr, &reply_size);
3824  if (error)
3825  {
3826  COMPARE_AND_FREE_BUFFER (reply, reply_ptr);
3828  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, error, 0);
3829  return error;
3830  }
3831  if (reply != reply_ptr)
3832  {
3833  error = ER_NET_UNUSED_BUFFER;
3834  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, error, 0);
3835  free_and_init (reply_ptr);
3836  return error;
3837  }
3838 
3839  ptr = or_unpack_string_nocopy (reply, &server_release);
3840  ptr = or_unpack_string_nocopy (ptr, &server_handshake); /* for backward compatibility */
3841  ptr = or_unpack_int (ptr, &server_capabilities);
3842  ptr = or_unpack_int (ptr, &server_bit_platform);
3843  ptr = or_unpack_string_nocopy (ptr, &server_host);
3844 
3845  /* get the error code which was from the server if it exists */
3846  error = er_errid ();
3847  if (error != NO_ERROR)
3848  {
3849  return error;
3850  }
3851 
3852  /* check bits model */
3853  if (server_bit_platform != rel_bit_platform ())
3854  {
3856  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, error, 2, server_bit_platform, rel_bit_platform ());
3857  return error;
3858  }
3859 
3860  /* If we can't get the server version, we have to disconnect it. */
3861  if (server_release == NULL)
3862  {
3864  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, error, 0);
3865  return error;
3866  }
3867 
3868  /*
3869  * 1. get the result of compatibility check.
3870  * 2. check if the both capabilities of client and server are compatible.
3871  * 3. check if the server has a capability to make it compatible.
3872  */
3873  compat = rel_get_net_compatible (client_release, server_release);
3874  if ((check_capabilities == true || server_capabilities & NET_CAP_REMOTE_DISABLED)
3875  && check_server_capabilities (server_capabilities, client_type, rel_compare (client_release, server_release),
3876  &compat, server_host, opt_cap) != server_capabilities)
3877  {
3878  error = ER_NET_SERVER_HAND_SHAKE;
3880  return error;
3881  }
3882  if (compat == REL_NOT_COMPATIBLE)
3883  {
3884  error = ER_NET_DIFFERENT_RELEASE;
3885  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, error, 2, server_release, client_release);
3886  return error;
3887  }
3888 
3889  return error;
3890 }
3891 
3892 #if defined(ENABLE_UNUSED_FUNCTION)
3893 /*
3894  * net_client_shutdown_server -
3895  *
3896  * return:
3897  *
3898  * Note: Sends the server shutdown request to the server.
3899  * This is not used and I'm not sure if it even works.
3900  * Need to be careful that we don't expect a reply here.
3901  */
3902 void
3903 net_client_shutdown_server (void)
3904 {
3905  css_send_request_to_server (net_Server_host, NET_SERVER_SHUTDOWN, NULL, 0);
3906 }
3907 #endif /* ENABLE_UNUSED_FUNCTION */
3908 
3909 /*
3910  * net_client_init -
3911  *
3912  * return: error code
3913  *
3914  * dbname(in): server name
3915  * hostname(in): server host name
3916  *
3917  * Note: This is called during startup to initialize the client side
3918  * communications. It sets up CSS and verifies connection with the server.
3919  */
3920 int
3921 net_client_init (const char *dbname, const char *hostname)
3922 {
3923  int error = NO_ERROR;
3924 
3925  /* don't really need to do this every time but bruce says its ok - we probably need to guarentee that a css_terminate
3926  * is always called before this */
3927  error = css_client_init (prm_get_integer_value (PRM_ID_TCP_PORT_ID), dbname, hostname);
3928  if (error != NO_ERROR)
3929  {
3930  goto end;
3931  }
3932 
3933  /* since urgent_message_handler() doesn't do anything yet, just use the default handler provided by css which writes
3934  * things to the system console */
3935 
3936  /* set our host/server names for further css communication */
3937  if (hostname != NULL && strlen (hostname) <= CUB_MAXHOSTNAMELEN)
3938  {
3939  strcpy (net_Server_host, hostname);
3940  if (dbname != NULL && strlen (dbname) <= DB_MAX_IDENTIFIER_LENGTH)
3941  {
3942  strcpy (net_Server_name, dbname);
3943  }
3944  else
3945  {
3947  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, error, 1, dbname);
3948  }
3949  }
3950  else
3951  {
3952  error = ER_NET_INVALID_HOST_NAME;
3953  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, error, 1, hostname);
3954  }
3955 
3956  /* On error, flush any state that may have been initialized by css. This is important for the PC's since we must
3957  * shutdown Winsock after it has been opened by css_client_init. */
3958 end:
3959  if (error)
3960  {
3961  css_terminate (false);
3962  }
3963 
3964  return error;
3965 }
3966 
3967 /*
3968  * net_cleanup_client_queues -
3969  *
3970  * return:
3971  *
3972  * Note:
3973  */
3974 void
3976 {
3977  if (net_Server_host[0] != '\0' && net_Server_name[0] != '\0')
3978  {
3980  }
3981 }
3982 
3983 /*
3984  * net_client_final -
3985  *
3986  * return: error cod
3987  *
3988  * Note: This is called during shutdown to close the communication interface.
3989  */
3990 int
3992 {
3993  css_terminate (false);
3994  return NO_ERROR;
3995 }
3996 
3997 /*
3998  * net_client_send_data -
3999  *
4000  * return:
4001  *
4002  * host(in):
4003  * rc(in):
4004  * databuf(in):
4005  * datasize(in):
4006  *
4007  * Note: Send a data buffer to the server.
4008  */
4009 int
4010 net_client_send_data (char *host, unsigned int rc, char *databuf, int datasize)
4011 {
4012  int error;
4013 
4014  if (databuf != NULL)
4015  {
4016  error = css_send_data_to_server (host, rc, databuf, datasize);
4017  if (error != NO_ERROR)
4018  {
4019  return set_server_error (error);
4020  }
4021  }
4022 
4023  return NO_ERROR;
4024 }
4025 
4026 /*
4027  * net_client_receive_action -
4028  *
4029  * return:
4030  *
4031  * rc(in):
4032  * action(in):
4033  *
4034  * Note:
4035  */
4036 int
4037 net_client_receive_action (int rc, int *action)
4038 {
4039  int size;
4040  int error;
4041  char *reply = NULL;
4042  int replysize = OR_INT_SIZE;
4043 
4044  error = NO_ERROR;
4045  if (net_Server_name[0] == '\0')
4046  {
4047  /* need to have a more appropriate "unexpected disconnect" message */
4049  return ER_NET_SERVER_CRASHED;
4050  }
4051 
4052  error = css_receive_data_from_server (rc, &reply, &size);
4053  if (error != NO_ERROR || reply == NULL)
4054  {
4055  if (reply != NULL)
4056  {
4057  free_and_init (reply);
4058  }
4059  return set_server_error (error);
4060  }
4061 
4062  if (size != replysize)
4063  {
4064  error = ER_NET_DATASIZE_MISMATCH;
4065  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, error, 2, replysize, size);
4066  replysize = size;
4067  if (reply != NULL)
4068  {
4069  free_and_init (reply);
4070  }
4071  return set_server_error (error);
4072  }
4073 
4074  or_unpack_int (reply, action);
4075  free_and_init (reply);
4076 
4077  return error;
4078 }
void net_client_logwr_send_end_msg(int rc, int error)
Definition: network_cl.c:2487
#define NO_ERROR
Definition: error_code.h:46
bool db_need_ignore_repl_delay(void)
Definition: db_admin.c:743
int net_client_request_2recv_copyarea(int request, char *argbuf, int argsize, char *replybuf, int replysize, char *databuf, int datasize, char *recvbuffer, int recvbuffer_size, LC_COPYAREA **reply_copy_area, int *eid)
Definition: network_cl.c:2769
int net_histo_stop(void)
Definition: network_cl.c:804
static int net_client_request_internal(int request, char *argbuf, int argsize, char *replybuf, int replysize, char *databuf, int datasize, char *replydata, int replydatasize)
Definition: network_cl.c:961
#define DB_HS_MISMATCHED_RW_MODE
Definition: connection_cl.h:40
int net_client_ping_server_with_handshake(int client_type, bool check_capabilities, int opt_cap)
Definition: network_cl.c:3782
#define ER_NET_DIFFERENT_RELEASE
Definition: error_code.h:642
PAGE_PTR last_pgptr
Definition: query_list.h:434
int char_tolower(int c)
Definition: chartype.c:146
void locator_free_copy_area(LC_COPYAREA *copyarea)
Definition: locator.c:534
int db_Connect_status
Definition: db_macro.c:88
unsigned int css_send_request_to_server_with_buffer(char *host, int request, char *arg_buffer, int arg_buffer_size, char *data_buffer, int data_buffer_size)
unsigned int css_send_req_to_server_2_data(char *host, int request, char *arg_buffer, int arg_buffer_size, char *data1_buffer, int data1_buffer_size, char *data2_buffer, int data2_buffer_size, char *reply_buffer, int reply_size)
char * or_unpack_unbound_listid(char *ptr, void **listid_ptr)
#define ER_NET_SERVER_DATA_RECEIVE
Definition: error_code.h:256
FILEIO_REMOTE_PROMPT_TYPE
Definition: file_io.h:128
#define ER_FAILED
Definition: error_code.h:47
#define ER_NET_DATA_TRUNCATED
Definition: error_code.h:268
static INT64 net_Histo_last_call_time
Definition: network_cl.c:98
int net_client_request2(int request, char *argbuf, int argsize, char *replybuf, int replysize, char *databuf, int datasize, char **replydata_ptr, int *replydatasize_ptr)
Definition: network_cl.c:1288
#define ER_DB_NO_MODIFICATIONS
Definition: error_code.h:683
char * locator_unpack_copy_area_descriptor(int num_objs, LC_COPYAREA *copyarea, char *desc)
Definition: locator.c:619
int rel_compare(const char *rel_a, const char *rel_b)
int rel_bit_platform(void)
#define BOOT_REPLICA_ONLY_BROKER_CLIENT_TYPE(client_type)
Definition: boot.h:76
const LOG_PAGEID LOGPB_HEADER_PAGE_ID
Definition: log_storage.hpp:51
int net_client_request_no_reply(int request, char *argbuf, int argsize)
Definition: network_cl.c:896
#define ASSERT_ERROR_AND_SET(error_code)
#define NET_CAP_HA_REPL_DELAY
Definition: network.h:268
#define CSS_RID_FROM_EID(eid)
#define REL_MAX_RELEASE_LENGTH
#define ER_NET_CANT_CONNECT_SERVER
Definition: error_code.h:261
#define NET_CAP_HA_REPLICA
Definition: network.h:269
#define NET_CAP_FORWARD_COMPATIBLE
Definition: network.h:264
char * er_get_area_error(char *buffer, int *length)
#define OR_ALIGNED_BUF(size)
unsigned int css_receive_data_from_server(unsigned int eid, char **buffer, int *size)
static int eid
Definition: cas_error_log.c:61
#define cursor_free_self_list_id(list_id)
Definition: cursor.h:108
#define OR_INT64_SIZE
#define CAST_STRLEN
Definition: porting.h:470
char * or_unpack_string_nocopy(char *ptr, char **string)
static char net_Server_host[CUB_MAXHOSTNAMELEN+1]
Definition: network_cl.c:106
#define ER_NET_NO_SERVER_HOST
Definition: error_code.h:260
unsigned int css_send_req_to_server_no_reply(char *host, int request, char *arg_buffer, int arg_buffer_size)
int er_errid(void)
#define OR_ALIGNED_BUF_SIZE(abuf)
#define NET_CAP_INTERRUPT_ENABLED
Definition: network.h:265
char * net_client_get_server_host(void)
Definition: network_cl.c:936
#define er_log_debug(...)
int net_client_request_recv_stream(int request, char *argbuf, int argsize, char *replybuf, int replybuf_size, char *databuf, int datasize, FILE *outfp)
Definition: network_cl.c:3587
static struct net_request_buffer net_Req_buffer[NET_SERVER_REQUEST_END]
Definition: network_cl.c:93
#define DB_HS_HA_DELAYED
Definition: connection_cl.h:41
int net_client_request2_no_malloc(int request, char *argbuf, int argsize, char *replybuf, int replysize, char *databuf, int datasize, char *replydata, int *replydatasize_ptr)
Definition: network_cl.c:1395
int net_client_send_data(char *host, unsigned int rc, char *databuf, int datasize)
Definition: network_cl.c:4010
void css_cleanup_client_queues(char *host_name)
static INT64 net_Histo_total_server_time
Definition: network_cl.c:99
static int net_Histo_setup
Definition: network_cl.c:95
int net_client_init(const char *dbname, const char *hostname)
Definition: network_cl.c:3921
#define OR_ALIGNED_BUF_START(abuf)
void net_histo_clear(void)
Definition: network_cl.c:666
char * or_pack_int64(char *ptr, INT64 number)
char boot_Host_name[CUB_MAXHOSTNAMELEN]
Definition: boot_cl.c:158
REL_COMPATIBILITY
int css_queue_receive_data_buffer(unsigned int eid, char *buffer, int buffer_size)
static int client_capabilities(void)
Definition: network_cl.c:230
static void net_histo_setup_names(void)
Definition: network_cl.c:462
int method_invoke_for_server(unsigned int rc, char *host_p, char *server_name_p, qfile_list_id *list_id_p, method_sig_list *method_sig_list_p)
Definition: query_method.c:271
unsigned int css_send_req_to_server(char *host, int request, char *arg_buffer, int arg_buffer_size, char *data_buffer, int data_buffer_size, char *reply_buffer, int reply_size)
#define ER_NET_HS_UNKNOWN_SERVER_REL
Definition: error_code.h:1460
void er_set(int severity, const char *file_name, const int line_no, int err_id, int num_args,...)
void net_cleanup_client_queues(void)
Definition: network_cl.c:3975
static int check_server_capabilities(int server_cap, int client_type, int rel_compare, REL_COMPATIBILITY *compatibility, const char *server_host, int opt_cap)
Definition: network_cl.c:282
#define assert(x)
#define ER_NET_HS_INCOMPAT_INTERRUPTIBILITY
Definition: error_code.h:1455
int or_packed_string_length(const char *string, int *strlen)
int net_client_request_recv_copyarea(int request, char *argbuf, int argsize, char *replybuf, int replysize, LC_COPYAREA **reply_copy_area)
Definition: network_cl.c:2583
#define BOOT_IS_ALLOWED_CLIENT_TYPE_IN_MT_MODE(host1, host2, client_type)
Definition: boot.h:91
int prm_get_integer_value(PARAM_ID prm_id)
int net_histo_print(FILE *stream)
Definition: network_cl.c:695
REL_COMPATIBILITY rel_get_net_compatible(const char *client_rel_str, const char *server_rel_str)
#define ER_OUT_OF_VIRTUAL_MEMORY
Definition: error_code.h:50
static void return_error_to_server(char *host, unsigned int eid)
Definition: network_cl.c:208
static int net_set_alloc_err_if_not_set(int err, const char *file, const int line)
Definition: network_cl.c:382
int css_client_init(int sockid, const char *server_name, const char *host_name)
unsigned int css_send_data_to_server(char *host, unsigned int eid, char *buffer, int buffer_size)
#define NET_CAP_HA_IGNORE_REPL_DELAY
Definition: network.h:270
#define COMPARE_AND_FREE_BUFFER(queued, reply)
Definition: network_cl.c:72
#define DB_MAX_IDENTIFIER_LENGTH
Definition: dbtype_def.h:495
static int compare_size_and_buffer(int *replysize, int size, char **replybuf, char *buf, const char *file, const int line)
Definition: network_cl.c:427
static int set_server_error(int error)
Definition: network_cl.c:144
int db_Disable_modifications
Definition: db_macro.c:90
#define ER_NET_DIFFERENT_BIT_PLATFORM
Definition: error_code.h:1207
void boot_server_die_or_changed(void)
Definition: boot_cl.c:1503
int net_histo_print_global_stats(FILE *stream, bool cumulative, const char *substr)
Definition: network_cl.c:756
int substr(std::string &result, bool &is_matched, const cub_regex_object &reg, const std::string &src, const int position, const int occurrence, const INTL_CODESET codeset)
#define ER_NET_DATASIZE_MISMATCH
Definition: error_code.h:253
#define NET_CAP_BACKWARD_COMPATIBLE
Definition: network.h:263
static int net_Histo_setup_mnt
Definition: network_cl.c:96
#define ER_NET_INVALID_SERVER_NAME
Definition: error_code.h:258
#define NULL
Definition: freelistheap.h:34
int str_to_int32(int *ret_p, char **end_p, const char *str_p, int base)
Definition: porting.c:2346
#define ER_NET_UNUSED_BUFFER
Definition: error_code.h:257
static int server_capabilities(void)
int net_client_request_3_data(int request, char *argbuf, int argsize, char *databuf1, int datasize1, char *databuf2, int datasize2, char *reply0, int replysize0, char *reply1, int replysize1, char *reply2, int replysize2)
Definition: network_cl.c:1490
static char * dbname
#define FILEIO_MAX_USER_RESPONSE_SIZE
Definition: file_io.h:50
static int success()
#define err(fd,...)
Definition: porting.h:431
char * or_unpack_int(char *ptr, int *number)
#define ER_NET_HS_INCOMPAT_RW_MODE
Definition: error_code.h:1456
char * or_unpack_int64(char *ptr, INT64 *number)
void er_set_with_oserror(int severity, const char *file_name, const int line_no, int err_id, int num_args,...)
static char net_Server_name[DB_MAX_IDENTIFIER_LENGTH+1]
Definition: network_cl.c:109
static int net_Histo_call_count
Definition: network_cl.c:97
int net_client_receive_action(int rc, int *action)
Definition: network_cl.c:4037
LC_COPYAREA * locator_recv_allocate_copyarea(int num_objs, char **packed_desc, int packed_desc_length, char **contents_ptr, int contents_length)
Definition: locator.c:755
static void error(const char *msg)
Definition: gencat.c:331
#define ER_NET_SERVER_HAND_SHAKE
Definition: error_code.h:922
static int rc
Definition: serial.c:50
char * or_pack_int(char *ptr, int number)
static void net_histo_request_finished(int request, int data_received)
Definition: network_cl.c:866
#define ARG_FILE_LINE
Definition: error_manager.h:44
#define NET_CAP_UPDATE_DISABLED
Definition: network.h:266
#define ER_AU_DBA_ONLY
Definition: error_code.h:204
int net_client_request_3recv_copyarea(int request, char *argbuf, int argsize, char *replybuf, int replysize, char *databuf, int datasize, char **recvbuffer, int *recvbuffer_size, LC_COPYAREA **reply_copy_area)
Definition: network_cl.c:3392
#define ER_NET_HS_REMOTE_DISABLED
Definition: error_code.h:1459
int net_client_final(void)
Definition: network_cl.c:3991
int net_client_ping_server(int client_val, int *server_val, int timeout)
Definition: network_cl.c:3727
static void net_consume_expected_packets(int rc, int num_packets)
Definition: network_cl.c:395
static void net_histo_add_entry(int request, int data_sent)
Definition: network_cl.c:833
const char * name
Definition: network_cl.c:87
void css_terminate(bool server_error)
int net_client_request(int request, char *argbuf, int argsize, char *replybuf, int replysize, char *databuf, int datasize, char *replydata, int replydatasize)
Definition: network_cl.c:1053
#define free_and_init(ptr)
Definition: memory_alloc.h:147
#define strlen(s1)
Definition: intl_support.c:43
#define ER_NET_INVALID_HOST_NAME
Definition: error_code.h:259
#define ER_NET_CANT_ALLOC_BUFFER
Definition: error_code.h:254
int net_client_request_with_logwr_context(LOGWR_CONTEXT *ctx_ptr, int request, char *argbuf, int argsize, char *replybuf, int replysize, char *databuf1, int datasize1, char *databuf2, int datasize2, char **replydata_ptr1, int *replydatasize_ptr1, char **replydata_ptr2, int *replydatasize_ptr2)
Definition: network_cl.c:2329
char * or_pack_string_with_length(char *ptr, const char *string, int length)
#define ER_HA_LW_FAILED_GET_LOG_PAGE
Definition: error_code.h:1281
#define DB_PAGESIZE
char * or_unpack_method_sig_list(char *ptr, void **method_sig_list_ptr)
unsigned int css_receive_data_from_server_with_timeout(unsigned int eid, char **buffer, int *size, int timeout)
int intl_mbs_casecmp(const char *mbs1, const char *mbs2)
Definition: intl_support.c:358
int method_send_error_to_server(unsigned int rc, char *host_p, char *server_name_p)
Definition: query_method.c:241
void er_clear(void)
#define NET_CAP_REMOTE_DISABLED
Definition: network.h:267
#define ER_NET_HS_HA_REPLICA_ONLY
Definition: error_code.h:1458
unsigned int css_send_error_to_server(char *host, unsigned int eid, char *buffer, int buffer_size)
int i
Definition: dynamic_load.c:954
static const char * get_capability_string(int cap, int cap_type)
Definition: network_cl.c:255
#define ER_NET_SERVER_CRASHED
Definition: error_code.h:269
int net_client_get_next_log_pages(int rc, char *replybuf, int replysize, int length)
Definition: network_cl.c:2518
int net_client_recv_copyarea(int request, char *replybuf, int replysize, char *recvbuffer, int recvbuffer_size, LC_COPYAREA **reply_copy_area, int rc)
Definition: network_cl.c:3169
void method_sig_list_freemem(method_sig_list *meth_sig_list)
Definition: query_method.c:526
#define COMPARE_SIZE_AND_BUFFER(replysize, size, replybuf, buf)
Definition: network_cl.c:68
int net_client_check_log_header(LOGWR_CONTEXT *ctx_ptr, char *argbuf, int argsize, char *replybuf, int replysize, char **logpg_area_buf, bool verbose)
Definition: network_cl.c:2216
int css_Errno
int net_client_request_with_callback(int request, char *argbuf, int argsize, char *replybuf, int replysize, char *databuf1, int datasize1, char *databuf2, int datasize2, char **replydata_listid, int *replydatasize_listid, char **replydata_page, int *replydatasize_page, char **replydata_plan, int *replydatasize_plan)
Definition: network_cl.c:1611
QUERY_SERVER_REQUEST
Definition: network.h:272
#define CUB_MAXHOSTNAMELEN
Definition: porting.h:379
const char * rel_release_string(void)
void db_set_host_status(char *hostname, int status)
Definition: db_admin.c:649
static char * host
int net_client_request_3_data_recv_copyarea(int request, char *argbuf, int argsize, char *databuf1, int datasize1, char *databuf2, int datasize2, char *replybuf, int replysize, LC_COPYAREA **reply_copy_area)
Definition: network_cl.c:3004
int net_histo_start(bool for_all_trans)
Definition: network_cl.c:775
#define DB_CONNECTION_STATUS_NOT_CONNECTED
Definition: db.h:46
#define ER_NET_HS_HA_REPL_DELAY
Definition: error_code.h:1457