HttpsSession.h 1.51 KB
Newer Older
xzl committed
1 2 3 4 5 6 7 8 9 10 11 12 13
/*
 * HttpsSession.h
 *
 *  Created on: 2017年4月19日
 *      Author: xzl
 */

#ifndef SRC_HTTP_HTTPSSESSION_H_
#define SRC_HTTP_HTTPSSESSION_H_

#include "HttpSession.h"
#include "Util/SSLBox.h"
#include "Util/TimeTicker.h"
xiongzilaing committed
14

xzl committed
15 16 17 18 19 20 21 22 23 24
using namespace ZL::Util;

namespace ZL {
namespace Http {

class HttpsSession: public HttpSession {
public:
	HttpsSession(const std::shared_ptr<ThreadPool> &pTh, const Socket::Ptr &pSock):
		HttpSession(pTh,pSock){
		m_sslBox.setOnEncData([&](const char *data, uint32_t len){
xzl committed
25 26 27
#ifdef ANDROID
			public_send(data,len);
#else//ANDROID
xzl committed
28
			HttpSession::send(data,len);
xzl committed
29
#endif//ANDROID
xzl committed
30 31
		});
		m_sslBox.setOnDecData([&](const char *data, uint32_t len){
xzl committed
32 33 34
#ifdef ANDROID
			public_onRecv(data,len);
#else//ANDROID
xzl committed
35
			HttpSession::onRecv(data,len);
xzl committed
36
#endif//ANDROID
xzl committed
37 38 39 40 41 42 43 44 45
		});
	}
	virtual ~HttpsSession(){
		//m_sslBox.shutdown();
	}
	void onRecv(const Socket::Buffer::Ptr &pBuf) override{
		TimeTicker();
		m_sslBox.onRecv(pBuf->data(), pBuf->size());
	}
xzl committed
46 47 48 49 50 51 52 53
#ifdef ANDROID
	int public_send(const char *data, uint32_t len){
		return HttpSession::send(data,len);
	}
	void public_onRecv(const char *data, uint32_t len){
		HttpSession::onRecv(data,len);
	}
#endif//ANDROID
xzl committed
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
private:
	virtual int send(const string &buf) override{
		TimeTicker();
		m_sslBox.onSend(buf.data(), buf.size());
		return buf.size();
	}
	virtual int send(const char *buf, int size) override{
		TimeTicker();
		m_sslBox.onSend(buf, size);
		return size;
	}
	SSL_Box m_sslBox;
};

} /* namespace Http */
} /* namespace ZL */

#endif /* SRC_HTTP_HTTPSSESSION_H_ */