18d51ab70SShuo Chen#include "TlsStream.h" 28d51ab70SShuo Chen 38d51ab70SShuo ChenTlsStreamPtr TlsStream::connect(TlsConfig* config, const char* hostport, const char* servername) 48d51ab70SShuo Chen{ 58d51ab70SShuo Chen TlsStreamPtr stream; 68d51ab70SShuo Chen TlsContext context(TlsContext::kClient, config); 78d51ab70SShuo Chen if (context.connect(hostport, servername)) 88d51ab70SShuo Chen { 98d51ab70SShuo Chen LOG_ERROR << context.error(); 108d51ab70SShuo Chen return stream; 118d51ab70SShuo Chen } 128d51ab70SShuo Chen if (context.handshake()) 138d51ab70SShuo Chen { 148d51ab70SShuo Chen LOG_ERROR << context.error(); 158d51ab70SShuo Chen return stream; 168d51ab70SShuo Chen } 178d51ab70SShuo Chen stream.reset(new TlsStream(std::move(context))); 187db0aea6SShuo Chen return stream; 198d51ab70SShuo Chen} 2002cc483dSShuo Chen 2102cc483dSShuo Chenint TlsStream::receiveSome(void* buf, int len) 2202cc483dSShuo Chen{ 2302cc483dSShuo Chen return context_.read(buf, len); 2402cc483dSShuo Chen} 2502cc483dSShuo Chen 2602cc483dSShuo Chenint TlsStream::sendSome(const void* buf, int len) 2702cc483dSShuo Chen{ 2802cc483dSShuo Chen return context_.write(buf, len); 2902cc483dSShuo Chen} 30