mirror of
https://github.com/Kiritow/GSock.git
synced 2024-03-22 13:10:51 +08:00
parent
bd3bd376f6
commit
1c4e3e5f24
20
gsock.cpp
20
gsock.cpp
|
@ -56,10 +56,7 @@ using BYTE = unsigned char;
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <vector>
|
#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));
|
myliblog("sockaddr %d sockaddr_in %d sockaddr_in6 %d\n", sizeof(sockaddr), sizeof(sockaddr_in), sizeof(sockaddr_in6));
|
||||||
/// Windows Platform need WinSock2.DLL initialization.
|
/// Windows Platform need WinSock2.DLL initialization.
|
||||||
|
@ -74,9 +71,22 @@ public:
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
myliblog("WSAGetLastError: %d\n", WSAGetLastError());
|
myliblog("WSAGetLastError: %d\n", WSAGetLastError());
|
||||||
throw std::runtime_error("Unable to load winsock2.dll. ");
|
return -1;
|
||||||
}
|
}
|
||||||
#endif
|
#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()
|
~_init_winsock2_2_class()
|
||||||
{
|
{
|
||||||
|
|
3
gsock.h
3
gsock.h
|
@ -10,6 +10,8 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
int InitNativeSocket();
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
GSOCK_OK = 0,
|
GSOCK_OK = 0,
|
||||||
|
@ -247,6 +249,7 @@ public:
|
||||||
// Call handle() to handle events
|
// Call handle() to handle events
|
||||||
int wait(int timeout);
|
int wait(int timeout);
|
||||||
|
|
||||||
|
// callback: void event_handler(vsock& s,int event)
|
||||||
void handle(const std::function<void(vsock&,int)>& callback);
|
void handle(const std::function<void(vsock&,int)>& callback);
|
||||||
|
|
||||||
~epoll();
|
~epoll();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user