NCBI C++ ToolKit
Public Member Functions | Public Attributes | Private Member Functions | List of all members
CSrvSocketTask Class Reference

Search Toolkit Book for CSrvSocketTask

Task controlling a socket. More...

#include "srv_sockets.hpp"
(Private to src/app/netcache.)

+ Inheritance diagram for CSrvSocketTask:
+ Collaboration diagram for CSrvSocketTask:

Public Member Functions

 CSrvSocketTask (void)
 
virtual ~CSrvSocketTask (void)
 
bool IsReadDataAvailable (void)
 Checks if there's some data available for reading in internal buffers. More...
 
bool IsWriteDataPending (void)
 Checks if there's some data pending in write buffers and waiting to be sent to kernel. More...
 
bool HasError (void)
 Checks if socket has some error in it. More...
 
bool CanHaveMoreRead (void)
 Checks if socket can ever have more data to read even though it may not have it at the moment. More...
 
bool NeedToClose (void)
 Checks if socket should be closed because of long inactivity or because server is in "hard" shutdown phase. More...
 
bool NeedEarlyClose (void)
 Checks if socket should be closed because of internal reasons (long inactivity or "hard" shutdown as in NeedToClose()) or because of external reasons, like error or EOF in the socket. More...
 
bool ReadToBuf (void)
 Read from socket into internal buffer. More...
 
size_t Read (void *buf, size_t size)
 Read from socket into memory. More...
 
bool ReadLine (CTempString *line)
 Read from socket one line which ends with '
', '\r
' or '\0'. More...
 
bool ReadData (void *buf, Uint2 size)
 Read from socket exactly the given data size. More...
 
template<typename NumType >
bool ReadNumber (NumType *num)
 Read from socket a number in native machine representation. More...
 
CSrvSocketTaskWriteText (CTempString message)
 Write text into socket. More...
 
template<typename NumType >
CSrvSocketTaskWriteNumber (NumType num)
 Write number into socket as string, i.e. More...
 
CSrvSocketTaskWriteBool (bool b)
 
void WriteData (const void *buf, size_t size)
 Write the exact amount of data into the socket. More...
 
size_t Write (const void *buf, size_t size)
 Write into the socket as much as immediately possible (including writing into internal write buffers and writing directly into socket) without blocking and without expanding write buffer. More...
 
void Flush (void)
 Flush all data saved in internal write buffers to socket. More...
 
void RequestFlush (void)
 Request flushing of all data saved in internal write buffers to socket. More...
 
bool FlushIsDone (void)
 Check if data flushing requested earlier is complete. More...
 
void StartProxyTo (CSrvSocketTask *dst_task, Uint8 proxy_size)
 Start proxying of raw data from this socket to the one in dst_task. More...
 
bool IsProxyInProgress (void)
 Check whether proxying started earlier is still in progress. More...
 
bool ProxyHadError (void)
 Check whether proxying started earlier finished successfully or any of sockets had some error in it. More...
 
bool Connect (Uint4 host, Uint2 port)
 Create new socket and connect it to given IP and port. More...
 
bool StartProcessing (TSrvThreadNum thread_num=0, bool boost=false)
 Start processing of the socket and include it into TaskServer's central epoll. More...
 
void CloseSocket (void)
 Close the socket gracefully, i.e. More...
 
void AbortSocket (void)
 Abort the socket, i.e. More...
 
void GetPeerAddress (string &host, Uint2 &port)
 Get peer IP and port for this socket. More...
 
Uint2 GetLocalPort (void)
 Get local port this socket was created on. More...
 
virtual void Terminate (void)
 Terminate the task. More...
 
- Public Member Functions inherited from CSrvTask
 CSrvTask (void)
 
void SetRunnable (bool boost=false)
 Set this task "runnable", i.e. More...
 
void RunAfter (Uint4 delay_sec)
 This call is basically equivalent to SetRunnable() but with guarantee that task will be scheduled for execution no earlier than delay_sec later (approximately, can be up to a second less if measured in absolute wall time). More...
 
void SetPriority (Uint4 prty)
 Set and retrieve task's priority. More...
 
Uint4 GetPriority (void)
 
void CreateNewDiagCtx (void)
 Create new diagnostic context for this task to work in. More...
 
void SetDiagCtx (CRequestContext *ctx)
 Set diagnostic context for this task to work in. More...
 
CRequestContextGetDiagCtx (void)
 Get current diagnostic context for the task. More...
 
void ReleaseDiagCtx (void)
 Releases current diagnostic context of the task. More...
 
virtual void ExecuteSlice (TSrvThreadNum thr_num)=0
 This is the main method to do all work this task should do. More...
 
virtual ~CSrvTask (void)
 

Public Attributes

CSrvSocketTaskm_ProxySrc
 Source task for proxying. More...
 
CSrvSocketTaskm_ProxyDst
 Destination task for proxying. More...
 
Uint8 m_ProxySize
 Amount left to proxy if proxying operation is in progress. More...
 
char * m_RdBuf
 Read buffer. More...
 
char * m_WrBuf
 Write buffer. More...
 
Uint8 m_ConnStartJfy
 Jiffy number when Connect() method was called. More...
 
int m_Fd
 File descriptor for the socket. More...
 
Uint2 m_RdSize
 Size of data available for reading in the read buffer. More...
 
Uint2 m_RdPos
 Position of current reading in the read buffer, i.e. More...
 
Uint2 m_WrMemSize
 Size of memory allocated for write buffer. More...
 
Uint2 m_WrSize
 Size of data in the write buffer waiting for writing. More...
 
Uint2 m_WrPos
 Position of current writing pointer in the write buffer. More...
 
bool m_CRMet
 Flag showing if '\r' symbol was seen at the end of last line but '
' wasn't seen yet. More...
 
bool m_ProxyHadError
 Flag showing that last proxying operation finished with error. More...
 
bool m_SockHasRead
 Flag showing that socket is readable. More...
 
bool m_SockCanWrite
 Flag showing that socket is writable. More...
 
bool m_SockCanReadMore
 Flag showing that socket can have more reads, i.e. there was no EOF yet. More...
 
bool m_NeedToClose
 Flag showing that socket needs to be closed because of long inactivity. More...
 
bool m_NeedToFlush
 Flag showing that task needs to flush all write buffers. More...
 
bool m_FlushIsDone
 Flag showing that write buffers were flushed. More...
 
Uint1 m_SeenReadEvts
 Number of last read event seen by Read() when it read from socket. More...
 
Uint1 m_SeenWriteEvts
 Number of last write event seen by Write() when it wrote to socket. More...
 
Uint8 m_ReadBytes
 Total number of bytes read from socket. More...
 
Uint8 m_WrittenBytes
 Total number of bytes written to socket. More...
 
Uint1 m_RegReadEvts
 Counter of "readable" events received from epoll. More...
 
Uint1 m_RegWriteEvts
 Counter of "writable" events received from epoll. More...
 
bool m_RegReadHup
 Flag showing if epoll returned RDHUP on this socket. More...
 
bool m_RegError
 Flag showing if there's error pending on the socket. More...
 
bool m_ErrorPrinted
 Flag showing if pending error in socket was printed in logs. More...
 
Uint2 m_PeerPort
 Remembered peer port. More...
 
Uint4 m_PeerAddr
 Remembered peer IP address. More...
 
string m_ConnReqId
 
- Public Attributes inherited from CSrvTask
TSrvTaskListHook m_TaskListHook
 Hook to put this task into TSrvTaskList. More...
 
TSrvThreadNum m_LastThread
 Thread number where this task was executed last time. More...
 
TSrvTaskFlags m_TaskFlags
 Bit-OR of flags for this task. More...
 
int m_LastActive
 Time (in seconds) when the task was active last time, i.e. More...
 
Uint4 m_Priority
 Task's priority. More...
 
CRequestContextm_DiagCtx
 Current diagnostic context for this task. More...
 
CRequestContext ** m_DiagChain
 Nested diagnostic contexts of this task. More...
 
size_t m_DiagChainSize
 
STimerTicketm_Timer
 Timer ticket assigned to this task when it calls RunAfter(). More...
 
CSrvTaskTerminator m_Terminator
 Object that will delete this task after call to Terminate(). More...
 
- Public Attributes inherited from SSrvSocketInfo
bool is_listening
 

Private Member Functions

 CSrvSocketTask (const CSrvSocketTask &)
 
CSrvSocketTaskoperator= (const CSrvSocketTask &)
 
virtual void InternalRunSlice (TSrvThreadNum thr_num)
 Internal function to execute time slice work. More...
 
void x_CloseSocket (bool do_abort)
 Close or abort the socket – they have little difference, thus they joined in one method. More...
 
void x_PrintError (void)
 Prints socket's error if there's any error pending on the socket. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from CSrvTask
static void PrintState (CSrvSocketTask &task)
 

Detailed Description

Task controlling a socket.

This task always becomes runnable in 3 cases:

Definition at line 101 of file srv_sockets.hpp.

Constructor & Destructor Documentation

◆ CSrvSocketTask() [1/2]

CSrvSocketTask::CSrvSocketTask ( void  )

◆ ~CSrvSocketTask()

CSrvSocketTask::~CSrvSocketTask ( void  )
virtual

Definition at line 1187 of file sockets_man.cpp.

References Critical(), free(), m_Fd, m_RdBuf, m_WrBuf, s_CloseSocket(), and SRV_LOG.

◆ CSrvSocketTask() [2/2]

CSrvSocketTask::CSrvSocketTask ( const CSrvSocketTask )
private

Member Function Documentation

◆ AbortSocket()

void CSrvSocketTask::AbortSocket ( void  )
inline

Abort the socket, i.e.

anything unsent in kernel buffers will be dropped.

Definition at line 472 of file srv_inlines.hpp.

References x_CloseSocket().

Referenced by CNCActiveHandler::x_StartProcessing().

◆ CanHaveMoreRead()

bool CSrvSocketTask::CanHaveMoreRead ( void  )
inline

Checks if socket can ever have more data to read even though it may not have it at the moment.

Socket won't have more data to read if EOF received.

