NCBI C++ ToolKit
Classes | Macros | Typedefs | Enumerations | Functions
ncbi_connection.c File Reference
#include "ncbi_priv.h"
#include "ncbi_socketp.h"
#include <connect/ncbi_connection.h>
#include <stdlib.h>
#include <string.h>
+ Include dependency graph for ncbi_connection.c:

Go to the source code of this file.

Go to the SVN repository for this file.

Classes

struct  SConnectionTag
 

Macros

#define NCBI_USE_ERRCODE_X   Connect_Conn
 
#define CONNECTION_MAGIC   0xEFCDAB09
 
#define CONN_LOG_EX(subcode, func_name, level, message, status)
 
#define CONN_LOG(s_c, f_n, lvl, msg)   CONN_LOG_EX(s_c, f_n, lvl, msg, status)
 
#define CONN_CALLTRACE(func_name)   /*((void) 0)*/
 
#define CONN_NOT_NULL_EX(subcode, func_name, retval)
 
#define CONN_NOT_NULL(s_c, f_n)   CONN_NOT_NULL_EX(s_c, f_n, eIO_InvalidArg)
 
#define CONN_TRACE(f_n, msg)   CONN_LOG(0, f_n, eLOG_Trace, msg)
 

Typedefs

typedef struct SConnectionTag SConnection
 

Enumerations

enum  ECONN_InternalFlag { fCONN_Flush = 1024 }
 
enum  ECONN_State {
  eCONN_Unusable = -1 , eCONN_Closed = 0 , eCONN_Open = 1 , eCONN_Bad = 2 ,
  eCONN_Cancel = 3 , eCONN_Corrupt = 5
}
 

Functions

static size_t x_CB2IDX (ECONN_Callback type)
 
static EIO_Status x_Callback (CONN conn, ECONN_Callback type, unsigned int flag)
 
static EIO_Status x_Flush (CONN conn, const STimeout *timeout, int isflush)
 
static EIO_Status x_ReInit (CONN conn, CONNECTOR connector, int close)
 
static EIO_Status s_Open (CONN conn)
 
EIO_Status CONN_CreateEx (CONNECTOR connector, TCONN_Flags flags, CONN *connection)
 Create all data necessary to establish a new connection (merely bind it to the specified CONNECTOR). More...
 
EIO_Status CONN_Create (CONNECTOR connector, CONN *conn)
 Same as CONN_CreateEx() called with 0 in the "flags" parameter. More...
 
EIO_Status CONN_ReInit (CONN conn, CONNECTOR connector)
 Reinit using new "connector". More...
 
const char * CONN_GetType (CONN conn)
 Get verbal representation of connection type as a character string. More...
 
char * CONN_Description (CONN conn)
 Return a human-readable description of the connection as a character '\0'-terminated string. More...
 
TNCBI_BigCount CONN_GetPosition (CONN conn, EIO_Event event)
 Get read ("event" == eIO_Read) or write ("event" == eIO_Write) position within the connection. More...
 
EIO_Status CONN_SetTimeout (CONN conn, EIO_Event event, const STimeout *timeout)
 Specify timeout for the connection I/O, including "Connect" (aka "Open") and "Close". More...
 
const STimeoutCONN_GetTimeout (CONN conn, EIO_Event event)
 Retrieve current timeout, return NULL(kInfiniteTimeout) if it is infinite. More...
 
EIO_Status CONN_Wait (CONN conn, EIO_Event event, const STimeout *timeout)
 Block on the connection until it becomes available for either reading or writing (depending on "event"), until timeout expires, or until any error. More...
 
static EIO_Status s_CONN_Write (CONN conn, const void *data, const size_t size, size_t *n_written)
 
static EIO_Status s_CONN_WritePersist (CONN conn, const void *data, const size_t size, size_t *n_written)
 
EIO_Status CONN_Write (CONN conn, const void *data, size_t size, size_t *n_written, EIO_WriteMethod how)
 
