File: connection_options.cpp

package info (click to toggle)
qpid-proton 0.37.0-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 18,384 kB
  • sloc: ansic: 37,828; cpp: 37,140; python: 15,302; ruby: 6,018; xml: 477; sh: 320; pascal: 52; makefile: 18
file content (75 lines) | stat: -rw-r--r-- 2,611 bytes parent folder | download | duplicates (3)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
 */

#include <proton/connection.hpp>
#include <proton/connection_options.hpp>
#include <proton/container.hpp>
#include <proton/messaging_handler.hpp>
#include <proton/transport.hpp>

#include <iostream>

using proton::connection_options;


class handler_2 : public proton::messaging_handler {
    void on_connection_open(proton::connection &c) override {
        std::cout << "connection events going to handler_2" << std::endl;
        std::cout << "connection max_frame_size: " << c.max_frame_size() <<
            ", idle timeout: " << c.idle_timeout() << std::endl;
        c.close();
    }
};

class main_handler : public proton::messaging_handler {
  private:
    std::string url;
    handler_2 conn_handler;

  public:
    main_handler(const std::string& u) : url(u) {}

    void on_container_start(proton::container &c) override {
        // Connection options for this connection.  Merged with and overriding the container's
        // client_connection_options() settings.
        c.connect(url, connection_options().handler(conn_handler).max_frame_size(2468));
    }

    void on_connection_open(proton::connection &c) override {
        std::cout << "unexpected connection event on main handler" << std::endl;
        c.close();
    }
};

int main(int argc, char **argv) {
    try {
        std::string url = argc > 1 ? argv[1] : "127.0.0.1:5672/examples";
        main_handler handler(url);
        proton::container container(handler);
        // Global connection options for future connections on container.
        container.client_connection_options(connection_options().max_frame_size(12345).idle_timeout(proton::duration(15000)));
        container.run();
        return 0;
    } catch (const std::exception& e) {
        std::cerr << e.what() << std::endl;
    }
    return 1;
}