NCBI C++ ToolKit
Classes | Macros | Typedefs | Functions | Variables
sockets_man.cpp File Reference
#include "task_server_pch.hpp"
#include <corelib/request_ctx.hpp>
#include <corelib/ncbireg.hpp>
#include "sockets_man.hpp"
#include "threads_man.hpp"
#include "srv_stat.hpp"
+ Include dependency graph for sockets_man.cpp:

Go to the source code of this file.

Go to the SVN repository for this file.

Classes

struct  SSocketsData
 Per-thread structure containing information about sockets. More...
 
struct  SListenSockInfo
 
class  CSrvListener
 

Macros

#define EPOLLIN   0x0001
 
#define EPOLLOUT   0x0004
 
#define EPOLLERR   0x0008
 
#define EPOLLHUP   0x0010
 
#define EPOLLRDHUP   0x2000
 
#define LOG_WITH_ERRNO(sev, msg, x_errno)
 
#define LOG_SOCK_ERROR(sev, fd, prefix)    s_LogSocketError(CSrvDiagMsg::sev, fd, prefix, __FILE__, __LINE__, NCBI_CURRENT_FUNCTION)
 

Typedefs

typedef intr::list< CSrvSocketTask, intr::base_hook< TSrvSockListHook >, intr::constant_time_size< false > > TSockList
 

Functions

void ConfigureSockets (const CNcbiRegistry *reg, CTempString section)
 
bool ReConfig_Sockets (const CTempString &section, const CNcbiRegistry &new_reg, string &)
 
void WriteSetup_Sockets (CSrvSocketTask &task)
 
void AssignThreadSocks (SSrvThread *thr)
 
void ReleaseThreadSocks (SSrvThread *thr)
 
static void s_LogWithErrStr (CSrvDiagMsg::ESeverity severity, const char *err_msg, int x_errno, const char *errno_str, const char *file, int line, const char *func)
 
static void s_LogWithErrno (CSrvDiagMsg::ESeverity severity, const char *err_msg, int x_errno, const char *file, int line, const char *func)
 
static bool s_SetSocketNonBlock (int sock)
 
static bool s_SetSocketOptions (int sock)
 
static void s_SetSocketQuickAck (int sock)
 
static bool s_CreateListeningSocket (Uint1 idx)
 
static bool s_StartListening (void)
 
static void s_RegisterListenEvent (SListenSockInfo *sock_info, Uint4 event)
 
static void s_RegisterClientEvent (CSrvSocketTask *task, Uint4 event)
 
static void s_LogSocketError (CSrvDiagMsg::ESeverity severity, int fd, const char *prefix, const char *file, int line, const char *func)
 
static void s_CloseSocket (int fd, bool do_abort)
 
static void s_CleanSockResources (CSrvSocketTask *task)
 
static void s_CreateDiagRequest (CSrvSocketTask *task, Uint2 port, Uint4 phost, Uint2 pport)
 
static void s_ProcessListenError (Uint1 sock_idx)
 
static void s_ProcessListenEvent (Uint1 sock_idx, TSrvThreadNum thread_num)
 
void DoSocketWait (void)
 
bool InitSocketsMan (void)
 
bool StartSocketsMan (void)
 
void FinalizeSocketsMan (void)
 
static void s_SaveSocket (CSrvSocketTask *task)
 
void s_DeleteOldestSockets (TSockList &lst)
 
void MoveAllSockets (SSocketsData *dst_socks, SSocketsData *src_socks)
 
void PromoteSockAmount (SSocketsData *socks)
 
void CheckConnectsTimeout (SSocketsData *socks)
 
void CleanSocketList (SSocketsData *socks)
 
void SetAllSocksRunnable (SSocketsData *socks)
 
void RequestStopListening (void)
 
static size_t s_ReadFromSocket (CSrvSocketTask *task, void *buf, size_t size)
 
static size_t s_WriteToSocket (CSrvSocketTask *task, const void *buf, size_t size)
 
