Skip to content

Commit

Permalink
修复Cygwin下的套接字错误
Browse files Browse the repository at this point in the history
  • Loading branch information
HEYAHONG committed Jan 10, 2025
1 parent aaca153 commit e90c146
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
10 changes: 10 additions & 0 deletions hcppbox/HCPPSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
**************************************************************/
#include "HCPPSocket.h"
#ifdef HCPPSOCKET_HAVE_SOCKET
#ifdef __CYGWIN__
void HCPPSocketCygwinHelperStartup();
void HCPPSocketCygwinHelperCleanup();
#endif // __CYGWIN__
static class socket_manager
{
public:
Expand All @@ -28,12 +32,18 @@ static class socket_manager
}
}
#endif
#ifdef __CYGWIN__
HCPPSocketCygwinHelperStartup();
#endif // __CYGWIN__
}
~socket_manager()
{
#ifdef WIN32
WSACleanup();
#endif
#ifdef __CYGWIN__
HCPPSocketCygwinHelperCleanup();
#endif // __CYGWIN__
}
} g_socket_manager;

Expand Down
37 changes: 37 additions & 0 deletions hcppbox/HCPPSocketCygwinHelper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/***************************************************************
* Name: HCPPSocketCygwinHelper.cpp
* Purpose: HCPPSocketCygwinHelper
* Author: HYH (hyhsystem.cn)
* Created: 2024-01-10
* Copyright: HYH (hyhsystem.cn)
* License: MIT
**************************************************************/

#ifdef __CYGWIN__

#include "winsock2.h"
#include "windows.h"

void HCPPSocketCygwinHelperStartup()
{
WSADATA wsaData;
const WORD VersionList[]=
{
(2 << 8) | 2,
(1 << 8) | 1,
};
for(size_t i=0; i<sizeof(VersionList)/sizeof(VersionList[0]); i++)
{
if(WSAStartup(VersionList[i],&wsaData)==0)
{
break;
}
}
}

void HCPPSocketCygwinHelperCleanup()
{
WSACleanup();
}

#endif // __CYGWIN__
11 changes: 11 additions & 0 deletions hcppbox/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,17 @@
- HCPPTimer.cpp
- HCPPTimer.h

## HCPPSocket

对各种操作系统的套接字进行一定的封装,用于编写更加通用的套接字程序。

### 文件列表

- HCPPSocket.cpp
- HCPPSocketCygwinHelper.cpp

- HCPPSocket.h

## HCPPInit

辅助实现动态注册初始化函数且按照一定顺序初始化。
Expand Down

0 comments on commit e90c146

Please sign in to comment.