Definition at line 382 of file srv_inlines.hpp.

References m_SockCanReadMore.

Referenced by NeedEarlyClose(), CNCMessageHandler::x_CloseCmdAndConn(), CNCMessageHandler::x_ReadAuthMessage(), CNCMessageHandler::x_ReadBlobChunkLength(), CNCMessageHandler::x_ReadCommand(), and CNCMessageHandler::x_StartCommand().

◆ CloseSocket()

void CSrvSocketTask::CloseSocket ( void  )
inline

Close the socket gracefully, i.e.

if any socket's data is still in kernel's buffers and didn't make it to wire it will be sent later. But internal task's write buffers won't be flushed.

Definition at line 466 of file srv_inlines.hpp.

References x_CloseSocket().

Referenced by Terminate(), and CNCMessageHandler::x_PrintCmdsCntAndClose().

◆ Connect()

bool CSrvSocketTask::Connect ( Uint4  host,
Uint2  port 
)

Create new socket and connect it to given IP and port.

If operation is successful TRUE is returned, FALSE returned otherwise. FALSE will be returned only in case of errors like network interface is down or things like that. If server is inaccessible then Connect() will return TRUE but later there will be error in the socket.

Definition at line 1425 of file sockets_man.cpp.

References AtomicAdd(), Critical(), GetCurThread(), GetLocalPort(), LOG_WITH_ERRNO, m_ConnStartJfy, m_Fd, m_RegError, s_CloseSocket(), s_CreateDiagRequest(), s_CurJiffies, s_SetSocketNonBlock(), s_SetSocketOptions(), s_TotalSockets, CSrvStat::SockOpenActive(), and SSrvThread::stat.

Referenced by CNCPeerControl::CreateNewSocket().

◆ Flush()

void CSrvSocketTask::Flush ( void  )

◆ FlushIsDone()

bool CSrvSocketTask::FlushIsDone ( void  )
inline

Check if data flushing requested earlier is complete.

Definition at line 428 of file srv_inlines.hpp.

References ACCESS_ONCE, and m_FlushIsDone.

Referenced by CNCActiveHandler::x_WaitOneLineAnswer().

◆ GetLocalPort()

Uint2 CSrvSocketTask::GetLocalPort ( void  )

Get local port this socket was created on.

Definition at line 1496 of file sockets_man.cpp.

References Critical(), len, LOG_WITH_ERRNO, and m_Fd.

Referenced by Connect(), and CNCMessageHandler::x_SocketOpened().

◆ GetPeerAddress()

void CSrvSocketTask::GetPeerAddress ( string host,
Uint2 port 
)

Get peer IP and port for this socket.

Definition at line 1512 of file sockets_man.cpp.

References CTaskServer::IPToString(), m_PeerAddr, and m_PeerPort.

Referenced by CNCMessageHandler::x_SocketOpened().

◆ HasError()

bool CSrvSocketTask::HasError ( void  )
inline

◆ InternalRunSlice()

void CSrvSocketTask::InternalRunSlice ( TSrvThreadNum  thr_num)
privatevirtual

◆ IsProxyInProgress()

bool CSrvSocketTask::IsProxyInProgress ( void  )
inline

Check whether proxying started earlier is still in progress.

Definition at line 454 of file srv_inlines.hpp.

References m_ProxyDst, and m_ProxySrc.

Referenced by CNCActiveHandler_Proxy::ExecuteSlice(), CNCActiveHandler_Proxy::SocketProxyDone(), and CNCMessageHandler::x_ReadBlobChunkLength().

◆ IsReadDataAvailable()

bool CSrvSocketTask::IsReadDataAvailable ( void  )
inline

Checks if there's some data available for reading in internal buffers.

Method doesn't say anything about data available in socket but not yet retrieved from kernel.

Definition at line 360 of file srv_inlines.hpp.

References m_RdPos, and m_RdSize.

Referenced by CNCMessageHandler::x_ReadAuthMessage(), and CNCMessageHandler::x_ReadCommand().

◆ IsWriteDataPending()

bool CSrvSocketTask::IsWriteDataPending ( void  )
inline

Checks if there's some data pending in write buffers and waiting to be sent to kernel.

Definition at line 366 of file srv_inlines.hpp.

References m_WrPos, and m_WrSize.

Referenced by Flush(), InternalRunSlice(), and Write().

◆ NeedEarlyClose()

bool CSrvSocketTask::NeedEarlyClose ( void  )
inline

Checks if socket should be closed because of internal reasons (long inactivity or "hard" shutdown as in NeedToClose()) or because of external reasons, like error or EOF in the socket.

Definition at line 394 of file srv_inlines.hpp.

References CanHaveMoreRead(), HasError(), and NeedToClose().