static void s_CompactBuffer (char *buf, Uint2 &size, Uint2 &pos)
 
static void s_ReadLF (CSrvSocketTask *task)
 
static Uint2 s_ReadFromBuffer (CSrvSocketTask *task, void *dest, size_t size)
 
static void s_CopyData (CSrvSocketTask *task, const void *buf, Uint2 size)
 
static size_t s_WriteNoPending (CSrvSocketTask *task, const void *buf, size_t size)
 
static void s_FlushData (CSrvSocketTask *task)
 
static void s_CompactWrBuffer (CSrvSocketTask *task)
 
static void s_DoDataProxy (CSrvSocketTask *src)
 

Variables

static const Uint1 kEpollEventsArraySize = 100
 
static const Uint2 kSockReadBufSize = 1000
 1000 below is chosen to be a little bit less than maximum packet size in Ethernet (~1500 bytes). More...
 
static const Uint2 kSockMinWriteSize = 1000
 
static const Uint2 kSockWriteBufSize = 2000
 In calculations in the file it's assumed that kSockWriteBufSize is at least twice as large as kSockMinWriteSize. More...
 
static const Uint1 kMaxCntListeningSocks = 16
 16 Uint4s on x86_64 is the size of CPU's cacheline. More...
 
static SListenSockInfo s_ListenSocks [kMaxCntListeningSocks]
 
static Uint1 s_CntListeningSocks = 0
 
static CMiniMutex s_ListenSocksLock
 
static Uint4 s_ListenEvents [kMaxCntListeningSocks]
 
static Uint4 s_ListenErrors [kMaxCntListeningSocks]
 
static CSrvListener s_Listener
 
static int s_EpollFD = -1
 
int s_TotalSockets = 0
 
int s_AllSocketsCount = 0
 
int s_SoftSocketLimit = 0
 
int s_HardSocketLimit = 0
 
static int s_SocketTimeout = 0
 
static Uint1 s_OldSocksDelBatch = 0
 
static Uint8 s_ConnTimeout = 10
 
static string s_HostName
 
static Uint8 s_AcceptDelay = 1000000
 
Uint8 s_CurJiffies
 
CSrvTime s_JiffyTime
 
SSrvThread ** s_Threads
 

Macro Definition Documentation

◆ EPOLLERR

#define EPOLLERR   0x0008

Definition at line 63 of file sockets_man.cpp.

◆ EPOLLHUP

#define EPOLLHUP   0x0010

Definition at line 64 of file sockets_man.cpp.

◆ EPOLLIN

#define EPOLLIN   0x0001

Definition at line 61 of file sockets_man.cpp.

◆ EPOLLOUT

#define EPOLLOUT   0x0004

Definition at line 62 of file sockets_man.cpp.

◆ EPOLLRDHUP

#define EPOLLRDHUP   0x2000

Definition at line 65 of file sockets_man.cpp.

◆ LOG_SOCK_ERROR

#define LOG_SOCK_ERROR (   sev,
  fd,
  prefix 
)     s_LogSocketError(CSrvDiagMsg::sev, fd, prefix, __FILE__, __LINE__, NCBI_CURRENT_FUNCTION)

Definition at line 422 of file sockets_man.cpp.

◆ LOG_WITH_ERRNO

#define LOG_WITH_ERRNO (   sev,
  msg,
  x_errno 
)
Value:
s_LogWithErrno(CSrvDiagMsg::sev, msg, x_errno, \
__FILE__, __LINE__, NCBI_CURRENT_FUNCTION) \
#define NCBI_CURRENT_FUNCTION
Get current function name.
Definition: ncbidiag.hpp:142
static void s_LogWithErrno(CSrvDiagMsg::ESeverity severity, const char *err_msg, int x_errno, const char *file, int line, const char *func)

Definition at line 245 of file sockets_man.cpp.

Typedef Documentation

◆ TSockList

