From dd6ac172c4f814fa4b5ace6caca80d00d7e01ac8 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 20 Feb 2020 21:23:22 +0300 Subject: bunch of useless threads replaced with a call of ProtoBroadcastAsync --- protocols/Twitter/src/proto.cpp | 35 +++++++---------------------------- protocols/Twitter/src/proto.h | 1 - 2 files changed, 7 insertions(+), 29 deletions(-) (limited to 'protocols/Twitter/src') diff --git a/protocols/Twitter/src/proto.cpp b/protocols/Twitter/src/proto.cpp index 3629a59f35..e2780da7b1 100644 --- a/protocols/Twitter/src/proto.cpp +++ b/protocols/Twitter/src/proto.cpp @@ -118,33 +118,6 @@ INT_PTR CTwitterProto::GetCaps(int type, MCONTACT) ///////////////////////////////////////////////////////////////////////////////////////// -struct TSendDirect -{ - __inline TSendDirect(MCONTACT _hContact, const CMStringA &_msg, int _msgid) : - hContact(_hContact), msg(_msg), msgid(_msgid) - {} - - MCONTACT hContact; - CMStringA msg; - int msgid; -}; - -void CTwitterProto::SendSuccess(void *p) -{ - if (p == nullptr) - return; - - auto *data = (TSendDirect*)p; - - CMStringA id(getMStringA(data->hContact, TWITTER_KEY_ID)); - if (!id.IsEmpty()) { - send_direct(id, data->msg); - ProtoBroadcastAck(data->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE)data->msgid, 0); - } - - delete data; -} - MEVENT CTwitterProto::RecvMsg(MCONTACT hContact, PROTORECVEVENT *pre) { MEVENT res = CSuper::RecvMsg(hContact, pre); @@ -158,8 +131,14 @@ int CTwitterProto::SendMsg(MCONTACT hContact, int, const char *msg) if (m_iStatus != ID_STATUS_ONLINE) return 0; + CMStringA id(getMStringA(hContact, TWITTER_KEY_ID)); + if (id.IsEmpty()) + return 0; + + send_direct(id, msg); + int seq = InterlockedIncrement(&g_msgid); - ForkThread(&CTwitterProto::SendSuccess, new TSendDirect(hContact, msg, seq)); + ProtoBroadcastAsync(hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE)seq); return seq; } diff --git a/protocols/Twitter/src/proto.h b/protocols/Twitter/src/proto.h index 498925ff4a..ba2773a18c 100644 --- a/protocols/Twitter/src/proto.h +++ b/protocols/Twitter/src/proto.h @@ -202,7 +202,6 @@ public: // Threads void __cdecl AddToListWorker(void *p); - void __cdecl SendSuccess(void *); void __cdecl DoSearch(void *); void __cdecl SignOn(void *); void __cdecl MessageLoop(void *); -- cgit v1.2.3