build ok for windows

This commit is contained in:
郑树新 2022-10-23 18:08:20 +08:00
parent 91b592152d
commit 106283c9f4
9 changed files with 34 additions and 23 deletions

View File

@ -189,7 +189,12 @@ struct FILE_EVENT {
IOCP_EVENT *poller_write;
socket_t iocp_sock;
int sock_type;
struct sockaddr_in addr;
union {
struct {
struct sockaddr_in addr;
socklen_t len;
} peer;
} var;
#endif
int refer;
};

View File

@ -344,7 +344,7 @@ int event_iocp_connect(EVENT *ev, FILE_EVENT *fe)
memset(&event->overlapped, 0, sizeof(event->overlapped));
ret = lpfnConnectEx(fe->fd,
(const struct sockaddr *) &fe->addr,
(const struct sockaddr *) &fe->var.peer.addr,
sizeof(struct sockaddr),
NULL,
0,

View File

@ -35,17 +35,17 @@ void file_event_init(FILE_EVENT *fe, socket_t fd)
#endif
#ifdef HAS_IOCP
fe->buff = NULL;
fe->size = 0;
fe->len = 0;
fe->h_iocp = NULL;
fe->reader = NULL;
fe->writer = NULL;
fe->rbuf = NULL;
fe->rsize = 0;
fe->rlen = 0;
fe->h_iocp = NULL;
fe->reader = NULL;
fe->writer = NULL;
fe->poller_read = NULL;
fe->poller_write = NULL;
fe->iocp_sock = INVALID_SOCKET;
fe->sock_type = getsocktype(fd);
memset(&fe->peer_addr, 0, sizeof(fe->peer_addr));
memset(&fe->var, 0, sizeof(fe->var));
#endif
fe->refer = 1;

View File

@ -221,11 +221,11 @@ static POLLFD *pollfd_alloc(POLL_EVENT *pe, struct pollfd *fds, nfds_t nfds)
pfds[i].fe = fiber_file_open_write(fds[i].fd);
}
#ifdef HAS_IOCP
pfds[i].fe->buff = NULL;
pfds[i].fe->size = 0;
pfds[i].fe->rbuf = NULL;
pfds[i].fe->rsize = 0;
#endif
pfds[i].pe = pe;
pfds[i].pfd = &fds[i];
pfds[i].pe = pe;
pfds[i].pfd = &fds[i];
pfds[i].pfd->revents = 0;
SET_POLLING(pfds[i].fe);
}

View File

@ -88,7 +88,7 @@
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>false</SDLCheck>
<AdditionalIncludeDirectories>..\..\c\include; ..\..\..\lib_acl\include;..\</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
@ -115,7 +115,7 @@
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;ACL_DLL;FIBER_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;ACL_DLL;FIBER_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>false</SDLCheck>
<AdditionalIncludeDirectories>..\..\c\include; ..\..\..\lib_acl\include;..\</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
@ -141,7 +141,7 @@ copy ..\..\c\libfiber.dll .\ /Y</Command>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;ACL_DLL;FIBER_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;ACL_DLL;FIBER_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>false</SDLCheck>
<AdditionalIncludeDirectories>..\..\c\include; ..\..\..\lib_acl\include;..\</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
@ -168,7 +168,7 @@ copy ..\..\c\libfiber.dll .\ /Y</Command>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>false</SDLCheck>
<AdditionalIncludeDirectories>..\..\c\include; ..\..\..\lib_acl\include;..\</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
@ -183,6 +183,7 @@ copy ..\..\c\libfiber.dll .\ /Y</Command>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\patch.c" />
<ClCompile Include="main.c" />
</ItemGroup>
<ItemGroup>

View File

@ -51,7 +51,12 @@ static int check_write(SOCKET fd, int timeout)
pfd.fd = fd;
pfd.events = POLLOUT;
#if defined(_WIN32) || defined(_WIN64)
n = WSAPoll(&pfd, 1, timeout);
#else
n = poll(&pfd, 1, timeout);
#endif
if (n < 0) {
printf("poll error: %s\r\n", acl_last_serror());
return -1;

View File

@ -131,7 +131,7 @@ int set_non_blocking(SOCKET fd, int on)
int flags = 0;
if (ioctlsocket(fd, FIONBIO, &n) < 0) {
msg_error("ioctlsocket(fd,FIONBIO) failed");
printf("ioctlsocket(fd,FIONBIO) failed\r\n");
return -1;
}
return flags;

View File

@ -11,7 +11,7 @@ extern "C" {
# define snprintf _snprintf
extern int optind;
extern char *optarg;
int getopt(int argc, char * const argv[], char *opts);
int getopt(int argc, char *argv[], const char *opts);
#else
# define SOCKET int
# define INVALID_SOCKET -1

View File

@ -132,8 +132,8 @@
</IgnoreSpecificDefaultLibraries>
</Link>
<PostBuildEvent>
<Command>copy ..\..\..\lib_acl\lib_acl_d.dll .\ /Y
copy ..\..\c\libfiber.dll .\ /Y</Command>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseDll|Win32'">
@ -158,8 +158,8 @@ copy ..\..\c\libfiber.dll .\ /Y</Command>
</IgnoreSpecificDefaultLibraries>
</Link>
<PostBuildEvent>
<Command>copy ..\..\..\lib_acl\lib_acl.dll .\ /Y
copy ..\..\c\libfiber.dll .\ /Y</Command>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">