typedef intr::list<CSrvSocketTask, intr::base_hook<TSrvSockListHook>, intr::constant_time_size<false> > TSockList

Definition at line 95 of file sockets_man.cpp.

Function Documentation

◆ AssignThreadSocks()

void AssignThreadSocks ( SSrvThread thr)

Definition at line 208 of file sockets_man.cpp.

References thr.

Referenced by s_AllocThread().

◆ CheckConnectsTimeout()

void CheckConnectsTimeout ( SSocketsData socks)

◆ CleanSocketList()

void CleanSocketList ( SSocketsData socks)

◆ ConfigureSockets()

void ConfigureSockets ( const CNcbiRegistry reg,
CTempString  section 
)

◆ DoSocketWait()

void DoSocketWait ( void  )

◆ FinalizeSocketsMan()

void FinalizeSocketsMan ( void  )

Definition at line 679 of file sockets_man.cpp.

References close(), and s_EpollFD.

Referenced by CTaskServer::Finalize().

◆ InitSocketsMan()

bool InitSocketsMan ( void  )

◆ MoveAllSockets()

void MoveAllSockets ( SSocketsData dst_socks,
SSocketsData src_socks 
)

Definition at line 768 of file sockets_man.cpp.

References SSocketsData::sock_cnt, and SSocketsData::sock_list.

Referenced by s_PerJiffyTasks_Worker().

◆ PromoteSockAmount()

void PromoteSockAmount ( SSocketsData socks)

Definition at line 777 of file sockets_man.cpp.

References AtomicAdd(), s_AllSocketsCount, and SSocketsData::sock_cnt.

Referenced by s_PerJiffyTasks_Worker().

◆ ReConfig_Sockets()

bool ReConfig_Sockets ( const CTempString section,
const CNcbiRegistry new_reg,
string err_message 
)

Definition at line 190 of file sockets_man.cpp.

References ConfigureSockets().

Referenced by CTaskServer::ReConfig().

◆ ReleaseThreadSocks()

void ReleaseThreadSocks ( SSrvThread thr)

Definition at line 215 of file sockets_man.cpp.

Referenced by s_StopCurMgrThread().

◆ RequestStopListening()

void RequestStopListening ( void  )

Definition at line 840 of file sockets_man.cpp.

References s_Listener, and CSrvTask::SetRunnable().

Referenced by TrackShuttingDown().

◆ s_CleanSockResources()

static void s_CleanSockResources ( CSrvSocketTask task)
static

◆ s_CloseSocket()

static void s_CloseSocket ( int  fd,
bool  do_abort 
)
static

◆ s_CompactBuffer()

static void s_CompactBuffer ( char *  buf,
Uint2 size,
Uint2 pos 
)
inlinestatic

◆ s_CompactWrBuffer()

static void s_CompactWrBuffer ( CSrvSocketTask task)
inlinestatic

◆ s_CopyData()

static void s_CopyData ( CSrvSocketTask task,
const void *  buf,
Uint2  size 
)
inlinestatic

◆ s_CreateDiagRequest()

static void s_CreateDiagRequest ( CSrvSocketTask task,
Uint2  port,
Uint4  phost,
Uint2  pport 
)
static

◆ s_CreateListeningSocket()

static bool s_CreateListeningSocket ( Uint1  idx)
static

◆ s_DeleteOldestSockets()

void s_DeleteOldestSockets ( TSockList lst)

◆ s_DoDataProxy()

static void s_DoDataProxy ( CSrvSocketTask src)
static

◆ s_FlushData()

static void s_FlushData ( CSrvSocketTask task)
inlinestatic

◆ s_LogSocketError()

static void s_LogSocketError ( CSrvDiagMsg::ESeverity  severity,
int  fd,
const char *  prefix,
const char *  file,
int  line,
const char *  func 
)
static

Definition at line 404 of file sockets_man.cpp.

References file, prefix, s_LogWithErrno(), and x_size().

