From 73301ca8b6965aa1e183c059619fe0a916c5430f Mon Sep 17 00:00:00 2001 From: Lao Ke <36225368+kehengzhong@users.noreply.github.com> Date: Sat, 4 Sep 2021 13:55:44 +0800 Subject: [PATCH] Add files via upload --- include/epcore.h | 4 +++ include/epdns.h | 3 +- include/epiocp.h | 82 +++++++++++++++++++++++++++++++++++++++++++ include/eprawsock.h | 4 +-- include/eptcp.h | 6 ++-- include/epudp.h | 19 ++++++---- include/epump.h | 20 +++++++---- include/epump_local.h | 2 +- include/iodev.h | 15 +++++++- include/worker.h | 4 +-- 10 files changed, 137 insertions(+), 22 deletions(-) create mode 100644 include/epiocp.h diff --git a/include/epcore.h b/include/epcore.h index 39eabca..db23f3e 100644 --- a/include/epcore.h +++ b/include/epcore.h @@ -34,6 +34,10 @@ typedef struct EPCore_ { */ int dispmode; +#ifdef HAVE_IOCP + HANDLE iocp_port; +#endif + /* wake up the epoll_wait/select while waiting in block for the fd-set ready */ #ifdef HAVE_EVENTFD int wakeupfd; diff --git a/include/epdns.h b/include/epdns.h index cf0d6c0..4db238d 100644 --- a/include/epdns.h +++ b/include/epdns.h @@ -353,7 +353,8 @@ typedef struct dns_mgmt_s { CRITICAL_SECTION cacheCS; hashtab_t * cache_table; - iodev_t * cli_dev; + int cli_dev_num; + iodev_t * cli_dev[4]; uint32 msgid; hashtab_t * msg_table; diff --git a/include/epiocp.h b/include/epiocp.h new file mode 100644 index 0000000..e2f96d0 --- /dev/null +++ b/include/epiocp.h @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2003-2021 Ke Hengzhong + * All rights reserved. See MIT LICENSE for redistribution. + */ + +#ifdef HAVE_IOCP + +#ifndef _EPIOCP_H_ +#define _EPIOCP_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef BOOL WINAPI AcceptExPtr(SOCKET, SOCKET, PVOID, DWORD, DWORD, DWORD, LPDWORD, LPOVERLAPPED); +typedef BOOL WINAPI ConnectExPtr(SOCKET, const struct sockaddr *, int, PVOID, DWORD, LPDWORD, LPOVERLAPPED); +typedef void WINAPI GetAcceptExSockaddrsPtr(PVOID, DWORD, DWORD, DWORD, LPSOCKADDR *, LPINT, LPSOCKADDR *, LPINT); + + +#define IOCP_NONE 0 +#define IOCP_READ_IN_PROGRESS 1 +#define IOCP_WRITE_IN_PROGRESS 2 +#define IOCP_ACCEPT_IN_PROGRESS 3 +#define IOCP_CONNECT_IN_PROGRESS 4 + +#define IOCP_BUF_CNT 16 + + +typedef struct iocp_event_st { + + OVERLAPPED ovlap; + int evtype; + + SOCKET fd; + SOCKET clifd; + + ulong devid; + DWORD flags; + + WSABUF bufs[IOCP_BUF_CNT]; + uint16 bufcnt; + int64 ionum; + + int64 mapsize; + HANDLE hmap; + void * pmap; + + uint16 state; + + int len; + uint8 buf[1]; +} iocp_event_t; + +void * iocp_event_alloc (int extsize); +void iocp_event_free (void * vcpe); + +void * iocp_event_accept_post (void * vdev); +void * iocp_event_recv_post (void * vdev, void * pbuf, int len); +void * iocp_event_recvfrom_post (void * vdev, void * pbuf, int len); +void * iocp_event_send_post (void * vdev, void * chunk, int64 pos, int httpchunk); +void * iocp_event_connect_post (void * vdev, char * host, int port, char * lip, int lport, int * retval); +void * iocp_event_ep_connect_post (void * vdev, ep_sockaddr_t * host, char * lip, int lport, int * retval); + + +int epcore_iocp_init (epcore_t * pcore); +int epcore_iocp_clean (epcore_t * pcore); + +int epump_iocp_init (epump_t * epump, int maxfd); +int epump_iocp_clean (epump_t * epump); + +int epump_iocp_setpoll (void * vepump, void * vpdev); +int epump_iocp_clearpoll (void * vepump, void * vpdev); + +int epump_iocp_dispatch (void * veps, btime_t * delay); + +#ifdef __cplusplus +} +#endif + +#endif + +#endif diff --git a/include/eprawsock.h b/include/eprawsock.h index aa8b473..3144b73 100644 --- a/include/eprawsock.h +++ b/include/eprawsock.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2020 Ke Hengzhong + * Copyright (c) 2003-2021 Ke Hengzhong * All rights reserved. See MIT LICENSE for redistribution. */ @@ -7,7 +7,7 @@ #define _EPRAWSOCK_H_ -#ifdef _WIN32 +#if defined(_WIN32) || defined(_WIN64) #if _MSC_VER > 1000 #pragma once diff --git a/include/eptcp.h b/include/eptcp.h index e50421b..ba59aa6 100644 --- a/include/eptcp.h +++ b/include/eptcp.h @@ -12,10 +12,12 @@ extern "C" { void * eptcp_listen_create (void * vpcore, char * localip, int port, void * para, int * retval, - IOHandler * cb, void * cbpara); + IOHandler * cb, void * cbpara, + iodev_t ** devlist, int * devnum); void * eptcp_listen (void * vpcore, char * localip, int port, void * para, int * retval, - IOHandler * cb, void * cbpara, int bindtype); + IOHandler * cb, void * cbpara, int bindtype, + void ** plist, int * listnum); /* Note: automatically detect if Linux kernel supported REUSEPORT. if supported, create listen socket for every current running epump threads diff --git a/include/epudp.h b/include/epudp.h index 36dc143..46b24e9 100644 --- a/include/epudp.h +++ b/include/epudp.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2020 Ke Hengzhong + * Copyright (c) 2003-2021 Ke Hengzhong * All rights reserved. See MIT LICENSE for redistribution. */ @@ -10,17 +10,21 @@ extern "C" { #endif -void * epudp_listen_create (void * vpcore, char * localip, int port, - void * para, int * retval, IOHandler * cb, void * cbpara); +void * epudp_listen_create (void * vpcore, char * localip, int port, void * para, + int * retval, IOHandler * cb, void * cbpara, + iodev_t ** devlist, int * devnum); -void * epudp_listen (void * vpcore, char * localip, int port, - void * para, int * retval, IOHandler * cb, void * cbpara); +void * epudp_listen (void * vpcore, char * localip, int port, void * para, int * pret, + IOHandler * cb, void * cbpara, int bindtype, void ** plist, int * listnum); void * epudp_mlisten (void * vpcore, char * localip, int port, void * para, IOHandler * cb, void * cbpara); -void * epudp_client (void * veps, struct in_addr * localip, int port, - void * para, int * retval, IOHandler * cb, void * cbpara); +void * epudp_client (void * vpcore, char * localip, int port, + void * para, int * retval, IOHandler * cb, void * cbpara, + iodev_t ** devlist, int * devnum); + +int epudp_recvfrom (void * vdev, void * vfrm, void * addr, int * pnum); #ifdef __cplusplus } @@ -28,3 +32,4 @@ void * epudp_client (void * veps, struct in_addr * localip, int port, #endif + diff --git a/include/epump.h b/include/epump.h index 9ec891c..6430c75 100644 --- a/include/epump.h +++ b/include/epump.h @@ -184,7 +184,8 @@ char * mlisten_lip (void * vmln); void * eptcp_listen (void * vpcore, char * localip, int port, void * para, int * retval, - IOHandler * cb, void * cbpara, int bindtype); + IOHandler * cb, void * cbpara, int bindtype, + void ** plist, int * listnum); /* Note: automatically detect if Linux kernel supported REUSEPORT. if supported, create listen socket for every current running epump threads @@ -201,15 +202,22 @@ void * eptcp_connect (void * vpcore, char * ip, int port, char * localip, int localport, void * para, int * retval, IOHandler * cb, void * cbpara); +void * eptcp_nb_connect (void * vpcore, char * host, int port, + char * localip, int localport, void * para, + int * retval, IOHandler * cb, void * cbpara); -void * epudp_listen (void * vpcore, char * localip, int port, - void * para, int * retval, IOHandler * cb, void * cbpara); - -void * epudp_client (void * veps, char * localip, int port, - void * para, int * retval, IOHandler * cb, void * cbpara); +void * epudp_listen (void * vpcore, char * localip, int port, void * para, int * pret, + IOHandler * cb, void * cbpara, int bindtype, void ** plist, int * listnum); + void * epudp_mlisten (void * vpcore, char * localip, int port, void * para, IOHandler * cb, void * cbpara); + +void * epudp_client (void * vpcore, char * localip, int port, + void * para, int * retval, IOHandler * cb, void * cbpara, + iodev_t ** devlist, int * devnum); + +int epudp_recvfrom (void * vdev, void * vfrm, void * addr, int * pnum); void * epusock_connect (void * vpcore, char * sockname, void * para, diff --git a/include/epump_local.h b/include/epump_local.h index 535a1a2..5c51ce8 100644 --- a/include/epump_local.h +++ b/include/epump_local.h @@ -79,7 +79,7 @@ typedef struct EPump_ { /* current threads management */ ulong threadid; -#ifdef _WIN32 +#if defined(_WIN32) || defined(_WIN64) HANDLE epumphandle; #endif diff --git a/include/iodev.h b/include/iodev.h index aeafadf..d5c92f5 100644 --- a/include/iodev.h +++ b/include/iodev.h @@ -9,6 +9,7 @@ #include "btype.h" #include "tsock.h" #include "mthread.h" +#include "frame.h" #ifdef __cplusplus extern "C" { @@ -69,6 +70,10 @@ typedef struct IODevice_ { SOCKET fd; int fdtype; + int family; + int socktype; + int protocol; + void * para; IOHandler * callback; void * cbpara; @@ -80,7 +85,15 @@ typedef struct IODevice_ { uint8 rwflag; uint8 iostate; - uint32 epev; + +#ifdef HAVE_IOCP + void * devfifo; + frame_t * rcvfrm; + ep_sockaddr_t sock; + int socklen; + int iocprecv; + int iocpsend; +#endif void * iot; diff --git a/include/worker.h b/include/worker.h index 480edaa..54dd0b1 100644 --- a/include/worker.h +++ b/include/worker.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2020 Ke Hengzhong + * Copyright (c) 2003-2021 Ke Hengzhong * All rights reserved. See MIT LICENSE for redistribution. */ @@ -29,7 +29,7 @@ typedef struct Worker_s { /* current threads management */ ulong threadid; -#ifdef _WIN32 +#if defined(_WIN32) || defined(_WIN64) HANDLE hworker; #endif