Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
kehengzhong authored Sep 4, 2021
1 parent cb0fab6 commit 73301ca
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 22 deletions.
4 changes: 4 additions & 0 deletions include/epcore.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion include/epdns.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
82 changes: 82 additions & 0 deletions include/epiocp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright (c) 2003-2021 Ke Hengzhong <[email protected]>
* 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
4 changes: 2 additions & 2 deletions include/eprawsock.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
* Copyright (c) 2003-2020 Ke Hengzhong <[email protected]>
* Copyright (c) 2003-2021 Ke Hengzhong <[email protected]>
* All rights reserved. See MIT LICENSE for redistribution.
*/

#ifndef _EPRAWSOCK_H_
#define _EPRAWSOCK_H_


#ifdef _WIN32
#if defined(_WIN32) || defined(_WIN64)

#if _MSC_VER > 1000
#pragma once
Expand Down
6 changes: 4 additions & 2 deletions include/eptcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 12 additions & 7 deletions include/epudp.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003-2020 Ke Hengzhong <[email protected]>
* Copyright (c) 2003-2021 Ke Hengzhong <[email protected]>
* All rights reserved. See MIT LICENSE for redistribution.
*/

Expand All @@ -10,21 +10,26 @@
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
}
#endif

#endif


20 changes: 14 additions & 6 deletions include/epump.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion include/epump_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ typedef struct EPump_ {

/* current threads management */
ulong threadid;
#ifdef _WIN32
#if defined(_WIN32) || defined(_WIN64)
HANDLE epumphandle;
#endif

Expand Down
15 changes: 14 additions & 1 deletion include/iodev.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "btype.h"
#include "tsock.h"
#include "mthread.h"
#include "frame.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -69,6 +70,10 @@ typedef struct IODevice_ {
SOCKET fd;
int fdtype;

int family;
int socktype;
int protocol;

void * para;
IOHandler * callback;
void * cbpara;
Expand All @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions include/worker.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003-2020 Ke Hengzhong <[email protected]>
* Copyright (c) 2003-2021 Ke Hengzhong <[email protected]>
* All rights reserved. See MIT LICENSE for redistribution.
*/

Expand Down Expand Up @@ -29,7 +29,7 @@ typedef struct Worker_s {

/* current threads management */
ulong threadid;
#ifdef _WIN32
#if defined(_WIN32) || defined(_WIN64)
HANDLE hworker;
#endif

Expand Down

0 comments on commit 73301ca

Please sign in to comment.