Referenced by InternalRunSlice(), s_DoDataProxy(), CNCMessageHandler::x_DoCmd_Get(), CNCMessageHandler::x_DoCmd_GetLast(), CNCMessageHandler::x_DoCmd_SyncBlobsList(), CNCMessageHandler::x_DoCmd_SyncGet(), CNCMessageHandler::x_DoCmd_SyncStart(), CNCActiveHandler::x_ExecuteProInfoCmd(), CNCActiveHandler::x_FinishBlobFromClient(), CNCMessageHandler::x_FinishReadingBlob(), CNCActiveHandler::x_FinishWritingBlob(), CNCActiveHandler::x_PrepareSyncProlongCmd(), CNCMessageHandler::x_ProxyToNextPeer(), CNCMessageHandler::x_PurgeToNextPeer(), CNCActiveHandler::x_PutSelfToPool(), CNCMessageHandler::x_PutToNextPeer(), CNCMessageHandler::x_ReadBlobChunk(), CNCMessageHandler::x_ReadBlobChunkLength(), CNCActiveHandler::x_ReadBlobData(), CNCMessageHandler::x_ReadBlobSignature(), CNCActiveHandler::x_ReadBlobsListBody(), CNCActiveHandler::x_ReadBlobsListKeySize(), CNCActiveHandler::x_ReadCopyProlong(), CNCActiveHandler::x_ReadCopyPut(), CNCActiveHandler::x_ReadDataForClient(), CNCActiveHandler::x_ReadDataPrefix(), CNCActiveHandler::x_ReadEventsListBody(), CNCActiveHandler::x_ReadEventsListKeySize(), CNCActiveHandler::x_ReadHttpDataPrefix(), CNCMessageHandler::x_ReadMetaNextPeer(), CNCMessageHandler::x_ReadMetaResults(), CNCMessageHandler::x_ReadPurgeResults(), CNCMessageHandler::x_ReadPutResults(), CNCActiveHandler::x_ReadSyncProInfoAnswer(), CNCActiveHandler::x_ReadSyncStartExtra(), CNCMessageHandler::x_SendCmdAsProxy(), CNCActiveHandler::x_SendCmdToExecute(), CNCActiveHandler::x_SendCopyPutCmd(), CNCMessageHandler::x_SendGetMetaCmd(), CNCMessageHandler::x_SendPurgeToPeerCmd(), CNCMessageHandler::x_SendPutToPeerCmd(), CNCActiveHandler::x_SendSyncGetCmd(), CNCMessageHandler::x_StartReadingBlob(), CNCMessageHandler::x_WaitForBlobAccess(), CNCActiveHandler::x_WaitForMetaInfo(), CNCMessageHandler::x_WaitForPeerAnswer(), CNCActiveHandler::x_WaitOneLineAnswer(), CNCActiveHandler::x_WriteBlobData(), CNCMessageHandler::x_WriteBlobData(), CNCMessageHandler::x_WriteFullBlobsList(), CNCMessageHandler::x_WriteInitWriteResponse(), and CNCMessageHandler::x_WriteSendBuff().

◆ NeedToClose()

bool CSrvSocketTask::NeedToClose ( void  )
inline

Checks if socket should be closed because of long inactivity or because server is in "hard" shutdown phase.

User code should always check result of this method at some pivot points where it has the ability to close.

Definition at line 388 of file srv_inlines.hpp.

References CTaskServer::IsInHardShutdown(), and m_NeedToClose.

Referenced by NeedEarlyClose(), CNCActiveHandler::x_CloseCmdAndConn(), CNCActiveHandler::x_ConnClosedReplaceable(), CNCMessageHandler::x_ReadAuthMessage(), CNCMessageHandler::x_ReadCommand(), CNCActiveHandler::x_SendCmdToExecute(), and CNCMessageHandler::x_StartCommand().

◆ operator=()

CSrvSocketTask& CSrvSocketTask::operator= ( const CSrvSocketTask )
private

◆ ProxyHadError()

bool CSrvSocketTask::ProxyHadError ( void  )
inline

Check whether proxying started earlier finished successfully or any of sockets had some error in it.

Definition at line 460 of file srv_inlines.hpp.

References m_ProxyHadError.

Referenced by CNCMessageHandler::x_ReadBlobChunkLength(), and CNCActiveHandler::x_ReadDataForClient().

◆ Read()

size_t CSrvSocketTask::Read ( void *  buf,
size_t  size 
)

Read from socket into memory.

Method combines reading from internal buffer and directly from socket (without changing data order) and reads as much as possible to do without blocking. Method returns total size of read data (can be 0 if no data immediately available).

Definition at line 1250 of file sockets_man.cpp.

References buf, kSockReadBufSize, m_RdPos, m_RdSize, ReadToBuf(), s_ReadFromBuffer(), s_ReadFromSocket(), and ncbi::grid::netcache::search::fields::size.

Referenced by CNCMessageHandler::x_ReadBlobChunk(), and CNCActiveHandler::x_ReadBlobData().

◆ ReadData()

bool CSrvSocketTask::ReadData ( void *  buf,
Uint2  size 
)
inline

Read from socket exactly the given data size.

If given size is not immediately available (without blocking) method doesn't read anything and returns FALSE. Otherwise data is copied to buf and TRUE is returned. Requested size must be less than internal read buffer.

Definition at line 434 of file srv_inlines.hpp.

References buf, m_RdBuf, m_RdPos, m_RdSize, ReadToBuf(), and ncbi::grid::netcache::search::fields::size.

