Initial
This commit is contained in:
82
wininet/connection.hpp
Normal file
82
wininet/connection.hpp
Normal file
@@ -0,0 +1,82 @@
|
||||
#ifndef _WININET_CONNECTION_HPP_
|
||||
#define _WININET_CONNECTION_HPP_
|
||||
#ifndef _WININET_INTERNET_HPP_
|
||||
#include <wininet/internet.hpp>
|
||||
#endif
|
||||
|
||||
class Connection
|
||||
{
|
||||
public:
|
||||
Connection();
|
||||
virtual ~Connection();
|
||||
bool connect(const Internet &internet,const String &strServer);
|
||||
bool connect(const Internet &internet,const String &strServer,int service,int port);
|
||||
bool connectURL(const Internet &internet,const String &strURL);
|
||||
void close();
|
||||
HINTERNET getHANDLE(void)const;
|
||||
bool isOkay(void)const;
|
||||
private:
|
||||
HINTERNET mhConnection;
|
||||
};
|
||||
|
||||
inline
|
||||
Connection::Connection()
|
||||
: mhConnection(0)
|
||||
{
|
||||
}
|
||||
|
||||
inline
|
||||
Connection::~Connection()
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
inline
|
||||
bool Connection::connect(const Internet &internet,const String &strServer)
|
||||
{
|
||||
if(!internet.isOkay())return false;
|
||||
close();
|
||||
mhConnection=::InternetConnect(internet.getHANDLE(),strServer.str(),INTERNET_INVALID_PORT_NUMBER,NULL,NULL,INTERNET_SERVICE_HTTP,0,0);
|
||||
return isOkay();
|
||||
}
|
||||
|
||||
// connect(internet,"loocalhost",INTERNET_SERVICE_HTTP,INTERNET_DEFAULT_HTTP_PORT)
|
||||
|
||||
inline
|
||||
bool Connection::connect(const Internet &internet,const String &strServer,int service,int port)
|
||||
{
|
||||
if(!internet.isOkay())return false;
|
||||
close();
|
||||
mhConnection=::InternetConnect(internet.getHANDLE(),strServer.str(),port,NULL,NULL,service,0,0);
|
||||
return isOkay();
|
||||
}
|
||||
|
||||
inline
|
||||
bool Connection::connectURL(const Internet &internet,const String &strURL)
|
||||
{
|
||||
if(!internet.isOkay())return false;
|
||||
close();
|
||||
mhConnection=::InternetConnect(internet.getHANDLE(),strURL.str(),INTERNET_INVALID_PORT_NUMBER,NULL,NULL,INTERNET_SERVICE_URL,0,0);
|
||||
return isOkay();
|
||||
}
|
||||
|
||||
inline
|
||||
void Connection::close()
|
||||
{
|
||||
if(!isOkay())return;
|
||||
::InternetCloseHandle(mhConnection);
|
||||
mhConnection=0;
|
||||
}
|
||||
|
||||
inline
|
||||
HINTERNET Connection::getHANDLE(void)const
|
||||
{
|
||||
return mhConnection;
|
||||
}
|
||||
|
||||
inline
|
||||
bool Connection::isOkay()const
|
||||
{
|
||||
return mhConnection?true:false;
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user