for win32 gui fiber

This commit is contained in:
zsxxsz 2018-01-12 00:28:30 +08:00
parent 5a45a0d886
commit d108b3750a
6 changed files with 57 additions and 52 deletions

View File

@ -726,9 +726,6 @@ EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fiber", "lib_fiber\samples\fiber\fiber_vc2012.vcxproj", "{BFCE4280-B6E5-414A-A8CD-F827A4A19B6F}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WinEchod", "lib_fiber\samples\WinEchod\WinEchod.vcxproj", "{F74A61AD-A309-47A5-A7C6-BAC888660BBC}"
ProjectSection(ProjectDependencies) = postProject
{34506C5D-E131-43BB-9656-BA39F0B56485} = {34506C5D-E131-43BB-9656-BA39F0B56485}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution

View File

@ -12,10 +12,10 @@
#define WM_SOCKET_NOTIFY (WM_USER + 8192)
typedef struct EVENT_WMSG {
EVENT event;
UINT nMsg;
HWND hWnd;
HINSTANCE hInstance;
EVENT event;
UINT nMsg;
HWND hWnd;
HINSTANCE hInstance;
const char *class_name;
FILE_EVENT **files;
int size;
@ -141,7 +141,7 @@ static int wmsg_del_read(EVENT_WMSG *ev, FILE_EVENT *fe)
if (fe->mask & EVENT_WRITE) {
lEvent = FD_CLOSE | FD_WRITE;
} else {
lEvent = 0;
lEvent = FD_CLOSE;
}
fe->mask &= ~EVENT_READ;
@ -191,46 +191,23 @@ static int wmsg_wait(EVENT *ev, int timeout)
if (!res) {
return 0;
}
do {
//if (msg.message != WM_TIMER || msg.hwnd != NULL || msg.wParam != id) {
TranslateMessage(&msg);
DispatchMessage(&msg);
} while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE));
//}
return 0;
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
static int wmsg_handle(EVENT *ev)
{
(void) ev;
return -1;
}
static const char *wmsg_name(void)
{
return "wmsg";
}
static void onClose(EVENT_WMSG *ev, SOCKET fd)
{
FILE_EVENT *fe = wmsg_fdmap_get(ev, fd);
if (fe == NULL) {
/* don nothing */
} else if (fe->mask & EVENT_READ) {
if (fe->r_proc) {
fe->r_proc(&ev->event, fe);
}
} else if (fe->mask & EVENT_WRITE) {
if (fe->w_proc) {
fe->w_proc(&ev->event, fe);
}
}
}
static void onRead(EVENT_WMSG *ev, SOCKET fd)
{
FILE_EVENT *fe = wmsg_fdmap_get(ev, fd);
if (fe == NULL) {
if (fe == NULL || fe->oper & EVENT_DEL_READ) {
msg_error("%s(%d): no FILE_EVENT, fd=%d",
__FUNCTION__, __LINE__, fd);
} else if (fe->r_proc == NULL) {
@ -259,7 +236,7 @@ static void onAccept(EVENT_WMSG *ev, SOCKET fd)
{
FILE_EVENT *fe = wmsg_fdmap_get(ev, fd);
if (fe == NULL) {
msg_fatal("%s(%d): no FILE_EVENT, fd=%d",
msg_error("%s(%d): no FILE_EVENT, fd=%d",
__FUNCTION__, __LINE__, fd);
} else if (fe->r_proc == NULL) {
msg_fatal("%s(%d): r_proc NULL, fd=%d",
@ -274,6 +251,22 @@ static void onConnect(EVENT_WMSG *ev, SOCKET fd)
onWrite(ev, fd);
}
static void onClose(EVENT_WMSG *ev, SOCKET fd)
{
FILE_EVENT *fe = wmsg_fdmap_get(ev, fd);
if (fe == NULL) {
/* don nothing */
} else if (fe->mask & EVENT_READ) {
if (fe->r_proc) {
fe->r_proc(&ev->event, fe);
}
} else if (fe->mask & EVENT_WRITE) {
if (fe->w_proc) {
fe->w_proc(&ev->event, fe);
}
}
}
static LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
EVENT_WMSG *ev = get_hwnd_event(hWnd);
@ -390,7 +383,19 @@ static HWND CreateSockWindow(const char *class_name, HINSTANCE hInstance)
return InitInstance(class_name, hInstance);
}
static int wmsg_handle(EVENT *ev)
{
(void) ev;
return -1;
}
static const char *wmsg_name(void)
{
return "wmsg";
}
static const char *__class_name = "__AclFiberEventsMainWClass";
EVENT *event_wmsg_create(int size)
{
EVENT_WMSG *ew = (EVENT_WMSG *) calloc(1, sizeof(EVENT_WMSG));

View File

@ -16,11 +16,6 @@ static void fiber_win_free(ACL_FIBER *fiber)
stack_free(fb);
}
static void fiber_win_init(ACL_FIBER *fiber, size_t size)
{
}
static void fiber_win_swap(ACL_FIBER *from, ACL_FIBER *to)
{
FIBER_WIN *fb_to = (FIBER_WIN *) to;
@ -33,17 +28,25 @@ static void __stdcall fiber_win_start(LPVOID ctx)
fb->fiber.start_fn(&fb->fiber);
}
static void fiber_win_init(FIBER_WIN *fb, size_t size)
{
if (fb->context) {
DeleteFiber(fb->context);
}
fb->context = CreateFiberEx(size, 0, FIBER_FLAG_FLOAT_SWITCH,
fiber_win_start, fb);
}
ACL_FIBER *fiber_win_alloc(void(*start_fn)(ACL_FIBER *), size_t size)
{
FIBER_WIN *fb = (FIBER_WIN *) calloc(1, sizeof(*fb));
fb->fiber.init_fn = fiber_win_init;
fb->fiber.free_fn = fiber_win_free;
fb->fiber.swap_fn = (void(*)(ACL_FIBER*, ACL_FIBER*)) fiber_win_swap;
fb->fiber.init_fn = (void (*)(ACL_FIBER*, size_t)) fiber_win_init;
fb->fiber.free_fn = fiber_win_free;
fb->fiber.swap_fn = (void (*)(ACL_FIBER*, ACL_FIBER*)) fiber_win_swap;
fb->fiber.start_fn = start_fn;
fb->context = NULL;
fb->context = CreateFiberEx(size, 0, FIBER_FLAG_FLOAT_SWITCH,
fiber_win_start, fb);
return (ACL_FIBER *) fb;
}

View File

@ -24,7 +24,7 @@ void CFiberClient::run(void)
break;
}
buf[ret] = 0;
printf("recv=%d, [%s]\r\n", ret, buf);
//printf("recv=%d, [%s]\r\n", ret, buf);
if (fiber_send(sock, buf, ret, 0) == -1)
{
printf("write error %s\r\n", acl::last_serror());

View File

@ -43,6 +43,7 @@
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<OutDir>.\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>

View File

@ -1,4 +1,3 @@
// WinEchodDlg.cpp : 实现文件
//