Referenced by ReadNumber(), CNCActiveHandler::x_ReadBlobsListBody(), and CNCActiveHandler::x_ReadEventsListBody().

◆ ReadLine()

bool CSrvSocketTask::ReadLine ( CTempString line)

Read from socket one line which ends with '
', '\r
' or '\0'.

Line read should fit into internal read buffer, i.e. it shouldn't be too long, otherwise method returns FALSE and raises error flag which means you won't be able to anything else with socket (besides closing). Method returns TRUE if line was successfully read and FALSE if there's no data or no line end markers in it. When method returned TRUE variable line will point to internal read buffer. Thus it should be used before calling any other Read*() methods – after that memory can become invalid.

Definition at line 1219 of file sockets_man.cpp.

References CTempString::assign(), kSockReadBufSize, m_CRMet, m_RdBuf, m_RdPos, m_RdSize, m_RegError, ReadToBuf(), s_ReadLF(), SRV_LOG, and Warning().

Referenced by CNCMessageHandler::x_AssignCmdParams(), CNCMessageHandler::x_ReadAuthMessage(), CNCMessageHandler::x_ReadCommand(), CNCActiveHandler::x_ReadHttpDataPrefix(), CNCActiveHandler::x_ReadSyncStartExtra(), and CNCActiveHandler::x_WaitOneLineAnswer().

◆ ReadNumber()

template<typename NumType >
bool CSrvSocketTask::ReadNumber ( NumType *  num)
inline

Read from socket a number in native machine representation.

If sizeof(NumType) bytes is not immediately available in the socket method returns FALSE and doesn't read anything. Otherwise it copies data into num and returns TRUE.

Definition at line 448 of file srv_inlines.hpp.

References ReadData().

Referenced by CNCMessageHandler::x_ReadBlobChunkLength(), CNCMessageHandler::x_ReadBlobSignature(), CNCActiveHandler::x_ReadBlobsListKeySize(), and CNCActiveHandler::x_ReadEventsListKeySize().

◆ ReadToBuf()

bool CSrvSocketTask::ReadToBuf ( void  )

Read from socket into internal buffer.

Method tries to completely fill the buffer even if there's some data already waiting in it.

Definition at line 1207 of file sockets_man.cpp.

References kSockReadBufSize, m_CRMet, m_RdBuf, m_RdPos, m_RdSize, s_CompactBuffer(), s_ReadFromSocket(), and s_ReadLF().

Referenced by Read(), ReadData(), ReadLine(), and s_DoDataProxy().

◆ RequestFlush()

void CSrvSocketTask::RequestFlush ( void  )
inline

Request flushing of all data saved in internal write buffers to socket.

Method can be called from anywhere even concurrently with ExecuteSlice() of this task. No other writing methods should be called until FlushIsDone() returns TRUE.

Definition at line 420 of file srv_inlines.hpp.

References ACCESS_ONCE, m_FlushIsDone, m_NeedToFlush, and CSrvTask::SetRunnable().

Referenced by CNCActiveHandler::x_FinishWritingBlob(), and CNCActiveHandler::x_SendCmdToExecute().

◆ StartProcessing()

bool CSrvSocketTask::StartProcessing ( TSrvThreadNum  thread_num = 0,
bool  boost = false 
)

Start processing of the socket and include it into TaskServer's central epoll.

Until this method is called TaskServer won't make this task runnable and won't check if it's readable or writable – any Read/Write operation will be unsuccessful (processing 0 bytes).

Definition at line 1475 of file sockets_man.cpp.

References Critical(), EPOLLIN, EPOLLOUT, GetCurThread(), LOG_WITH_ERRNO, m_Fd, CSrvTask::m_LastThread, s_EpollFD, s_SaveSocket(), CSrvTask::SetRunnable(), and SSrvThread::thread_num.

Referenced by s_ProcessListenEvent(), and CNCActiveHandler::x_StartProcessing().

◆ StartProxyTo()

void CSrvSocketTask::StartProxyTo ( CSrvSocketTask dst_task,
Uint8  proxy_size 
)

Start proxying of raw data from this socket to the one in dst_task.

Method must be called from inside of ExecuteSlice() of this task. And nothing else should be done with both sockets until IsProxyInProgress() returns FALSE. Only proxy_size bytes is transferred between sockets. Proxying can stop earlier only if NeedEarlyClose() on either socket returns true. In this case ProxyHadError() will return true and nothing else could be done with sockets except closing.

Definition at line 1349 of file sockets_man.cpp.

References m_ProxyDst, m_ProxyHadError, m_ProxySize, m_ProxySrc, and s_DoDataProxy().

Referenced by CNCActiveHandler_Proxy::ExecuteSlice(), and CNCMessageHandler::x_ReadBlobChunkLength().

◆ Terminate()

void CSrvSocketTask::Terminate ( void  )
virtual

Terminate the task.

Method is overridden here to add some extra processing for sockets.

Reimplemented from CSrvTask.

Definition at line 1528 of file sockets_man.cpp.

References CloseSocket(), m_Fd, and MarkTaskTerminated().

