41 #define NCBI_USE_ERRCODE_X Connect_Stream
51 #if (defined(NCBI_COMPILER_GCC) && NCBI_COMPILER_VERSION < 700) \
52 || defined(NCBI_COMPILER_ANY_CLANG)
68 #if !defined(NCBI_COMPILER_GCC) || NCBI_COMPILER_GCC >= 700
82 unique_ptr<char, void (*)(
void*)>
84 string result(
"[CConn_Streambuf::");
106 ::sprintf(x_timeout,
"[%u.%06us]",
107 timeout->
usec / 1000000 + timeout->
sec,
108 timeout->
usec % 1000000);
124 : m_Conn(0), x_Connector(connector),
125 m_WriteBuf(0), m_ReadBuf(&x_Buf), m_BufSize(1), m_Status(status),
175 : m_Conn(
conn), x_Connector(0),
176 m_WriteBuf(0), m_ReadBuf(&x_Buf), m_BufSize(1), m_Status(
eIO_Success),
232 unique_ptr<CT_CHAR_TYPE[]> wbp;
251 setp(write_buf, write_buf + buf_size);
257 setg(ptr, ptr, ptr +
size);
274 "Failed to open",
m_Status, timeout));
289 size_t count = (size_t)(egptr() - gptr());
314 "CONN_Pushback() failed"));
320 if (pbase() < pptr()) {
326 "Cannot finalize implicitly"
327 ", data loss may result"));
368 "CONN_Close() failed",
399 if (
buf || buf_size) {
401 "CConn_Streambuf::setbuf() only allowed with (0, 0)");
413 "Write data pending"));
436 size_t n_towrite = (size_t)(pptr() - pbase());
443 _ASSERT(n_written <= n_towrite);
449 memmove(pbase(), pbase() + n_written, n_towrite - n_written);
451 pbump(-
int(n_written));
456 n_towrite -= n_written;
508 size_t n = (size_t) m;
509 size_t n_written = 0;
514 if (
n && pbase() +
n < epptr()) {
516 x_written = (size_t)(epptr() - pptr());
520 memcpy(pptr(),
buf, x_written);
521 pbump(
int(x_written));
522 n_written += x_written;
525 return (streamsize) n_written;
530 size_t x_towrite = (size_t)(pptr() - pbase());
534 _ASSERT(x_written <= x_towrite);
543 memmove(pbase(), pbase() + x_written, x_towrite - x_written);
545 pbump(-
int(x_written));
553 if (!x_written &&
n) {
556 "CONN_Write(direct) failed",
m_Status,
562 n_written += x_written;
565 return (streamsize) n_written;
572 x_written = (size_t)(epptr() - pptr());
576 memcpy(pptr(),
buf, x_written);
577 n_written += x_written;
578 pbump(
int(x_written));
584 return (streamsize) n_written;
599 #ifdef NCBI_COMPILER_MIPSPRO
600 if (m_MIPSPRO_ReadsomeGptrSetLevel && m_MIPSPRO_ReadsomeGptr != gptr())
644 size_t n = (size_t) m;
649 n_read = (size_t)(egptr() - gptr());
653 memcpy(
buf, gptr(), n_read);
657 return (streamsize) n_read;
686 size_t xx_read = x_read;
708 return (streamsize) n_read;
722 #define POLLING &CConn_IOStream::kZeroTimeout
753 if (!tmo || (tmo->
sec | tmo->
usec))
788 IOS_BASE::seekdir whence,
789 IOS_BASE::openmode which)
791 if (whence == IOS_BASE::cur && off == 0) {
802 && ((whence == IOS_BASE::cur && (off > 0)) ||
803 (whence == IOS_BASE::beg && (off -=
x_GetGPos()) >= 0))){
804 if (
m_Conn &&
x_Read(0, (streamsize) off) == (streamsize) off)
823 "CONN_Pushback() failed"));
845 if (pbase() < pptr()) {
873 if (gptr() < egptr())
882 "CONN_Wait() failed",
891 switch (GetErrCode()) {
892 case eConn:
return "eConn";
901 switch (GetErrCode()) {
902 case eTimeout:
return "eIO_Timeout";
906 case eUnknown:
return "eIO_Unknown";
907 case eClosed:
return "eIO_Closed";
CConn_Streambuf(CONNECTOR connector, EIO_Status status, const STimeout *timeout, size_t buf_size, CConn_IOStream::TConn_Flags flags, CT_CHAR_TYPE *ptr, size_t size)
virtual ~CConn_Streambuf()
EIO_Status Status(EIO_Event direction) const
virtual CT_INT_TYPE underflow(void)
streamsize x_Read(CT_CHAR_TYPE *buf, streamsize n)
void x_Init(const STimeout *timeout, size_t buf_size, CConn_IOStream::TConn_Flags flags, CT_CHAR_TYPE *ptr, size_t size)
CT_POS_TYPE x_GetPPos(void)
CT_CHAR_TYPE * m_WriteBuf
string x_Message(const char *method, const char *message, EIO_Status status=eIO_Success, const STimeout *timeout=kInfiniteTimeout)
virtual CT_INT_TYPE overflow(CT_INT_TYPE c)
virtual streamsize xsgetn(CT_CHAR_TYPE *buf, streamsize n)
static EIO_Status x_OnClose(CONN conn, TCONN_Callback type, void *data)
EIO_Status Fetch(const STimeout *timeout)
virtual CT_POS_TYPE seekoff(CT_OFF_TYPE off, IOS_BASE::seekdir whence, IOS_BASE::openmode which=IOS_BASE::in|IOS_BASE::out)
Only seekoff(0, IOS_BASE::cur, *) to obtain current position, and input skip-forward are permitted: s...
EIO_Status x_Close(bool close)
virtual streamsize xsputn(const CT_CHAR_TYPE *buf, streamsize n)
EIO_Status Pushback(const CT_CHAR_TYPE *data, streamsize size, bool push)
Push the specified data "data" of size "size" back into the underlying connection CONN.
virtual CNcbiStreambuf * setbuf(CT_CHAR_TYPE *buf, streamsize buf_size)
Only setbuf(0, 0) is allowed to make I/O unbuffered, other parameters will cause an exception thrown ...
virtual streamsize showmanyc(void)
EIO_Status x_Pushback(void) THROWS_NONE
CT_POS_TYPE x_GetGPos(void)
static CS_CONNECTION * conn
std::ofstream out("events_result.xml")
main entry point for tests
virtual const char * GetErrCodeString(void) const override
virtual const char * GetErrCodeString(void) const override
#define NCBI_IO_CHECK(errnum)
Check EIO_Status, throw an exception if something is wrong.
@ eConn
Unspecified connect problem.
unsigned int TConn_Flags
bitwise OR of EConn_Flag
@ fConn_ReadUnbuffered
read buffer NOT to be alloc'd
@ fConn_WriteUnbuffered
write buffer NOT 2.b. alloc'd
@ fConn_DelayOpen
do not force CONN open in ctor
@ fConn_Untie
do not flush before reading
EIO_Status CONN_CreateEx(CONNECTOR connector, TCONN_Flags flags, CONN *conn)
Create all data necessary to establish a new connection (merely bind it to the specified CONNECTOR).
EIO_Status CONN_Read(CONN conn, void *buf, size_t size, size_t *n_read, EIO_ReadMethod how)
EIO_Status CONN_Flush(CONN conn)
Explicitly flush connection from any pending data written by CONN_Write().
EIO_Status CONN_SetCallback(CONN conn, ECONN_Callback type, const SCONN_Callback *new_cb, SCONN_Callback *old_cb)
unsigned int TCONN_Callback
EIO_Status CONN_Write(CONN conn, const void *buf, size_t size, size_t *n_written, EIO_WriteMethod how)
CONNECTOR next
linked list
void * data
data to pass to the callback as its last arg
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".
char * CONN_Description(CONN conn)
Return a human-readable description of the connection as a character '\0'-terminated string.
FDestroy destroy
destroys handle, can be NULL
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...
SMetaConnector * meta
back link to original meta
const char * CONN_GetType(CONN conn)
Get verbal representation of connection type as a character string.
EIO_Status CONN_Close(CONN conn)
Close the connection and destroy all relevant internal data.
EIO_Status CONN_GetSOCK(CONN conn, SOCK *sock)
Get an underlying SOCK handle for connection that is implemented as a socket.
const STimeout * CONN_GetTimeout(CONN conn, EIO_Event event)
Retrieve current timeout, return NULL(kInfiniteTimeout) if it is infinite.
const STimeout g_NcbiDefConnTimeout
DEF_CONN_TIMEOUT as STimeout.
EIO_Status CONN_Status(CONN conn, EIO_Event dir)
Obtain status of the last I/O operation.
EIO_Status CONN_Pushback(CONN conn, const void *data, size_t size)
Push "size" bytes from the buffer "data" back into connection.
FCONN_Callback func
function address to call on the event
@ eCONN_OnClose
NB: CONN has been flushed prior to the call.
@ fCONN_Untie
do not call flush method prior to reading
@ fCONN_Supplement
supplement I/O with extended return codes
#define _ALWAYS_TRACE(message)
Define macros to support debugging.
#define ERR_POST_X(err_subcode, message)
Error posting with default error code and given error subcode.
void Critical(CExceptionArgs_Base &args)
void Error(CExceptionArgs_Base &args)
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
void Trace(CExceptionArgs_Base &args)
void Warning(CExceptionArgs_Base &args)
#define THROWS_NONE
Do not use 'throw' dynamic exception specification for C++11 compilers.
virtual const char * GetErrCodeString(void) const
Get error code interpreted as text.
uint64_t Uint8
8-byte (64-bit) unsigned integer
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
IO_PREFIX::streambuf CNcbiStreambuf
Portable alias for streambuf.
unsigned int usec
microseconds (modulo 1,000,000)
const char * IO_StatusStr(EIO_Status status)
Get the text form of an enum status value.
EIO_Event
I/O event (or direction).
@ eIO_Timeout
timeout expired before any I/O succeeded
@ eIO_NotSupported
operation is not supported or is not available
@ eIO_Success
everything is fine, no error occurred
@ eIO_InvalidArg
bad argument / parameter value(s) supplied
@ eIO_ReadPlain
read readily available data only, wait if none
@ eIO_WritePlain
write as much as possible, report back how much
@ eIO_ReadWrite
eIO_Read | eIO_Write (also, eCONN_OnFlush)
@ eIO_Open
also serves as no-event indicator in SOCK_Poll
@ eIO_Close
also serves as an error indicator in SOCK_Poll
Definition of all error codes used in connect library (xconnect.lib, xconnext.lib etc).
static void text(MDB_val *v)
const struct ncbi::grid::netcache::search::fields::SIZE size
static bool x_IsThrowable(EIO_Status status)
static bool x_CheckConn(CONN conn)
NCBI C++ auxiliary debug macros.
std::istream & in(std::istream &in_, double &x_)