46 lines
1.5 KiB
C++
46 lines
1.5 KiB
C++
/*
|
|
* Copyright (c) 2023 Fancy Code.
|
|
* 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.
|
|
*/
|
|
#ifndef TCP_CLIENT_IMPL_H
|
|
#define TCP_CLIENT_IMPL_H
|
|
#include "ITcpClient.h"
|
|
#include "TcpModule.h"
|
|
#include "hloop.h"
|
|
#include "hsocket.h"
|
|
#include "hssl.h"
|
|
#include <memory>
|
|
#include <mutex>
|
|
#include <thread>
|
|
class TcpClientImpl : public ITcpClient, public std::enable_shared_from_this<TcpClientImpl>
|
|
{
|
|
public:
|
|
TcpClientImpl(const TcpClientParam ¶m, const void *object);
|
|
virtual ~TcpClientImpl() = default;
|
|
void Init(void) override;
|
|
void UnInit(void) override;
|
|
void Readed(const void *data, size_t length) override;
|
|
ssize_t Write(const void *buf, const size_t bufLenght) override;
|
|
void Closed(void) override;
|
|
void Loop(void);
|
|
|
|
private:
|
|
std::mutex mMutex;
|
|
hloop_t *mLoop;
|
|
hio_t *mIo;
|
|
const TcpClientParam mParam;
|
|
std::thread mTcpClientThread;
|
|
const void *mObjectThis;
|
|
};
|
|
std::shared_ptr<ITcpClient> *NewTcpClient(const TcpClientParam ¶m);
|
|
#endif |