Skip to content

Commit

Permalink
Allow to disable reserving buffer strings
Browse files Browse the repository at this point in the history
  • Loading branch information
RoLex committed Mar 2, 2019
1 parent ecdc8ed commit ac831bc
Show file tree
Hide file tree
Showing 22 changed files with 614 additions and 352 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ message(STATUS)
SET(VERLIHUB_VERSION_MAJOR 1)
SET(VERLIHUB_VERSION_MINOR 1)
SET(VERLIHUB_VERSION_PATCH 0)
SET(VERLIHUB_VERSION_TWEAK 46)
SET(VERLIHUB_VERSION_TWEAK 47)
SET(VERLIHUB_VERSION "${VERLIHUB_VERSION_MAJOR}.${VERLIHUB_VERSION_MINOR}.${VERLIHUB_VERSION_PATCH}.${VERLIHUB_VERSION_TWEAK}")
#SET(VERLIHUB_SOVERSION "${VERLIHUB_VERSION_MAJOR}.${VERLIHUB_VERSION_MINOR}.${VERLIHUB_VERSION_PATCH}")
SET(PROJECT_NAME "verlihub")
Expand Down Expand Up @@ -185,6 +185,7 @@ IF(NOT HAVE_GETOPT_H)
MESSAGE(FATAL_ERROR "[ ER ] getopt.h header not found, it is required to build Verlihub.")
ENDIF(NOT HAVE_GETOPT_H)

OPTION(USE_BUFFER_RESERVE "Use buffer string reservation?" OFF) # use cmake -DUSE_BUFFER_RESERVE=ON to use buffer string reservation
OPTION(DEFINE_DEBUG "Build the project using debugging code" OFF) # use cmake -DDEFINE_DEBUG=ON to enable debug

IF(DEFINE_DEBUG)
Expand Down
2 changes: 2 additions & 0 deletions plugins/chatroom/crooms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ void cRoom::OnLoad()
mChatRoom->mClass = tUserCl(3);

if (mTopic.size()) {
#ifdef USE_BUFFER_RESERVE
if (desc.capacity() < (desc.size() + 2 + mTopic.size()))
desc.reserve(desc.size() + 2 + mTopic.size());
#endif

desc.append(": ");
desc.append(mTopic);
Expand Down
4 changes: 4 additions & 0 deletions plugins/floodprot/cpifloodprot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ bool cpiFloodprot::OnNewConn(cConnDC *conn)
{
if (!mFloodprotect->AddConn(conn, 1)) {
string omsg;
#ifdef USE_BUFFER_RESERVE
omsg.reserve(63 + 1);
#endif
omsg = "Sorry, the limit of connections from your IP has been exceeded."; // length = 63
conn->Send(omsg, true);
conn->CloseNice(500); // not sure if this is needed
Expand All @@ -77,7 +79,9 @@ bool cpiFloodprot::OnUserLogin(cUser *user)
{
if (!mFloodprotect->AddConn(user->mxConn, 1)) {
string omsg;
#ifdef USE_BUFFER_RESERVE
omsg.reserve(76 + 1);
#endif
omsg = "Sorry, the limit of unregistered connections form your IP has been exceeded."; // length = 76
user->mxConn->Send(omsg, true);
user->mxConn->CloseNice(500); // not sure if this is needed
Expand Down
2 changes: 2 additions & 0 deletions plugins/lua/callbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2200,8 +2200,10 @@ int _EditBot(lua_State *L)

serv->mP.Create_MyINFO(robot->mMyINFO, nick, desc, conn, mail, shar, false); // send new myinfo after quit, dont reserve for pipe, we are not sending this

#ifdef USE_BUFFER_RESERVE
if (temp.capacity() < (robot->mMyINFO.size() + 1)) // reserve for pipe
temp.reserve(robot->mMyINFO.size() + 1);
#endif

temp = robot->mMyINFO;
serv->mUserList.SendToAll(temp, serv->mC.delayed_myinfo, true); // show new myinfo to all
Expand Down
2 changes: 2 additions & 0 deletions plugins/perl/callbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ bool nVerliHub::nPerlPlugin::nCallback::EditBot(const char *nick, int clas, cons
serv->mP.Create_MyINFO(robot->mMyINFO, nick, desc, conn, mail, shar, false); // dont reserve for pipe, we are not sending this
//pi->mPerl.editBot(nick, shar, (char*)robot->mMyINFO.c_str(), clas);
string temp;
#ifdef USE_BUFFER_RESERVE
temp.reserve(robot->mMyINFO.size() + 1); // first use, reserve for pipe
#endif
serv->mUserList.SendToAll(temp, serv->mC.delayed_myinfo, true); // show new myinfo to all

if (clas >= 3) { // todo: oplist_class, userip
Expand Down
4 changes: 4 additions & 0 deletions plugins/python/cpipython.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1338,11 +1338,15 @@ w_Targs *_SetMyINFO(int id, w_Targs *args)
freee(origmail);
freee(origsize);

#ifdef USE_BUFFER_RESERVE
if (u->mMyINFO.capacity() < newinfo.size())
u->mMyINFO.reserve(newinfo.size());
#endif

u->mMyINFO = newinfo;
#ifdef USE_BUFFER_RESERVE
newinfo.reserve(newinfo.size() + 1); // reserve for pipe
#endif
cpiPython::me->server->mUserList.SendToAll(newinfo, cpiPython::me->server->mC.delayed_myinfo, true);
return w_ret1;
}
Expand Down
Loading

0 comments on commit ac831bc

Please sign in to comment.