add a method for init native socket library

Fixed #6
This commit is contained in:
Kirigaya Kazuto 2018-09-09 16:11:28 +08:00
parent bd3bd376f6
commit 1c4e3e5f24
2 changed files with 29 additions and 16 deletions

View File

@ -56,10 +56,7 @@ using BYTE = unsigned char;
#include <stdexcept>
#include <vector>
class _init_winsock2_2_class
{
public:
_init_winsock2_2_class()
int InitNativeSocket()
{
myliblog("sockaddr %d sockaddr_in %d sockaddr_in6 %d\n", sizeof(sockaddr), sizeof(sockaddr_in), sizeof(sockaddr_in6));
/// Windows Platform need WinSock2.DLL initialization.
@ -74,9 +71,22 @@ public:
if (ret < 0)
{
myliblog("WSAGetLastError: %d\n", WSAGetLastError());
throw std::runtime_error("Unable to load winsock2.dll. ");
return -1;
}
#endif
return 0;
}
class _init_winsock2_2_class
{
public:
_init_winsock2_2_class()
{
if (InitNativeSocket() < 0)
{
throw std::runtime_error("Unable to Initialize native socket libray.");
}
}
~_init_winsock2_2_class()
{

View File

@ -10,6 +10,8 @@
#include <string>
#include <vector>
int InitNativeSocket();
enum
{
GSOCK_OK = 0,
@ -247,6 +249,7 @@ public:
// Call handle() to handle events
int wait(int timeout);
// callback: void event_handler(vsock& s,int event)
void handle(const std::function<void(vsock&,int)>& callback);
~epoll();