EIO_Status CONN_Pushback (CONN conn, const void *data, size_t size)
 Push "size" bytes from the buffer "data" back into connection. More...
 
EIO_Status CONN_Flush (CONN conn)
 Explicitly flush connection from any pending data written by CONN_Write(). More...
 
static EIO_Status s_CONN_Read (CONN conn, void *buf, const size_t size, size_t *n_read, int peek)
 
static EIO_Status s_CONN_ReadPersist (CONN conn, void *buf, const size_t size, size_t *n_read)
 
EIO_Status CONN_Read (CONN conn, void *buf, size_t size, size_t *n_read, EIO_ReadMethod how)
 
EIO_Status CONN_ReadLine (CONN conn, char *line, size_t size, size_t *n_read)
 Read up to "size" bytes from connection into a string buffer pointed to by "line". More...
 
EIO_Status CONN_Status (CONN conn, EIO_Event dir)
 Obtain status of the last I/O operation. More...
 
EIO_Status CONN_Close (CONN conn)
 Close the connection and destroy all relevant internal data. More...
 
EIO_Status CONN_SetCallback (CONN conn, ECONN_Callback type, const SCONN_Callback *newcb, SCONN_Callback *oldcb)
 
EIO_Status CONN_GetSOCK (CONN conn, SOCK *sock)
 Get an underlying SOCK handle for connection that is implemented as a socket. More...
 
EIO_Status CONN_SetFlags (CONN conn, TCONN_Flags flags)
 Set connection processing flags. More...
 
TCONN_Flags CONN_GetFlags (CONN conn)
 Get connection processing flags currently in effect. More...
 
EIO_Status CONN_SetUserData (CONN conn, void *data)
 Associate an arbitraty user data pointer with the connection. More...
 
void * CONN_GetUserData (CONN conn)
 Get current value of the user's data pointer last associated with the connection, or NULL (if CONN is NULL or no pointer is currently set). More...
 

Macro Definition Documentation

◆ CONN_CALLTRACE

#define CONN_CALLTRACE (   func_name)    /*((void) 0)*/

Definition at line 94 of file ncbi_connection.c.

◆ CONN_LOG

#define CONN_LOG (   s_c,
  f_n,
  lvl,
  msg 
)    CONN_LOG_EX(s_c, f_n, lvl, msg, status)

Definition at line 83 of file ncbi_connection.c.

◆ CONN_LOG_EX

#define CONN_LOG_EX (   subcode,
  func_name,
  level,
  message,
  status 
)
Value:
do { \
const char* ststr = ((EIO_Status) status != eIO_Success \
? IO_StatusStr((EIO_Status) status) \
: ""); \
const char* ctype = (conn && conn->meta.get_type \
? conn->meta.get_type(conn->meta.c_get_type) \
: 0); \
char* descr = (conn && conn->meta.descr \
? conn->meta.descr(conn->meta.c_descr) \
: 0); \
char stbuf[80]; \
if ((EIO_Status) status == eIO_Timeout && timeout) { \
assert(timeout != kDefaultTimeout); \
sprintf(stbuf, "%s[%u.%06u]", ststr, \
timeout->usec / 1000000 + timeout->sec, \
timeout->usec % 1000000); \
assert(strlen(stbuf) < sizeof(stbuf)); \
ststr = stbuf; \
} \
CORE_LOGF_X(subcode, level, \
("[CONN_" #func_name "(%s%s%s)] %s%s%s", \
ctype && *ctype ? ctype : "UNDEF", \
descr && *descr ? "; " : "", descr ? descr : "", \
message, \
ststr && *ststr ? ": " : "", \
ststr ? ststr : "")); \
if (descr) \
free(descr); \
} while (0)
static CS_CONNECTION * conn
Definition: ct_dynamic.c:25
EIO_Status
I/O status.
Definition: ncbi_core.h:132
const char * IO_StatusStr(EIO_Status status)
Get the text form of an enum status value.
Definition: ncbi_core.c:56
#define kDefaultTimeout
Definition: ncbi_types.h:81
@ eIO_Timeout
timeout expired before any I/O succeeded
Definition: ncbi_core.h:134
@ eIO_Success
everything is fine, no error occurred
Definition: ncbi_core.h:133

