acl/lib_acl_cpp/include/acl_cpp/stream/polarssl_io.hpp

102 lines
2.8 KiB
C++
Raw Normal View History

#pragma once
2017-06-02 14:47:24 +08:00
#include "../acl_cpp_define.hpp"
#include "stream_hook.hpp"
struct ACL_VSTREAM;
2014-11-19 00:25:21 +08:00
namespace acl {
class polarssl_conf;
class atomic_long;
2014-11-19 00:25:21 +08:00
/**
* stream/aio_stream IO
* stream/aio_stream IO ()
* stream/aio_stream destroy() 
2014-11-19 00:25:21 +08:00
*/
class ACL_CPP_API polarssl_io : public stream_hook
{
public:
/**
*
* @param conf {polarssl_conf&} SSL
* @param server_side {bool}
*
* @param nblock {bool}
2014-11-19 00:25:21 +08:00
*/
polarssl_io(polarssl_conf& conf, bool server_side, bool nblock = false);
2014-11-19 00:25:21 +08:00
/**
* SSL IO
*/
2019-07-07 11:00:12 +08:00
virtual void destroy(void);
2014-11-19 00:25:21 +08:00
/**
* SSL IO handshake_ok()
* 使 SSL
* @return {bool}
* 1 false
* 2 true
* 2.1 IO SSL
* 2.2 IO IO
* handshake_ok() SSL
*/
bool handshake(void);
/**
* SSL
* @return {bool}
*/
bool handshake_ok(void)
{
return handshake_ok_;
}
2014-12-07 23:48:11 +08:00
/**
* /
* @param yes {bool} false
2014-12-07 23:48:11 +08:00
* @return {polarssl_io&}
*/
polarssl_io& set_non_blocking(bool yes);
/**
* SSL IO
* @return {bool} true
2014-12-07 23:48:11 +08:00
*/
bool is_non_blocking(void) const
{
return nblock_;
2014-12-07 23:48:11 +08:00
}
/**
*
* @return {bool}
*/
bool check_peer(void);
2014-11-19 00:25:21 +08:00
private:
2019-07-07 11:00:12 +08:00
~polarssl_io(void);
2014-11-19 00:25:21 +08:00
virtual bool open(ACL_VSTREAM* s);
2014-11-19 00:25:21 +08:00
virtual bool on_close(bool alive);
virtual int read(void* buf, size_t len);
virtual int send(const void* buf, size_t len);
private:
polarssl_conf& conf_;
atomic_long* refers_;
bool server_side_;
bool nblock_;
bool handshake_ok_;
2014-11-19 00:25:21 +08:00
void* ssl_;
void* ssn_;
void* rnd_;
ACL_VSTREAM* stream_;
2014-11-19 00:25:21 +08:00
static int sock_read(void *ctx, unsigned char *buf, size_t len);
static int sock_send(void *ctx, const unsigned char *buf, size_t len);
};
} // namespace acl