FFL_TcpClient.hpp 1.8 KB
Newer Older
L
libb 已提交
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 76 77 78
/*
*  This file is part of FFL project.
*
*  The MIT License (MIT)
*  Copyright (C) 2017-2018 zhufeifei All rights reserved.
*
*  FFL_TcpClient.hpp
*  Created by zhufeifei(34008081@qq.com) on 2018/07/14
*  https://github.com/zhenfei2016/FFLv2-lib.git
*  网络客户端定义
*
*/
#ifndef _FFL_TCP_CLIENT_HPP_
#define _FFL_TCP_CLIENT_HPP_

#include <net/FFL_NetSocket.hpp>
#include <FFL_RefBase.hpp>

namespace FFL {
	class FFLIB_API_IMPORT_EXPORT TcpClient : public IOReader, public IOWriter {
    public:
        //
        //  tcp相关的,连接到服务器上,如果设置过fd则返回false
        //
        static status_t connect(const char* ip, uint16_t port,TcpClient& client);

	public:
		TcpClient(NetFD fd=INVALID_NetFD);
		virtual ~TcpClient();

		//
		// 保存一些用户数据
		//
		void setUserdata(void* priv);
		void* getUserdata();

		NetFD getFd();

		//
		//  读数据到缓冲区
		//  buf:缓冲区地址
		//  count:需要读的大小
		//  pReaded:实质上读了多少数据
		//  返回错误码  : FFL_OK表示成功
		//
		virtual status_t read(uint8_t* buf, size_t count, size_t* pReaded);
		//
		//  写数据到文件中
		//  buf:缓冲区地址
		//  count:缓冲区大小
		//  pWrite:实质上写了多少数据
		//  返回错误码  : FFL_OK表示成功
		//
		virtual status_t write(const void* buf, size_t count, size_t* pWrite);
		//
		//  写数据到文件中
		//  bufVec:缓冲区地址,数组
		//  count:数组大小
		//  pWrite:实质上写了多少数据
		//  返回错误码  : FFL_OK表示成功
		//
		virtual status_t writeVec(const BufferVec* bufVec, int count, size_t* pWrite);		
	public:
		void close();

		
	protected:
		friend class HttpClient;
		friend class WebSocketClient;
		friend class NetStreamReader;
		CSocket mSocket;
		void* mPriv;
	};	

	
}

#endif