lichao
2021-04-14 aa1542b6d6a4680088ac715c4ce40f97ada554fb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*
 * =====================================================================================
 *
 *       Filename:  failed_msg.cpp
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  2021年04月12日 16时10分53秒
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Li Chao (), lichao@aiotlink.com
 *   Organization:  
 *
 * =====================================================================================
 */
#include "failed_msg.h"
 
FailedMsgQ::Func FailedMsgQ::PrepareSender(const std::string &remote, Msg const &msg)
{
    msg.AddRef();
    return [remote, msg](void *valid_sock) {
        assert(valid_sock);
        ShmSocket &sock = *static_cast<ShmSocket *>(valid_sock);
        bool r = sock.Send(remote.data(), msg);
        //TODO check remote removed.
        if (r && msg.IsCounted()) {
            auto tmp = msg; // Release() is not const, but it's safe to release.
            tmp.Release(sock.shm());
        }
        return r;
    };
}