◆ s_LogWithErrno()

static void s_LogWithErrno ( CSrvDiagMsg::ESeverity  severity,
const char *  err_msg,
int  x_errno,
const char *  file,
int  line,
const char *  func 
)
static

Definition at line 235 of file sockets_man.cpp.

References file, s_LogWithErrStr(), and strerror().

Referenced by s_LogSocketError().

◆ s_LogWithErrStr()

static void s_LogWithErrStr ( CSrvDiagMsg::ESeverity  severity,
const char *  err_msg,
int  x_errno,
const char *  errno_str,
const char *  file,
int  line,
const char *  func 
)
static

◆ s_ProcessListenError()

static void s_ProcessListenError ( Uint1  sock_idx)
static

◆ s_ProcessListenEvent()

static void s_ProcessListenEvent ( Uint1  sock_idx,
TSrvThreadNum  thread_num 
)
static

◆ s_ReadFromBuffer()

static Uint2 s_ReadFromBuffer ( CSrvSocketTask task,
void *  dest,
size_t  size 
)
inlinestatic

◆ s_ReadFromSocket()

static size_t s_ReadFromSocket ( CSrvSocketTask task,
void *  buf,
size_t  size 
)
static

◆ s_ReadLF()

static void s_ReadLF ( CSrvSocketTask task)
inlinestatic

◆ s_RegisterClientEvent()

static void s_RegisterClientEvent ( CSrvSocketTask task,
Uint4  event 
)
inlinestatic

◆ s_RegisterListenEvent()

static void s_RegisterListenEvent ( SListenSockInfo sock_info,
Uint4  event 
)
inlinestatic

◆ s_SaveSocket()

static void s_SaveSocket ( CSrvSocketTask task)
static

◆ s_SetSocketNonBlock()

static bool s_SetSocketNonBlock ( int  sock)
inlinestatic

◆ s_SetSocketOptions()

static bool s_SetSocketOptions ( int  sock)
static

Definition at line 284 of file sockets_man.cpp.

References Critical(), LOG_WITH_ERRNO, and value.

Referenced by CSrvSocketTask::Connect(), and s_ProcessListenEvent().

◆ s_SetSocketQuickAck()

static void s_SetSocketQuickAck ( int  sock)
static

Definition at line 303 of file sockets_man.cpp.

References Critical(), LOG_WITH_ERRNO, and value.

Referenced by CSrvSocketTask::InternalRunSlice().

◆ s_StartListening()

static bool s_StartListening ( void  )
static

Definition at line 370 of file sockets_man.cpp.

References i, s_CntListeningSocks, and s_CreateListeningSocket().

Referenced by StartSocketsMan().

◆ s_WriteNoPending()

static size_t s_WriteNoPending ( CSrvSocketTask task,
const void *  buf,
size_t  size 
)
inlinestatic

◆ s_WriteToSocket()

static size_t s_WriteToSocket ( CSrvSocketTask task,
const void *  buf,
size_t  size 
)
static

◆ SetAllSocksRunnable()

void SetAllSocksRunnable ( SSocketsData socks)

Definition at line 827 of file sockets_man.cpp.

References NON_CONST_ITERATE, and SSocketsData::sock_list.

Referenced by s_PerJiffyTasks_Worker().

◆ StartSocketsMan()

bool StartSocketsMan ( void  )

Definition at line 667 of file sockets_man.cpp.

References Critical(), s_CntListeningSocks, s_StartListening(), and SRV_LOG.

Referenced by CTaskServer::Run().

◆ WriteSetup_Sockets()

void WriteSetup_Sockets ( CSrvSocketTask task)

Variable Documentation

◆ kEpollEventsArraySize

const Uint1 kEpollEventsArraySize = 100
static

Definition at line 72 of file sockets_man.cpp.

Referenced by DoSocketWait().

◆ kMaxCntListeningSocks

const Uint1 kMaxCntListeningSocks = 16
static