Referenced by CNCActiveHandler_Proxy::ExecuteSlice(), s_ProcessListenEvent(), and CNCMessageHandler::x_PrintCmdsCntAndClose().

◆ Write()

size_t CSrvSocketTask::Write ( const void *  buf,
size_t  size 
)

Write into the socket as much as immediately possible (including writing into internal write buffers and writing directly into socket) without blocking and without expanding write buffer.

Method returns amount of data written which can be 0 if socket is not writable at the moment.

Definition at line 1273 of file sockets_man.cpp.

References buf, IsWriteDataPending(), kSockMinWriteSize, kSockWriteBufSize, m_WrPos, m_WrSize, s_CompactWrBuffer(), s_CopyData(), s_FlushData(), s_WriteNoPending(), s_WriteToSocket(), and ncbi::grid::netcache::search::fields::size.

Referenced by s_DoDataProxy(), CNCActiveHandler::x_WriteBlobData(), CNCMessageHandler::x_WriteBlobData(), CNCMessageHandler::x_WriteHttpResponse(), and CNCMessageHandler::x_WriteSendBuff().

◆ WriteBool()

CSrvSocketTask & CSrvSocketTask::WriteBool ( bool  b)
inline

◆ WriteData()

void CSrvSocketTask::WriteData ( const void *  buf,
size_t  size 
)

Write the exact amount of data into the socket.

All the data will be written, internal write buffer will be expanded to accommodate it if necessary.

Definition at line 1323 of file sockets_man.cpp.

References buf, m_WrBuf, m_WrMemSize, m_WrSize, max(), s_CopyData(), ncbi::grid::netcache::search::fields::size, and SRV_FATAL.

Referenced by WriteText(), CNCActiveHandler::x_FinishWritingBlob(), CNCMessageHandler::x_ReadBlobChunkLength(), CNCActiveHandler::x_StartWritingBlob(), and CNCActiveHandler::x_WriteBlobData().

◆ WriteNumber()

template<typename NumType >
CSrvSocketTask & CSrvSocketTask::WriteNumber ( NumType  num)
inline

◆ WriteText()

CSrvSocketTask & CSrvSocketTask::WriteText ( CTempString  message)
inline

Write text into socket.

The whole text message will be written, internal write buffer will be expanded to accommodate the message if necessary.

Definition at line 400 of file srv_inlines.hpp.

References CTempString::data(), CTempString::size(), and WriteData().

Referenced by CNCMessageHandler::BeginProxyResponse(), CSrvPrintProxy::operator<<(), CNCStat::PrintState(), CSrvStat::PrintState(), SMMStat::PrintState(), CNCPeerControl::PrintState(), CNCPeerControl::PrintSyncStat(), NCAlertData::Report(), CNCAlerts::Report(), CNCActiveHandler::SetProxy(), CNCBlobStorage::WriteBlobStat(), WriteBool(), CNCDistributionConf::WriteEnvInfo(), CNCBlobStorage::WriteEnvInfo(), CNCServer::WriteEnvInfo(), WriteNumber(), CNCDistributionConf::WriteSetup(), CNCBlobStorage::WriteSetup(), CTaskServer::WriteSetup(), WriteSetup_Logging(), WriteSetup_Scheduler(), WriteSetup_Sockets(), WriteSetup_Threads(), WriteSetup_TimeMan(), CNCMessageHandler::x_CleanCmdResources(), CNCMessageHandler::x_DoCmd_CopyPut(), CNCMessageHandler::x_DoCmd_Get(), CNCMessageHandler::x_DoCmd_GetBList(), CNCMessageHandler::x_DoCmd_GetConfig(), CNCMessageHandler::x_DoCmd_GetLast(), CNCMessageHandler::x_DoCmd_GetMeta(), CNCMessageHandler::x_DoCmd_GetSize(), CNCMessageHandler::x_DoCmd_HasBlob(), CNCMessageHandler::x_DoCmd_Health(), CNCMessageHandler::x_DoCmd_IC_Store(), CNCMessageHandler::x_DoCmd_Prolong(), CNCMessageHandler::x_DoCmd_ProxyMeta(), CNCMessageHandler::x_DoCmd_Put(), CNCMessageHandler::x_DoCmd_SetValid(), CNCMessageHandler::x_DoCmd_SyncBlobsList(), CNCMessageHandler::x_DoCmd_SyncGet(), CNCMessageHandler::x_DoCmd_SyncProlongInfo(), CNCMessageHandler::x_DoCmd_SyncStart(), CNCMessageHandler::x_DoCmd_Version(), CNCMessageHandler::x_ReportBlobNotFound(), CNCMessageHandler::x_ReportError(), CNCMessageHandler::x_ReportOK(), CNCActiveHandler::x_SendCmdToExecute(), CNCMessageHandler::x_WriteHttpHeader(), CNCMessageHandler::x_WriteHttpResponse(), CNCMessageHandler::x_WriteInitWriteResponse(), and CNCMessageHandler::x_WriteSyncStartExtra().

◆ x_CloseSocket()

void CSrvSocketTask::x_CloseSocket ( bool  do_abort)
private