Definition at line 52 of file ncbi_connection.c.

◆ CONN_NOT_NULL

#define CONN_NOT_NULL (   s_c,
  f_n 
)    CONN_NOT_NULL_EX(s_c, f_n, eIO_InvalidArg)

Definition at line 120 of file ncbi_connection.c.

◆ CONN_NOT_NULL_EX

#define CONN_NOT_NULL_EX (   subcode,
  func_name,
  retval 
)
Value:
do { \
CONN_CALLTRACE(func_name); \
if (!conn) { \
static const STimeout* timeout = 0/*dummy*/; \
CONN_LOG_EX(subcode, func_name, eLOG_Error, \
"NULL connection handle", retval); \
assert(conn); \
return retval; \
} \
if (conn->magic != CONNECTION_MAGIC) { \
static const STimeout* timeout = 0/*dummy*/; \
CONN_LOG_EX(subcode, func_name, eLOG_Critical, \
"Corrupt connection handle", 0); \
assert(0); \
return retval; \
} \
} while (0)
@ eLOG_Critical
Definition: ncbi_core.h:298
@ eLOG_Error
Definition: ncbi_core.h:297
#define CONNECTION_MAGIC
Timeout structure.
Definition: ncbi_types.h:76

Definition at line 101 of file ncbi_connection.c.

◆ CONN_TRACE

#define CONN_TRACE (   f_n,
  msg 
)    CONN_LOG(0, f_n, eLOG_Trace, msg)

Definition at line 123 of file ncbi_connection.c.

◆ CONNECTION_MAGIC

#define CONNECTION_MAGIC   0xEFCDAB09

Definition at line 43 of file ncbi_connection.c.

◆ NCBI_USE_ERRCODE_X

#define NCBI_USE_ERRCODE_X   Connect_Conn

Definition at line 40 of file ncbi_connection.c.

Typedef Documentation

◆ SConnection

typedef struct SConnectionTag SConnection

Enumeration Type Documentation

◆ ECONN_InternalFlag

Enumerator
fCONN_Flush 

Definition at line 131 of file ncbi_connection.c.

◆ ECONN_State

Enumerator
eCONN_Unusable 
eCONN_Closed 
eCONN_Open 
eCONN_Bad 
eCONN_Cancel 
eCONN_Corrupt 

Definition at line 138 of file ncbi_connection.c.

Function Documentation

◆ s_CONN_Read()

static EIO_Status s_CONN_Read ( CONN  conn,
void *  buf,
const size_t  size,
size_t *  n_read,
int  peek 
)
static

◆ s_CONN_ReadPersist()

static EIO_Status s_CONN_ReadPersist ( CONN  conn,
void *  buf,
const size_t  size,
size_t *  n_read 
)
static

◆ s_CONN_Write()

static EIO_Status s_CONN_Write ( CONN  conn,
const void *  data,
const size_t  size,
size_t *  n_written 
)
static

◆ s_CONN_WritePersist()

static EIO_Status s_CONN_WritePersist ( CONN  conn,
const void *  data,
const size_t  size,
size_t *  n_written 
)
static

◆ s_Open()

static EIO_Status s_Open ( CONN  conn)
static

◆ x_Callback()

static EIO_Status x_Callback ( CONN  conn,
ECONN_Callback  type,
unsigned int  flag 
)
static

◆ x_CB2IDX()

static size_t x_CB2IDX ( ECONN_Callback  type)
static

◆ x_Flush()

static EIO_Status x_Flush ( CONN  conn,
const STimeout timeout,
int  isflush 
)
static

◆ x_ReInit()

static EIO_Status x_ReInit ( CONN  conn,
CONNECTOR  connector,
int  close 
)
static
Modified on Mon May 27 04:36:18 2024 by modify_doxy.py rev. 669887