mirror of
https://github.com/Kiritow/GSock.git
synced 2024-03-22 13:10:51 +08:00
parent
bd3bd376f6
commit
1c4e3e5f24
30
gsock.cpp
30
gsock.cpp
|
@ -56,27 +56,37 @@ using BYTE = unsigned char;
|
|||
#include <stdexcept>
|
||||
#include <vector>
|
||||
|
||||
class _init_winsock2_2_class
|
||||
int InitNativeSocket()
|
||||
{
|
||||
public:
|
||||
_init_winsock2_2_class()
|
||||
{
|
||||
myliblog("sockaddr %d sockaddr_in %d sockaddr_in6 %d\n", sizeof(sockaddr), sizeof(sockaddr_in), sizeof(sockaddr_in6));
|
||||
/// Windows Platform need WinSock2.DLL initialization.
|
||||
#ifdef _WIN32
|
||||
WORD wd;
|
||||
WSAData wdt;
|
||||
wd=MAKEWORD(2,2);
|
||||
int ret=WSAStartup(wd,&wdt);
|
||||
wd = MAKEWORD(2, 2);
|
||||
int ret = WSAStartup(wd, &wdt);
|
||||
|
||||
myliblog("WSAStartup() Returns: %d\n",ret);
|
||||
myliblog("WSAStartup() Returns: %d\n", ret);
|
||||
|
||||
if(ret<0)
|
||||
if (ret < 0)
|
||||
{
|
||||
myliblog("WSAGetLastError: %d\n",WSAGetLastError());
|
||||
throw std::runtime_error("Unable to load winsock2.dll. ");
|
||||
myliblog("WSAGetLastError: %d\n", WSAGetLastError());
|
||||
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()
|
||||
{
|
||||
|
|
3
gsock.h
3
gsock.h
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue
Block a user