Skip to content

Commit

Permalink
Merge pull request #1 from SinuxLee/feature/winIocp
Browse files Browse the repository at this point in the history
merge win iocp
  • Loading branch information
SinuxLee authored Jul 20, 2019
2 parents bbbe911 + 373b941 commit 10f2900
Show file tree
Hide file tree
Showing 33 changed files with 6,362 additions and 18 deletions.
19 changes: 19 additions & 0 deletions Makefile.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
SOURCE = src/ae.c src/anet.c src/adlist.c src/Win32_Interop/*.c src/Win32_Interop/*.cpp
LIB_TARGET = libae.lib
LIBS = ws2_32.lib User32.lib libae.lib
LINK_FLAG = /DEBUG /subsystem:console

$(LIB_TARGET):
@cl /EHsc /D_WIN32 /c $(SOURCE)
@link -lib *.obj /out:$(LIB_TARGET)

timer:
@cl /c example\timer.c
@link $(LINK_FLAG) timer.obj $(LIBS) /OUT:timer.exe

echo:
@cl /c example\echo.c
@link $(LINK_FLAG) echo.obj $(LIBS) /OUT:echo.exe

clean:
@del *.exe *.obj *.lib *.ilk *.pdb
17 changes: 10 additions & 7 deletions example/echo.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#ifndef _WIN32
#include <unistd.h>
#endif

#include "../src/ae.h"
#include "../src/anet.h"

void writeToClient(aeEventLoop *loop, int fd, void *clientdata, int mask)
{
char *buffer = clientdata;
printf("%p\n", clientdata);
printf("%s\n", buffer);
write(fd, buffer, strlen(buffer));
free(buffer);
aeDeleteFileEvent(loop, fd, mask);
Expand All @@ -20,10 +22,11 @@ void readFromClient(aeEventLoop *loop, int fd, void *clientdata, int mask)
{
int buffer_size = 1024;
char *buffer = malloc(sizeof(char) * buffer_size);
bzero(buffer, buffer_size);
memset(buffer, 0x00, sizeof(char) * buffer_size);
int size;
size = read(fd, buffer, buffer_size);
if (size == 0)

if (size <= 0)
{
printf("Client disconnected\n");
free(buffer);
Expand Down Expand Up @@ -53,14 +56,14 @@ void acceptTcpHandler(aeEventLoop *loop, int fd, void *clientdata, int mask)
int main()
{
int ipfd;
// create main event loop
aeEventLoop *loop;
loop = aeCreateEventLoop(1024);

// create server socket
ipfd = anetTcpServer(NULL, 8000, "0.0.0.0", 0);
assert(ipfd != ANET_ERR);

// create main event loop
aeEventLoop *loop;
loop = aeCreateEventLoop(1024);

// regist socket connect callback
int ret;
ret = aeCreateFileEvent(loop, ipfd, AE_READABLE, acceptTcpHandler, NULL);
Expand Down
Loading

0 comments on commit 10f2900

Please sign in to comment.