50 #ifdef NCBI_POSIX_THREADS
54 #define NCBI_USE_ERRCODE_X Connect_Core
84 static string x_Reg(
const char* section,
const char* name,
85 const char*
value = 0,
90 x_section =
'[' +
string(section) +
']';
95 x_name =
'"' +
string(name) +
'"';
103 switch (
int(storage)) {
105 x_storage =
", <Transient>";
108 x_storage =
", <Persistent>";
115 return x_section + x_name + x_value + x_storage;
121 const char* section,
const char* name,
126 +
x_Reg(section, name) +
')');
131 =
static_cast<const IRegistry*
> (user_data)->
Get(section, name);
133 size_t len = item.size();
134 if (
len >= value_size)
135 len = value_size - 1;
142 +
x_Reg(section, name) +
") = \"" +
string(
value)
143 + (
result ?
"\"" :
"\" <Truncated>"));
149 +
x_Reg(section, name) +
") failed");
157 const char* section,
const char* name,
161 _TRACE(
"s_REG_" +
string(
value ?
"Set" :
"Unset") +
'('
174 : reg->
Unset(section, name,
195 static_cast<const IRegistry*
> (user_data)->RemoveReference();
239 switch (
int(level)) {
253 x_level =
"Critical";
270 static const char kOutOfMemory[] =
"Ouch! Out of memory";
273 _TRACE(
"s_LOG_Handler(" +
x_Log(mess->level) +
')');
276 switch (
int(mess->level)) {
308 if (mess->message && *mess->message) {
318 if (mess->raw_size) {
322 if (mess->raw_data) {
332 data.assign(
buf.get(), (
size_t)(end -
buf.get()));
334 diag <<
"\n#################### [BEGIN] Raw Data ("
336 <<
" byte" << &
"s"[!(mess->raw_size != 1)] <<
"):"
338 <<
"\n#################### [_END_] Raw Data";
379 x_how =
"TryLockRead";
422 +
x_Lock(how) +
") failed");
434 delete static_cast<CRWLock*
> (user_data);
474 const string& referer
476 return referer.empty() ? 0 :
strdup(referer.c_str());
502 return id.empty() ? 0 :
strdup(
id.c_str());
529 static MONKEY_RETTYPE
530 MONKEY_STDCALL s_MonkeySend(MONKEY_SOCKTYPE sock,
531 const MONKEY_DATATYPE
data,
540 static MONKEY_RETTYPE
541 MONKEY_STDCALL s_MonkeyRecv(MONKEY_SOCKTYPE sock,
547 return CMonkey::Instance()->Recv(sock,
buf,
size,
flags,
552 static int MONKEY_STDCALL s_MonkeyConnect(MONKEY_SOCKTYPE sock,
553 const struct sockaddr* name,
554 MONKEY_SOCKLENTYPE namelen)
556 return CMonkey::Instance()->Connect(sock, name, namelen);
560 static int s_MonkeyPoll(
size_t*
n,
564 return CMonkey::Instance()->
565 Poll(
n, (
SSOCK_Poll**) polls, return_status) ? 1 : 0;
569 static void s_MonkeyClose(SOCKET sock)
571 CMonkey::Instance()->Close(sock);
575 static void s_MonkeySockHasSocket(
void* sock,
576 MONKEY_SOCKTYPE socket)
578 CMonkey::Instance()->SockHasSocket((
SOCK)sock, socket);
583 static int s_MONKEY_Poll_dummy(
size_t*
n,
591 static void s_MONKEY_Close_dummy(SOCKET sock)
598 static void s_SetMonkeyHooks(EMonkeyHookSwitch hook_switch)
602 case eMonkeyHookSwitch_Disabled:
605 g_MONKEY_Connect = 0;
608 g_MONKEY_SockHasSocket = 0;
610 case eMonkeyHookSwitch_Enabled:
611 g_MONKEY_Send = s_MonkeySend;
612 g_MONKEY_Recv = s_MonkeyRecv;
613 g_MONKEY_Connect = s_MonkeyConnect;
614 g_MONKEY_Poll = s_MonkeyPoll;
615 g_MONKEY_Close = s_MonkeyClose;
616 g_MONKEY_SockHasSocket = s_MonkeySockHasSocket;
626 #ifdef NCBI_POSIX_THREADS
659 _TRACE(
"CONNECT::s_Fini()");
689 _TRACE(
"CONNECT::s_Init(reg="
697 auto connect_init =
s_ConnectInit.load(memory_order_acquire);
699 ERR_POST_X(11,
"CONNECT_Init() called more than once");
732 if (x_set && atexit(
s_Fini) != 0)
734 #ifdef NCBI_POSIX_THREADS
739 static const char* what[] = {0,
"exit",
"fork",
"exit/fork"};
741 <<
"Failed to register "
742 << what[err] <<
" handler" << &
"s"[!(err == 3)]);
753 CMonkey::MonkeyHookSwitchSet(s_SetMonkeyHooks);
772 _TRACE(
"CONNECT_Init(reg="
789 auto connect_init =
s_ConnectInit.load(memory_order_relaxed);
Incapsulate compile time information such as __FILE__, __LINE__, NCBI_MODULE, current function.
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
static CNcbiApplicationGuard InstanceGuard(void)
Singleton method.
const CNcbiRegistry & GetConfig(void) const
Get the application's cached configuration parameters (read-only).
const string & GetProgramDisplayName(void) const
Get the application's "display" name.
string GetSessionID(void) const
Session ID.
void SetSessionID(const string &session)
const string & GetProperty(const string &name) const
Get property value or empty string.
const CNcbiDiag & SetErrorCode(int code=0, int subcode=0) const
Set error code and subcode numbers.
const string & GetNextSubHitID(CTempString prefix=CTempString())
Get current hit id appended with auto-incremented sub-hit id.
void SetDtab(const string &dtab)
bool IsVisibleDiagPostLevel(EDiagSev sev)
Check if the specified severity is higher or equal to the currently selected post level and will be p...
static CRequestContext & GetRequestContext(void)
Shortcut to CDiagContextThreadData::GetThreadData().GetRequestContext()
NCBI_XNCBI_EXPORT void Abort(void)
Smart abort function.
const string & GetDtab(void) const
#define ERR_POST_X(err_subcode, message)
Error posting with default error code and given error subcode.
EDiagSev
Severity level for the posted diagnostics.
@ eDiag_Trace
Trace message.
@ eDiag_Info
Informational message.
@ eDiag_Error
Error message.
@ eDiag_Warning
Warning message.
@ eDiag_Fatal
Fatal error – guarantees exit(or abort)
@ eDiag_Critical
Critical error message.
void Critical(CExceptionArgs_Base &args)
#define NCBI_CATCH_ALL_X(err_subcode, message)
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
#define THROWS_NONE
Do not use 'throw' dynamic exception specification for C++11 compilers.
void AddReference(void) const
Add reference to object.
#define NCBI_PARAM_TYPE(section, name)
Generate typename for a parameter from its {section, name} attributes.
@ eParam_Default
Default flags.
bool Unset(const string §ion, const string &name, TFlags flags=0)
Fully unset the configuration parameter value, so that HasEntry returns false.
bool Set(const string §ion, const string &name, const string &value, TFlags flags=0, const string &comment=kEmptyStr)
Set the configuration parameter value.
@ fTruncate
Leading, trailing blanks can be truncated.
@ fPersistent
Persistent – saved when file is written.
@ fTransient
Transient – not saved by default.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
SOCKSSL NcbiSetupTls(void)
Setup a TLS (Transport Layer Security) provider library to support SSL in ncbi_socket....
void SOCK_SetupSSL(FSSLSetup setup)
Store SSL setup callback until actual initialization.
SOCKSSL(* FSSLSetup)(void)
SSL setup callback.
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
static void PtrToString(string &out_str, const void *ptr)
Convert pointer to string.
static string UIntToString(unsigned int value, TNumToStringFlags flags=0, int base=10)
Convert UInt to string.
void ReadLock(void)
Read lock.
bool TryReadLock(void)
Try read lock.
bool TryWriteLock(void)
Try write lock.
void WriteLock(void)
Write lock.
void Unlock(void)
Release the RW-lock.
LOG LOG_cxx2c(void)
Create LOG on top of C++ Toolkit CNcbiDiag.
#define UTIL_PRINTABLE_WIDTH
ELOG_Level
Log severity level.
char * UTIL_PrintableStringEx(const char *data, size_t size, char *buf, TUTIL_PrintableFlags flags, int width)
Create a printable representation of a block of data of the specified size (or, if size is 0,...
void CORE_SetREG(REG rg)
Set the registry (no registry if "rg" is passed zero) – to be used by the core internals.
REG REG_cxx2c(IRWRegistry *reg, bool pass_ownership)
Convert a C++ Toolkit registry object to a REG registry.
EMT_Lock
Set the lock/unlock callback function and its data for MT critical section.
void CONNECT_Init(const IRWRegistry *reg, CRWLock *lock, TConnectInitFlags flag, FSSLSetup ssl)
Init [X]CONNECT library with the specified "reg" and "lock" (ownership for either or both can be deta...
EREG_Storage
Transient/Persistent storage.
REG REG_Create(void *data, FREG_Get get, FREG_Set set, FREG_Cleanup cleanup, MT_LOCK lock)
Create a new registry (with an internal reference count set to 1).
void CORE_SetLOCK(MT_LOCK lk)
Set the MT critical section lock/unlock handler – to be used by the core internals for protection of ...
MT_LOCK MT_LOCK_cxx2c(CRWLock *lock, bool pass_ownership)
Convert a C++ Toolkit lock object to an MT_LOCK lock.
const char * IO_StatusStr(EIO_Status status)
Get the text form of an enum status value.
LOG LOG_Create(void *data, FLOG_Handler handler, FLOG_Cleanup cleanup, MT_LOCK lock)
Create a new LOG (with an internal reference count set to 1).
unsigned int TConnectInitFlags
Bitwise OR of EConnectInitFlag.
size_t UTIL_PrintableStringSize(const char *data, size_t size)
Calculate size of buffer needed to store printable representation of the block of data of the specifi...
MT_LOCK MT_LOCK_Create(void *data, FMT_LOCK_Handler handler, FMT_LOCK_Cleanup cleanup)
Create a new MT lock (with an internal reference count set to 1).
void CORE_SetLOG(LOG lg)
Set the log handle (no logging if "lg" is passed zero) – to be used by the core internals (CORE LOG).
ENcbiRequestID
NCBI request ID enumerator.
@ eConnectInit_OwnLock
Lock ownership gets passed.
@ eConnectInit_NoSSL
Do NOT init secure socket layer (SSL)
@ eConnectInit_OwnRegistry
Registry ownership gets passed.
@ eMT_Unlock
unlock critical section
@ eMT_Lock
lock critical section
@ eMT_LockRead
lock critical section for reading
@ eMT_TryLock
try to lock, return immediately
@ eMT_TryLockRead
try to lock for reading, return immediately
@ eREG_Transient
only in-memory storage while program runs
@ eREG_Persistent
hard-copy storage across program runs
@ eIO_Success
everything is fine, no error occurred
@ eNcbiRequestID_SID
NCBI Session ID.
@ eNcbiRequestID_HitID
NCBI Hit ID.
unsigned int
A callback function used to compare two keys in a database.
Definition of all error codes used in connect library (xconnect.lib, xconnext.lib etc).
const TYPE & Get(const CNamedParameterList *param)
const struct ncbi::grid::netcache::search::fields::SIZE size
const GenericPointer< typename T::ValueType > T2 value
char * strncpy0(char *s1, const char *s2, size_t n)
Copy not more than "n" characters from string "s2" into "s1", and return the result,...
AutoPtr< char, CDeleter< char > > TTempCharPtr
NCBI_PARAM_DEF_EX(bool, CONN, TRACE_REG, false, eParam_Default, CONN_TRACE_REG)
static atomic< EConnectInit > s_ConnectInit
static CSafeStatic< TTraceLog > s_TraceLog
static char * s_GetRequestID(ENcbiRequestID reqid)
static void s_REG_Cleanup(void *user_data) THROWS_NONE
DEFINE_STATIC_FAST_MUTEX(s_ConnectInitMutex)
NCBI_PARAM_TYPE(CONN, TRACE_LOCK) TTraceLock
static TCORE_Set s_CORE_Set
static void x_PostFork(void)
static const char * s_GetAppName(void)
static void s_Fini(void) THROWS_NONE
static int s_REG_Get(void *user_data, const char *section, const char *name, char *value, size_t value_size) THROWS_NONE
static CSafeStatic< TTraceLock > s_TraceLock
static int s_LOCK_Handler(void *user_data, EMT_Lock how) THROWS_NONE
static int s_REG_Set(void *user_data, const char *section, const char *name, const char *value, EREG_Storage storage) THROWS_NONE
static CSafeStatic< TTraceReg > s_TraceReg
static void x_PreFork(void)
NCBI_PARAM_TYPE(CONN, TRACE_REG) TTraceReg
static void s_Init(const IRWRegistry *reg=0, FSSLSetup ssl=0, CRWLock *lock=0, TConnectInitFlags flag=0, EConnectInit how=eConnectInit_Weak)
static const char * s_GetReferer(void)
NCBI_PARAM_TYPE(CONN, TRACE_LOG) TTraceLog
static string x_Log(ELOG_Level level)
static void s_LOG_Handler(void *, const SLOG_Message *mess) THROWS_NONE
static string x_Lock(EMT_Lock how)
NCBI_PARAM_DECL(bool, CONN, TRACE_REG)
static string x_Reg(const char *section, const char *name, const char *value=0, EREG_Storage storage=eREG_Transient)
static void s_LOCK_Cleanup(void *user_data) THROWS_NONE
static const char * s_GetRequestDTab(void)
@ eConnectInit_Strong
User init detected.
@ eConnectInit_Weak
CConn_Initer.
@ eConnectInit_Intact
Not yet visited.
@ eConnectInit_Explicit
CONNECT_Init() called.
unsigned int g_NCBI_ConnectRandomSeed
FNcbiGetRequestDtab g_CORE_GetRequestDtab
FNcbiGetRequestID g_CORE_GetRequestID
FNcbiGetAppName g_CORE_GetAppName
FNcbiGetReferer g_CORE_GetReferer
#define NCBI_CONNECT_SRAND_ADDEND
Static variables safety - create on demand, destroy on application termination.
Common macro to detect used sanitizers and suppress memory leaks if run under LeakSanitizer.
#define NCBI_LSAN_DISABLE_GUARD
EIO_Status SOCK_SetupSSLInternalEx(FSSLSetup setup, int init)
Defines the CNcbiApplication and CAppException classes for creating NCBI applications.
NCBI C++ auxiliary debug macros.
static int message_len(const char *message, int offset)
Defines CRequestContext class for NCBI C++ diagnostic API.
const Int2 kOutOfMemory
Failure due to out-of-memory condition.
Message and miscellaneous data to pass to log post callback FLOG_Handler.