FETPAPI 0.3.0.0
This project provides C++ classes which facilitate the developement of ETP1.2 clients and servers.
Loading...
Searching...
No Matches
PlainClientSession.h
1/*-----------------------------------------------------------------------
2Licensed to the Apache Software Foundation (ASF) under one
3or more contributor license agreements. See the NOTICE file
4distributed with this work for additional information
5regarding copyright ownership. The ASF licenses this file
6to you under the Apache License, Version 2.0 (the
7"License"; you may not use this file except in compliance
8with the License. You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12Unless required by applicable law or agreed to in writing,
13software distributed under the License is distributed on an
14"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15KIND, either express or implied. See the License for the
16specific language governing permissions and limitations
17under the License.
18-----------------------------------------------------------------------*/
19#pragma once
20
21#include "AbstractClientSessionCRTP.h"
22
23namespace ETP_NS
24{
25 class PlainClientSession : public AbstractClientSessionCRTP<PlainClientSession>
26 {
27 public:
28 /*
29 * @param frameSize Sets the size of the write buffer used by the implementation to send frames : https://www.boost.org/doc/libs/1_75_0/libs/beast/doc/html/beast/ref/boost__beast__websocket__stream/write_buffer_bytes/overload1.html.
30 */
31 FETPAPI_DLL_IMPORT_OR_EXPORT PlainClientSession(
32 InitializationParameters const* initializationParams, const std::string & target, const std::string & authorization, const std::string& proxyAuthorization = "",
33 const std::map<std::string, std::string>& additionalHandshakeHeaderFields = {}, std::size_t frameSize = 4096);
34
35 virtual ~PlainClientSession() = default;
36
37 // Called by the base class
38 FETPAPI_DLL_IMPORT_OR_EXPORT websocket::stream<tcp::socket>& ws() { return ws_; }
39
40 bool isTls() const final{ return false; }
41
42 void on_resolve(boost::system::error_code ec, tcp::resolver::results_type results)
43 {
44 if (ec) {
45 std::cerr << "on_resolve : " << ec.message() << std::endl;
46 }
47
48 // Make the connection on the IP address we get from a lookup
49 boost::asio::async_connect(
50 ws_.next_layer(),
51 results.begin(),
52 results.end(),
53 std::bind(
54 &AbstractClientSessionCRTP::on_connect,
55 std::static_pointer_cast<AbstractClientSessionCRTP>(shared_from_this()),
56 std::placeholders::_1));
57 }
58
59 private:
60 websocket::stream<tcp::socket> ws_;
61 };
62}
Definition AbstractClientSessionCRTP.h:28
Definition InitializationParameters.h:41
Definition PlainClientSession.h:26