// Copyright (c) Facebook, Inc. and its affiliates. // // Licensed 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. #pragma once #include "rsocket/RSocketClient.h" #include "rsocket/RSocketServer.h" namespace rsocket { /** * Main entry to creating RSocket clients and servers. */ class RSocket { public: // Creates a RSocketClient which is connected to the remoteside. // keepaliveInterval of 0 will result in no keepAlives static folly::Future> createConnectedClient( std::shared_ptr, SetupParameters setupParameters = SetupParameters(), std::shared_ptr responder = std::make_shared(), std::chrono::milliseconds keepaliveInterval = kDefaultKeepaliveInterval, std::shared_ptr stats = RSocketStats::noop(), std::shared_ptr connectionEvents = std::shared_ptr(), std::shared_ptr resumeManager = ResumeManager::makeEmpty(), std::shared_ptr coldResumeHandler = std::shared_ptr(), folly::EventBase* stateMachineEvb = nullptr); // Creates a RSocketClient which cold-resumes from the provided state // keepaliveInterval of 0 will result in no keepAlives static folly::Future> createResumedClient( std::shared_ptr, ResumeIdentificationToken token, std::shared_ptr resumeManager, std::shared_ptr coldResumeHandler, std::shared_ptr responder = std::make_shared(), std::chrono::milliseconds keepaliveInterval = kDefaultKeepaliveInterval, std::shared_ptr stats = RSocketStats::noop(), std::shared_ptr connectionEvents = std::shared_ptr(), ProtocolVersion protocolVersion = ProtocolVersion::Latest, folly::EventBase* stateMachineEvb = nullptr); // Creates a RSocketClient from an existing DuplexConnection. A keepalive // interval of 0 will result in no keepalives. static std::unique_ptr createClientFromConnection( std::unique_ptr connection, folly::EventBase& transportEvb, SetupParameters setupParameters = SetupParameters(), std::shared_ptr connectionFactory = nullptr, std::shared_ptr responder = std::make_shared(), std::chrono::milliseconds keepaliveInterval = kDefaultKeepaliveInterval, std::shared_ptr stats = RSocketStats::noop(), std::shared_ptr connectionEvents = nullptr, std::shared_ptr resumeManager = ResumeManager::makeEmpty(), std::shared_ptr coldResumeHandler = nullptr, folly::EventBase* stateMachineEvb = nullptr); // A convenience function to create RSocketServer static std::unique_ptr createServer( std::unique_ptr, std::shared_ptr stats = RSocketStats::noop()); RSocket() = delete; RSocket(const RSocket&) = delete; RSocket(RSocket&&) = delete; RSocket& operator=(const RSocket&) = delete; RSocket& operator=(RSocket&&) = delete; }; } // namespace rsocket