APUE Learning Example Source Code
guowenxue
2019-06-26 157be0b0d4c7d4809cfcafc76235cc18388378c8
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
35
#include <cstring>
#include <mosquittopp.h>
 
static int run = -1;
 
class mosquittopp_test : public mosqpp::mosquittopp
{
    public:
        mosquittopp_test(const char *id, bool clean_session);
};
 
mosquittopp_test::mosquittopp_test(const char *id, bool clean_session) : mosqpp::mosquittopp(id, clean_session)
{
}
 
int main(int argc, char *argv[])
{
    struct mosquittopp_test *mosq;
 
    int port = atoi(argv[1]);
 
    mosqpp::lib_init();
 
    mosq = new mosquittopp_test("01-no-clean-session", false);
 
    mosq->connect("localhost", port, 60);
 
    while(run == -1){
        mosq->loop();
    }
 
    mosqpp::lib_cleanup();
 
    return run;
}