mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2025-05-15 09:18:27 +00:00
Added WSInit class to initialize WinSock2.
This commit is contained in:
parent
1b2f37e241
commit
767ed02280
1 changed files with 16 additions and 24 deletions
40
httplib.h
40
httplib.h
|
@ -87,7 +87,6 @@ public:
|
||||||
typedef std::function<void (const Request&, const Response&)> Logger;
|
typedef std::function<void (const Request&, const Response&)> Logger;
|
||||||
|
|
||||||
Server();
|
Server();
|
||||||
~Server();
|
|
||||||
|
|
||||||
void get(const char* pattern, Handler handler);
|
void get(const char* pattern, Handler handler);
|
||||||
void post(const char* pattern, Handler handler);
|
void post(const char* pattern, Handler handler);
|
||||||
|
@ -116,7 +115,6 @@ private:
|
||||||
class Client {
|
class Client {
|
||||||
public:
|
public:
|
||||||
Client(const char* host, int port);
|
Client(const char* host, int port);
|
||||||
~Client();
|
|
||||||
|
|
||||||
std::shared_ptr<Response> get(const char* url);
|
std::shared_ptr<Response> get(const char* url);
|
||||||
std::shared_ptr<Response> head(const char* url);
|
std::shared_ptr<Response> head(const char* url);
|
||||||
|
@ -504,6 +502,22 @@ inline void parse_query_text(const std::string& s, Map& params)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
class WSInit {
|
||||||
|
public:
|
||||||
|
WSInit::WSInit() {
|
||||||
|
WSADATA wsaData;
|
||||||
|
WSAStartup(0x0002, &wsaData);
|
||||||
|
}
|
||||||
|
|
||||||
|
WSInit::~WSInit() {
|
||||||
|
WSACleanup();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
static WSInit wsinit_;
|
||||||
|
#endif
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
// Request implementation
|
// Request implementation
|
||||||
|
@ -559,17 +573,6 @@ inline void Response::set_content(const std::string& s, const char* content_type
|
||||||
inline Server::Server()
|
inline Server::Server()
|
||||||
: svr_sock_(-1)
|
: svr_sock_(-1)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
|
||||||
WSADATA wsaData;
|
|
||||||
WSAStartup(0x0002, &wsaData);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Server::~Server()
|
|
||||||
{
|
|
||||||
#ifdef _WIN32
|
|
||||||
WSACleanup();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void Server::get(const char* pattern, Handler handler)
|
inline void Server::get(const char* pattern, Handler handler)
|
||||||
|
@ -730,17 +733,6 @@ inline Client::Client(const char* host, int port)
|
||||||
: host_(host)
|
: host_(host)
|
||||||
, port_(port)
|
, port_(port)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
|
||||||
WSADATA wsaData;
|
|
||||||
WSAStartup(0x0002, &wsaData);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Client::~Client()
|
|
||||||
{
|
|
||||||
#ifdef _WIN32
|
|
||||||
WSACleanup();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Client::read_response_line(FILE* fp, Response& res)
|
inline bool Client::read_response_line(FILE* fp, Response& res)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue