KjSslServer.cpp

Go to the documentation of this file.
00001 
00013 /***************************************************************************
00014  *   Copyright (C) 2007 by Jan Koci   *
00015  *   honza.koci@email.cz   *
00016  *   http://kengine.sourceforge.net/tutorial/
00017  *                                                                         *
00018  *   This program is free software; you can redistribute it and/or modify  *
00019  *   it under the terms of the GNU General Public License as published by  *
00020  *   the Free Software Foundation; either version 2 of the License, or     *
00021  *   (at your option) any later version.                                   *
00022  *                                                                         *
00023  *   This program is distributed in the hope that it will be useful,       *
00024  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00025  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00026  *   GNU General Public License for more details.                          *
00027  *                                                                         *
00028  *   You should have received a copy of the GNU General Public License     *
00029  *   along with this program; if not, write to the                         *
00030  *   Free Software Foundation, Inc.,                                       *
00031  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
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         // First call to BIO_accept() -- sets up accept BIO
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         // Second call to BIO_accept() -- Wait for incoming connection
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 }

Generated on Tue Jul 24 10:03:19 2007 for KjSslSocket by  doxygen 1.4.6