rv = ::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
96FORMAT_MESSAGE_FROM_SYSTEM |
97FORMAT_MESSAGE_MAX_WIDTH_MASK |
98FORMAT_MESSAGE_IGNORE_INSERTS,
100MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
104errstr = errmsg.c_str();
109::LocalFree((HLOCAL) tmpstr);
120 returnretval.
get() ? retval.
get() : message;
126 return "[CNamedPipe::"+ where +
"] "+ what;
137 #if defined(NCBI_OS_MSWIN) 145 return(
error== ERROR_NO_DATA ||
146 error== ERROR_BROKEN_PIPE ||
147 error== ERROR_PIPE_NOT_CONNECTED ?
true:
false);
198m_ReadStatus(eIO_Closed), m_WriteStatus(eIO_Closed)
221+
"\" already open");
226SECURITY_ATTRIBUTES attr;
227attr.nLength =
sizeof(attr);
228attr.bInheritHandle =
TRUE;
229attr.lpSecurityDescriptor =
NULL;
241 unsigned longx_sleep = 1;
245GENERIC_READ | GENERIC_WRITE,
246FILE_SHARE_READ | FILE_SHARE_WRITE,
247&attr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
251 DWORD mode= PIPE_READMODE_BYTE | PIPE_NOWAIT;
252 if( ::SetNamedPipeHandleState(pipe, &
mode,
NULL,
NULL) ) {
255 error= ::GetLastError();
258 error= ::GetLastError();
261&&
error!= ERROR_PIPE_BUSY) ||
263&&
error!= ERROR_PIPE_NOT_CONNECTED)) {
265&&
error== ERROR_FILE_NOT_FOUND) {
272 "Named pipe \""+ pipename
275?
"open":
"set non-blocking"));
281 if(x_timeout != INFINITE) {
282 if(x_sleep > x_timeout) {
285x_timeout -= x_sleep;
302 catch(
string& what) {
319+
"\" already exists");
325 "Named pipe \""+ pipename
332SECURITY_ATTRIBUTES attr;
333attr.nLength =
sizeof(attr);
334attr.bInheritHandle =
TRUE;
335attr.lpSecurityDescriptor =
NULL;
338 m_Pipe= ::CreateNamedPipe
341PIPE_TYPE_BYTE | PIPE_NOWAIT,
350 if(
error== ERROR_ALREADY_EXISTS) {
354 "Named pipe \""+ pipename
355+
"\" failed to create");
363 catch(
string& what) {
391 unsigned longx_sleep = 1;
397 if(
error== ERROR_PIPE_CONNECTED) {
402 if(
error== ERROR_NO_DATA
) {
408+
"\" still connected");
410 if(
error!= ERROR_PIPE_LISTENING) {
413+
"\" not listening");
419 if(x_timeout != INFINITE) {
420 if(x_sleep > x_timeout) {
423x_timeout -= x_sleep;
438 catch(
string& what) {
457+
"\" failed to flush");
461+
"\" failed to flush");
470 if(!::DisconnectNamedPipe(
m_Pipe)) {
476+
"\" failed to disconnect");
485(void) ::CloseHandle(
m_Pipe);
502+
"\" already disconnected");
509 catch(
string& what) {
528 catch(
string& what) {
534(void) ::CloseHandle(
m_Pipe);
555 unsigned longx_sleep = 1;
582 if(x_timeout != INFINITE) {
583 if(x_sleep > x_timeout) {
586x_timeout -= x_sleep;
613:
" not connected"));
627 if(bytes_avail >
count) {
631 if( !bytes_avail ) {
636+
"\" read failed");
640*n_read = bytes_avail;
645}
else if(status != eIO_Closed) {
648+
"\" peek failed");
651 catch(
string& what) {
660 size_t* n_written,
const STimeout* timeout)
663 _ASSERT(n_written && !*n_written);
673:
" not connected"));
686 DWORDbytes_written = 0;
688 unsigned longx_sleep = 1;
691 if( bytes_written ) {
712+
"\" write failed");
720 if(x_timeout != INFINITE) {
721 if(x_sleep > x_timeout) {
724x_timeout -= x_sleep;
734*n_written = bytes_written;
737 catch(
string& what) {
752:
" not connected")));
766 returnstatus == eIO_Closed ?
eIO_Success: status;
774 switch( direction ) {
787 #elif defined(NCBI_OS_UNIX) 796 static const intkListenQueueSize = 64;
827 boolx_SetSocketBufSize(
intsock,
size_t bufsize,
intdir);
840: m_LSocket(0), m_IoSocket(0), m_PipeSize(0)
860 if(m_LSocket || m_IoSocket) {
863+
"\" already open");
869|| (status == eIO_Closed
875 "Named pipe \""+ pipename
876+
"\" failed to open UNIX socket: " 885 if(!x_SetSocketBufSize(fd, pipesize, SO_SNDBUF) ||
886!x_SetSocketBufSize(fd, pipesize, SO_RCVBUF)) {
890 "Named pipe \""+ pipename
892 " UNIX socket buffer size " 902 catch(
string& what) {
916 if(m_LSocket || m_IoSocket) {
919+
"\" already exists");
923 switch(pipe.GetType()) {
933 "Named pipe path \""+ pipename
934+
"\" already exists");
942 "Named pipe \""+ pipename
943+
"\" failed to create listening" 947m_PipeSize = pipesize;
951 catch(
string& what) {
964 if(!m_LSocket || m_IoSocket) {
968+
'"'+
string(m_LSocket
973status =
LSOCK_Accept(m_LSocket, timeout, &m_IoSocket);
980+
"\" failed to accept in UNIX socket: " 989 if(!x_SetSocketBufSize(fd, m_PipeSize, SO_SNDBUF) ||
990!x_SetSocketBufSize(fd, m_PipeSize, SO_RCVBUF)) {
993+
"\" failed to set UNIX socket buffer " 1001 catch(
string& what) {
1036 if( !m_IoSocket ) {
1039+
"\" already disconnected"));
1048 if(!m_LSocket && !m_IoSocket) {
1069 if( !m_IoSocket ) {
1072+
'"'+
string(m_LSocket
1086+
"\" read failed: " 1090 catch(
string& what) {
1099 size_t* n_written,
const STimeout* timeout)
1102 _ASSERT(n_written && !*n_written);
1107 if( !m_IoSocket ) {
1110+
'"'+
string(m_LSocket
1124+
"\" write failed: " 1128 catch(
string& what) {
1138 if( !m_IoSocket ) {
1146 return SOCK_Wait(m_IoSocket, event, timeout);
1152 return!m_IoSocket ? eIO_Closed :
SOCK_Status(m_IoSocket, direction);
1156 boolCNamedPipeHandle::x_SetSocketBufSize(
intsock,
size_t bufsize,
intdir)
1162 if(::getsockopt(sock, SOL_SOCKET, dir, &bs_old, &bs_len) == 0
1163&& bs_new > bs_old) {
1164 if(::setsockopt(sock, SOL_SOCKET, dir, &bs_new, bs_len) != 0) {
1183: m_PipeSize(pipesize),
1184m_OpenTimeout(0), m_ReadTimeout(0), m_WriteTimeout(0)
1224n_written = &x_written;
1257 switch(direction) {
1317 #ifdef NCBI_OS_MSWIN 1318 static const charkSeparators[] =
":/\\";
1320 static const charkSeparators[] =
"/";
1322 if(pipename.find_first_of(kSeparators) !=
NPOS) {
1327 #if defined(NCBI_OS_MSWIN) 1329 #elif defined(NCBI_OS_UNIX) 1332 const char* pipedir =
"/var/tmp";
1333 if(::stat(pipedir, &
st) != 0 || !S_ISDIR(
st.st_mode)
1334|| ::access(pipedir, W_OK) != 0) {
1336 if(::stat(pipedir, &
st) != 0 || !S_ISDIR(
st.st_mode)
1337|| ::access(pipedir, W_OK) != 0) {
1411 Create(pipename, timeout);
EIO_Status Status(EIO_Event direction) const
EIO_Status Open(const string &pipename, const STimeout *timeout, size_t pipesize, CNamedPipeClient::TFlags flags)
EIO_Status x_WaitForRead(const STimeout *timeout, DWORD *in_avail)
EIO_Status Close(bool close=true)
EIO_Status Read(void *buf, size_t count, size_t *n_read, const STimeout *timeout)
EIO_Status Listen(const STimeout *timeout)
EIO_Status x_Disconnect(bool orderly)
EIO_Status Disconnect(void)
EIO_Status Create(const string &pipename, size_t pipesize)
EIO_Status Wait(EIO_Event event, const STimeout *timeout)
EIO_Status Write(const void *buf, size_t count, size_t *n_written, const STimeout *timeout)
element_type * get(void) const
Get pointer.
@ eTakeOwnership
An object can take ownership of another.
@ eNoOwnership
No ownership is assumed.
#define ERR_POST_X(err_subcode, message)
Error posting with default error code and given error subcode.
@ eSocket
Socket (UNIX only)
CNamedPipeClient(size_t pipesize=0)
Default constructor.
const STimeout * m_OpenTimeout
Timeouts.
EIO_Status Create(const string &pipename, const STimeout *timeout=kDefaultTimeout, size_t pipesize=0)
Create a server-side pipe.
CNamedPipeServer(size_t pipesize=0)
Default constructor.
EIO_Status Wait(EIO_Event event, const STimeout *timeout)
Wait for I/O readiness in the pipe.
EIO_Status Status(EIO_Event direction) const
Return (for the specified "direction"): eIO_Closed â if the pipe is closed for I/O; eIO_Timeout â if ...
const STimeout * GetTimeout(EIO_Event event) const
Get the pipe I/O timeout (or NULL, if the timeout is infinite).
bool m_IsClientSide
client/server-side pipe
STimeout m_ReadTimeoutValue
storage for m_ReadTimeout
string m_PipeName
pipe name
EIO_Status Close(void)
Close pipe connection.
EIO_Status Listen(void)
Listen on a pipe for new client connection.
void x_SetName(const string &pipename)
STimeout m_OpenTimeoutValue
storage for m_OpenTimeout
size_t m_PipeSize
pipe size
virtual ~CNamedPipe()
Destructor.
CNamedPipe(size_t pipe_size=0)
Constructor.
const STimeout * m_WriteTimeout
eIO_Write
EIO_Status Read(void *buf, size_t count, size_t *n_read=0)
Read data from the pipe.
STimeout m_WriteTimeoutValue
storage for m_WriteTimeout
const STimeout * m_ReadTimeout
eIO_Read
EIO_Status SetTimeout(EIO_Event event, const STimeout *timeout)
Specify timeout for the pipe I/O (see Open|Read|Write functions).
CNamedPipeHandle * m_NamedPipeHandle
OS-specific handle.
EIO_Status Open(const string &pipename, const STimeout *timeout=kDefaultTimeout, size_t pipesize=0, TFlags flags=0)
Open a client-side pipe connection.
EIO_Status Disconnect(void)
Disconnect the client.
EIO_Status Write(const void *buf, size_t count, size_t *n_written=0)
Write data to the pipe.
@ fNoLogIfClosed
Do not log error if server end is closed.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
EIO_Status LSOCK_CreateUNIX(const char *path, unsigned short backlog, LSOCK *lsock, TSOCK_Flags flags)
EIO_Status SOCK_SetTimeout(SOCK sock, EIO_Event event, const STimeout *timeout)
Specify timeout for the connection I/O (see SOCK_[Read|Write|Close]()).
EIO_Status SOCK_Close(SOCK sock)
Close the SOCK handle, and destroy all relevant internal data.
EIO_Status LSOCK_Accept(LSOCK lsock, const STimeout *timeout, SOCK *sock)
[SERVER-side] Accept connection from a client.
EIO_Status SOCK_Read(SOCK sock, void *buf, size_t size, size_t *n_read, EIO_ReadMethod how)
Read/peek up to "size" bytes from "sock" to a buffer pointed to by "buf".
EIO_Status SOCK_Status(SOCK sock, EIO_Event direction)
Return low-level socket I/O status of *last* socket operation.
EIO_Status SOCK_Wait(SOCK sock, EIO_Event event, const STimeout *timeout)
Block on the socket until either the specified "event" is available or "timeout" expires (if "timeout...
EIO_Status SOCK_Write(SOCK sock, const void *data, size_t size, size_t *n_written, EIO_WriteMethod how)
Write "size" bytes of "data" to "sock".
EIO_Status LSOCK_Close(LSOCK lsock)
[SERVER-side] Close the listening socket, destroy relevant internal data.
EIO_Status SOCK_CreateUNIX(const char *path, const STimeout *timeout, SOCK *sock, const void *data, size_t size, TSOCK_Flags flags)
EIO_Status SOCK_GetOSHandle(SOCK sock, void *handle_buf, size_t handle_size)
Same as SOCK_GetOSHandleEx(sock, handle_buf, handle_size, eNoOwnership).
static enable_if< is_arithmetic< TNumeric >::value||is_convertible< TNumeric, Int8 >::value, string >::type NumericToString(TNumeric value, TNumToStringFlags flags=0, int base=10)
Convert numeric value to string.
static string & ToLower(string &str)
Convert string to lower case â string& version.
const long kMicroSecondsPerSecond
Number of microseconds in one second.
unsigned long NcbiTimeoutToMs(const STimeout *timeout)
unsigned int usec
microseconds (modulo 1,000,000)
const char * IO_StatusStr(EIO_Status status)
Get the text form of an enum status value.
const char * NcbiMessagePlusError(int *dynamic, const char *message, int error, const char *descr)
Add current "error" (and maybe its description) to the message: <message>[ {error=[[<error>][,...
EIO_Event
I/O event (or direction).
@ eIO_Timeout
timeout expired before any I/O succeeded
@ eIO_Success
everything is fine, no error occurred
@ eIO_Unknown
unknown I/O error (likely fatal but can retry)
@ 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
#define INVALID_HANDLE_VALUE
A value for an invalid file handle.
#define HANDLE
An abstraction for a file handle.
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).
static const STimeout kZeroTimeout
#define NAMEDPIPE_THROW(err, errtxt)
static string x_FormatError(int error, const string &message)
AutoPtr< char, CDeleter< char > > TTempCharPtr
static string s_FormatErrorMessage(const string &where, const string &what)
const unsigned long kWaitPrecision
static const STimeout * s_SetTimeout(const STimeout *from, STimeout *to)
static bool x_IsDisconnectError(DWORD error)
Portable interprocess named pipe API for: UNIX, MS-Win.
#define TRUE
bool replacment for C indicating true.
void SleepMilliSec(unsigned long ml_sec, EInterruptOnSignal onsignal=eRestartOnSignal)
Defines classes: CDirEntry, CFile, CDir, CSymLink, CMemoryFile, CFileUtil, CFileLock,...
static PCRE2_SIZE bufsize
static SLJIT_INLINE sljit_ins st(sljit_gpr r, sljit_s32 d, sljit_gpr x, sljit_gpr b)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4