00001
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include "KjSslServer.h"
00035
00036 KjSslServer::KjSslServer(char* _strConn, const string &_strCertFile,const string &_strKeyFile): m_strCertFile(_strCertFile),m_strKeyFile(_strKeyFile)
00037 {
00038 cout << "KjSslServer::KjSslServer()" << endl;
00039 cout << "First call of BIO_new_accept" << endl;
00040 m_pBioAccept=BIO_new_accept(_strConn);
00041 if(!m_pBioAccept)
00042 {
00043 m_bIsValid=false;
00044 return;
00045 }
00046 BIO_set_bind_mode(m_pBioAccept,BIO_BIND_REUSEADDR);
00047
00048 if(BIO_do_accept(m_pBioAccept)<=0)
00049 {
00050 m_bIsValid=false;
00051 CheckErrors("BIO_do_accept(binding to socket)");
00052 return;
00053 }
00054 m_bIsValid=true;
00055 }
00056
00057 KjSslServer::~KjSslServer()
00058 {
00059 cout << "KjSslObject::~KjSslObject()" << endl;
00060 BIO_free_all(m_pBioAccept);
00061 }
00062
00065 KjSslConnection* KjSslServer::NextClient()
00066 {
00067
00068 KjSslConnection *pRet = NULL;
00069 cout << "Waiting for new client request ..." << endl;
00070 cout << "this " << this << endl;
00071 cout << "m_pBioAccept " << m_pBioAccept << endl;
00072 if(m_pBioAccept)
00073 {
00074 cout << "Try BIO_do_accept ..." << endl;
00075 if(BIO_do_accept(m_pBioAccept)<=0)
00076 {
00077 cout << "BIO_do_accept fails ..." << endl;
00078 CheckErrors("BIO_do_accept (exteblishing connection)");
00079 return NULL;
00080 }
00081 BIO* pBioConnect;
00082 cout << "Try BIO_pop ..." << endl;
00083 pBioConnect=BIO_pop(m_pBioAccept);
00084 cout << "Try new KjSslConnection(pBioConnect,m_strCertFile,m_strKeyFile ...)" << endl;
00085 pRet = new KjSslConnection(pBioConnect,m_strCertFile,m_strKeyFile);
00086 if (!pRet)
00087 {
00088 delete pRet;
00089 return NULL;
00090 }
00091 cout << "Waiting for new client request ... returns" << endl;
00092 }
00093 else
00094 {
00095 cerr << "m_pBioAccept doesn`t allocated" << endl;
00096 }
00097 return pRet;
00098 }
00099
00102 void KjSslServer::DeleteClient(KjSslConnection* _pCon)
00103 {
00104 if(_pCon)
00105 {
00106 delete _pCon;
00107 _pCon = NULL;
00108 }
00109 }