Close or abort the socket – they have little difference, thus they joined in one method.

Definition at line 1519 of file sockets_man.cpp.

References m_Fd, s_CleanSockResources(), and s_CloseSocket().

Referenced by AbortSocket(), and CloseSocket().

◆ x_PrintError()

void CSrvSocketTask::x_PrintError ( void  )
private

Prints socket's error if there's any error pending on the socket.

Definition at line 1198 of file sockets_man.cpp.

References LOG_SOCK_ERROR, m_ErrorPrinted, m_Fd, and Warning().

Referenced by HasError().

Member Data Documentation

◆ m_ConnReqId

string CSrvSocketTask::m_ConnReqId

Definition at line 348 of file srv_sockets.hpp.

Referenced by s_CreateDiagRequest(), and CNCMessageHandler::x_PrintRequestStart().

◆ m_ConnStartJfy

Uint8 CSrvSocketTask::m_ConnStartJfy

Jiffy number when Connect() method was called.

Variable is used to track connection timeouts.

Definition at line 281 of file srv_sockets.hpp.

Referenced by CheckConnectsTimeout(), Connect(), and InternalRunSlice().

◆ m_CRMet

bool CSrvSocketTask::m_CRMet

Flag showing if '\r' symbol was seen at the end of last line but '
' wasn't seen yet.

Definition at line 299 of file srv_sockets.hpp.

Referenced by ReadLine(), ReadToBuf(), and s_ReadLF().

◆ m_ErrorPrinted

bool CSrvSocketTask::m_ErrorPrinted

Flag showing if pending error in socket was printed in logs.

Definition at line 340 of file srv_sockets.hpp.

Referenced by x_PrintError().

◆ m_Fd

int CSrvSocketTask::m_Fd

◆ m_FlushIsDone

bool CSrvSocketTask::m_FlushIsDone

Flag showing that write buffers were flushed.

Definition at line 314 of file srv_sockets.hpp.

Referenced by FlushIsDone(), InternalRunSlice(), and RequestFlush().

◆ m_NeedToClose

bool CSrvSocketTask::m_NeedToClose

Flag showing that socket needs to be closed because of long inactivity.

Definition at line 310 of file srv_sockets.hpp.

Referenced by CNCActiveHandler::CheckCommandTimeout(), NeedToClose(), and s_DeleteOldestSockets().

◆ m_NeedToFlush

bool CSrvSocketTask::m_NeedToFlush

Flag showing that task needs to flush all write buffers.

Definition at line 312 of file srv_sockets.hpp.

Referenced by Flush(), InternalRunSlice(), and RequestFlush().

◆ m_PeerAddr

Uint4 CSrvSocketTask::m_PeerAddr

Remembered peer IP address.

Value valid only for sockets created from listening sockets.

Definition at line 346 of file srv_sockets.hpp.

Referenced by GetPeerAddress(), and s_ProcessListenEvent().

◆ m_PeerPort

Uint2 CSrvSocketTask::m_PeerPort

Remembered peer port.

Value valid only for sockets created from listening sockets.

Definition at line 343 of file srv_sockets.hpp.

Referenced by GetPeerAddress(), and s_ProcessListenEvent().

◆ m_ProxyDst

CSrvSocketTask* CSrvSocketTask::m_ProxyDst

Destination task for proxying.

This variable is set to non-NULL value only in source tasks for proxying.

Definition at line 267 of file srv_sockets.hpp.

Referenced by InternalRunSlice(), IsProxyInProgress(), s_DoDataProxy(), and StartProxyTo().

◆ m_ProxyHadError

bool CSrvSocketTask::m_ProxyHadError

Flag showing that last proxying operation finished with error.

Definition at line 301 of file srv_sockets.hpp.

Referenced by ProxyHadError(), s_DoDataProxy(), and StartProxyTo().

◆ m_ProxySize

Uint8 CSrvSocketTask::m_ProxySize

Amount left to proxy if proxying operation is in progress.

Value is set only in source tasks for proxying.

Definition at line 270 of file srv_sockets.hpp.

Referenced by s_DoDataProxy(), and StartProxyTo().

◆ m_ProxySrc

CSrvSocketTask* CSrvSocketTask::m_ProxySrc

Source task for proxying.

This variable is set to non-NULL value only in destination tasks for proxying.

Definition at line 263 of file srv_sockets.hpp.

Referenced by InternalRunSlice(), IsProxyInProgress(), s_DoDataProxy(), and StartProxyTo().

◆ m_RdBuf

char* CSrvSocketTask::m_RdBuf

◆ m_RdPos

Uint2 CSrvSocketTask::m_RdPos

Position of current reading in the read buffer, i.e.

all data in [0, m_RdPos) was already read; data in [m_RdPos, m_RdSize) are queued for reading.

Definition at line 289 of file srv_sockets.hpp.

Referenced by IsReadDataAvailable(), Read(), ReadData(), ReadLine(), ReadToBuf(), s_DoDataProxy(), s_ReadFromBuffer(), and s_ReadLF().

◆ m_RdSize

Uint2 CSrvSocketTask::m_RdSize