16 Uint4s on x86_64 is the size of CPU's cacheline.

And it should be more than enough for NetCache.

Definition at line 82 of file sockets_man.cpp.

Referenced by CTaskServer::AddListeningPort().

◆ kSockMinWriteSize

const Uint2 kSockMinWriteSize = 1000
static

Definition at line 76 of file sockets_man.cpp.

Referenced by s_DoDataProxy(), s_WriteNoPending(), and CSrvSocketTask::Write().

◆ kSockReadBufSize

const Uint2 kSockReadBufSize = 1000
static

1000 below is chosen to be a little bit less than maximum packet size in Ethernet (~1500 bytes).

Definition at line 75 of file sockets_man.cpp.

Referenced by CSrvSocketTask::CSrvSocketTask(), CSrvSocketTask::Read(), CSrvSocketTask::ReadLine(), CSrvSocketTask::ReadToBuf(), and s_DoDataProxy().

◆ kSockWriteBufSize

const Uint2 kSockWriteBufSize = 2000
static

In calculations in the file it's assumed that kSockWriteBufSize is at least twice as large as kSockMinWriteSize.

Definition at line 79 of file sockets_man.cpp.

Referenced by CSrvSocketTask::CSrvSocketTask(), and CSrvSocketTask::Write().

◆ s_AcceptDelay

Uint8 s_AcceptDelay = 1000000
static

Definition at line 166 of file sockets_man.cpp.

Referenced by ConfigureSockets(), s_ProcessListenEvent(), and WriteSetup_Sockets().

◆ s_AllSocketsCount

int s_AllSocketsCount = 0

Definition at line 159 of file sockets_man.cpp.

Referenced by PromoteSockAmount().

◆ s_CntListeningSocks

Uint1 s_CntListeningSocks = 0
static

◆ s_ConnTimeout

Uint8 s_ConnTimeout = 10
static

◆ s_CurJiffies

Uint8 s_CurJiffies
extern

◆ s_EpollFD

int s_EpollFD = -1
static

◆ s_HardSocketLimit

int s_HardSocketLimit = 0

◆ s_HostName

string s_HostName
static

Definition at line 165 of file sockets_man.cpp.

Referenced by CTaskServer::GetHostName().

◆ s_JiffyTime

CSrvTime s_JiffyTime
extern

Definition at line 54 of file time_man.cpp.

Referenced by ConfigureSockets(), DoSocketWait(), and WriteSetup_Sockets().

◆ s_Listener

CSrvListener s_Listener
static

◆ s_ListenErrors

Uint4 s_ListenErrors[kMaxCntListeningSocks]
static

◆ s_ListenEvents

Uint4 s_ListenEvents[kMaxCntListeningSocks]
static

◆ s_ListenSocks

SListenSockInfo s_ListenSocks[kMaxCntListeningSocks]
static

◆ s_ListenSocksLock

CMiniMutex s_ListenSocksLock
static

Definition at line 153 of file sockets_man.cpp.

Referenced by CTaskServer::AddListeningPort().

◆ s_OldSocksDelBatch

Uint1 s_OldSocksDelBatch = 0
static

Definition at line 163 of file sockets_man.cpp.

Referenced by ConfigureSockets(), s_DeleteOldestSockets(), and WriteSetup_Sockets().

◆ s_SocketTimeout

int s_SocketTimeout = 0
static

Definition at line 162 of file sockets_man.cpp.

Referenced by ConfigureSockets(), s_DeleteOldestSockets(), and WriteSetup_Sockets().

◆ s_SoftSocketLimit

int s_SoftSocketLimit = 0

◆ s_Threads

SSrvThread** s_Threads
extern

Definition at line 59 of file threads_man.cpp.

Referenced by s_ProcessListenEvent().

◆ s_TotalSockets

int s_TotalSockets = 0
Modified on Sat Mar 02 10:54:17 2024 by modify_doxy.py rev. 669887