Size of data available for reading in the read buffer.

Definition at line 285 of file srv_sockets.hpp.

Referenced by IsReadDataAvailable(), Read(), ReadData(), ReadLine(), ReadToBuf(), s_DoDataProxy(), s_ReadFromBuffer(), and s_ReadLF().

◆ m_ReadBytes

Uint8 CSrvSocketTask::m_ReadBytes

Total number of bytes read from socket.

Definition at line 328 of file srv_sockets.hpp.

Referenced by s_CleanSockResources(), s_CreateDiagRequest(), and s_ReadFromSocket().

◆ m_RegError

bool CSrvSocketTask::m_RegError

Flag showing if there's error pending on the socket.

Definition at line 338 of file srv_sockets.hpp.

Referenced by CheckConnectsTimeout(), Connect(), HasError(), InternalRunSlice(), ReadLine(), s_ReadFromSocket(), s_RegisterClientEvent(), and s_WriteToSocket().

◆ m_RegReadEvts

Uint1 CSrvSocketTask::m_RegReadEvts

Counter of "readable" events received from epoll.

Definition at line 332 of file srv_sockets.hpp.

Referenced by InternalRunSlice(), s_ReadFromSocket(), and s_RegisterClientEvent().

◆ m_RegReadHup

bool CSrvSocketTask::m_RegReadHup

Flag showing if epoll returned RDHUP on this socket.

Definition at line 336 of file srv_sockets.hpp.

Referenced by s_ReadFromSocket(), and s_RegisterClientEvent().

◆ m_RegWriteEvts

Uint1 CSrvSocketTask::m_RegWriteEvts

Counter of "writable" events received from epoll.

Definition at line 334 of file srv_sockets.hpp.

Referenced by CheckConnectsTimeout(), InternalRunSlice(), s_RegisterClientEvent(), and s_WriteToSocket().

◆ m_SeenReadEvts

Uint1 CSrvSocketTask::m_SeenReadEvts

Number of last read event seen by Read() when it read from socket.

If this number is equal to m_RegReadEvts then no new "readable" events came from epoll and thus result of last read defines if there is more data in the socket to read (if last read returned less data than provided buffer size then there's no more data in the socket).

Definition at line 320 of file srv_sockets.hpp.

Referenced by InternalRunSlice(), s_ReadFromSocket(), and s_RegisterClientEvent().

◆ m_SeenWriteEvts

Uint1 CSrvSocketTask::m_SeenWriteEvts

Number of last write event seen by Write() when it wrote to socket.

If this number is equal to m_RegWriteEvts then no new "writable" events came from epoll and thus result of last write defines if more data can be written in the socket (if last write have written less data than provided buffer size then nothing else can be written in the socket).

Definition at line 326 of file srv_sockets.hpp.

Referenced by CheckConnectsTimeout(), InternalRunSlice(), s_RegisterClientEvent(), and s_WriteToSocket().

◆ m_SockCanReadMore

bool CSrvSocketTask::m_SockCanReadMore

Flag showing that socket can have more reads, i.e. there was no EOF yet.

Definition at line 307 of file srv_sockets.hpp.

Referenced by CanHaveMoreRead(), InternalRunSlice(), and s_ReadFromSocket().

◆ m_SockCanWrite

bool CSrvSocketTask::m_SockCanWrite

Flag showing that socket is writable.

Definition at line 305 of file srv_sockets.hpp.

Referenced by s_WriteToSocket().

◆ m_SockHasRead

bool CSrvSocketTask::m_SockHasRead

Flag showing that socket is readable.

Definition at line 303 of file srv_sockets.hpp.

Referenced by InternalRunSlice(), and s_ReadFromSocket().

◆ m_WrBuf

char* CSrvSocketTask::m_WrBuf

◆ m_WrittenBytes

Uint8 CSrvSocketTask::m_WrittenBytes

Total number of bytes written to socket.

Definition at line 330 of file srv_sockets.hpp.

Referenced by s_CleanSockResources(), s_CreateDiagRequest(), and s_WriteToSocket().

◆ m_WrMemSize

Uint2 CSrvSocketTask::m_WrMemSize

Size of memory allocated for write buffer.

This size can grow in methods requiring exact writing like WriteData(), WriteText() etc.

Definition at line 292 of file srv_sockets.hpp.

Referenced by s_DoDataProxy(), and WriteData().

◆ m_WrPos

Uint2 CSrvSocketTask::m_WrPos

Position of current writing pointer in the write buffer.

Definition at line 296 of file srv_sockets.hpp.

Referenced by IsWriteDataPending(), s_CompactWrBuffer(), s_FlushData(), and Write().

◆ m_WrSize

Uint2 CSrvSocketTask::m_WrSize

Size of data in the write buffer waiting for writing.

Definition at line 294 of file srv_sockets.hpp.

Referenced by IsWriteDataPending(), s_CompactWrBuffer(), s_CopyData(), s_DoDataProxy(), s_FlushData(), Write(), and WriteData().


The documentation for this class was generated from the following files:
Modified on Mon Jul 22 05:05:34 2024 by modify_doxy.py rev. 669887