flat assembler
Message board for the users of flat assembler.
Index
> Projects and Ideas > let's build a LIBEVENT webserver without websocket + json Goto page 1, 2, 3 Next |
Author |
|
sleepsleep 09 Feb 2012, 07:13
hi there,
how bout let's build a robust portable WSAAsyncSelect webserver together? who wanna join, using win32ax.inc, make it as simple as possible then only we add other features. 2012-02-11 11:53PM [ok] i think i fix the buffer for incoming socket, and buffer for holding x unit of client socket structure [ok] i plan to do find CR,LF on incoming http response, write first line to log, then parse the incoming header data. i plan to DOC_ROOT for serving file i plan to test how it performs under multi connected user (eg, some downloading big file, some surfing pages) i need to clear about connection:close, keep-alive, how to determine those states i have question regarding before the RECV function, where windows put those data? what is the size of windows or winsock buffer for that part. 2012-02-13 09:54PM next is using FindFirstFile to get file handle and return the file to requested client socket. will try open several browser clients and download > 500mb files concurrently and hopefully our server functions normally. will only check for several common mime file type based on extension. will code HttpReplyBufferPrepare. thank you.
Last edited by sleepsleep on 09 Jul 2012, 11:01; edited 5 times in total |
|||||||||||
09 Feb 2012, 07:13 |
|
JohnFound 09 Feb 2012, 07:27
How you will make portable web server, using Win32 API?
|
|||
09 Feb 2012, 07:27 |
|
JohnFound 09 Feb 2012, 07:57
Ah, I got it now.
But why not to make it portable in terms of OS as well? |
|||
09 Feb 2012, 07:57 |
|
sleepsleep 09 Feb 2012, 08:35
it needs more effort to start it first,
more and more more more effort to make it runs and everybody happy. so, right now, i think the best way is, target window first, then we see how later. |
|||
09 Feb 2012, 08:35 |
|
revolution 09 Feb 2012, 11:39
Let me know when you get around to adding the SSL code.
The rest of it, the general listener portion, is the easy part. And you can probably find a lot of asm code already written to do listening and basic page and/or application serving. |
|||
09 Feb 2012, 11:39 |
|
sleepsleep 09 Feb 2012, 12:46
no problem revolution, hope this project could reach that stage.
i will upload a basic one later and then let see how many fasmer interested to chip in ideas or better more efficient method. |
|||
09 Feb 2012, 12:46 |
|
sleepsleep 10 Feb 2012, 00:12
ok, a simple GUI that listen 80.
Code: WM_SLSOCKET = WM_USER + 1 .if [wmsg] = WM_SLSOCKET mov eax,[lparam] and eax,0xffff .if eax = FD_CLOSE invoke closesocket,[wparam] stdcall FileWriteLog,[logHandle],<'- FD_CLOSE',CR,LF> .elseif eax = FD_ACCEPT stdcall FileWriteLog,[logHandle],<'- FD_ACCEPT',CR,LF> .elseif eax = FD_READ stdcall FileWriteLog,[logHandle],<'- FD_READ',CR,LF> .endif .elseif [wmsg] = WM_DESTROY invoke PostQuitMessage,0 xor eax,eax jmp .finish .endif you could use FileWriteLog for debug purpose, next is accept client, i was thinking about virtualalloc to save array list accepted client socket handle struct clientsockinfo s dd 0 ; client socket ssend dd 0 ; bytes sent, so max is 0xFFFF FFFF? srecv dd 0 ; bytes received buffer dd 0 ; memory address we alloc for socket through virtualalloc? ends if we want to prevent the ddos, then we need to record each connected ip, set a limit of connection within certain time-frame OR we should just leave this ddos job to router?? i read some MSDN page, it mentioned that we could just use send() and no need to handle FD_WRITE, so what are the pros & cons if we handle our FD_WRITE VS we should just invoke send and let window finish the job (assume we can't handle it better than them)?
|
|||||||||||
10 Feb 2012, 00:12 |
|
sleepsleep 10 Feb 2012, 08:24
ok, i made a little bit progress,
now, it should capable to accept multiple client, up to Code: invoke listen,[wsListener],0xFF SOCKETCLIENTINFO_POOL = 1000 invoke VirtualAlloc,NULL,sizeof.SOCKET_CLIENTINFO * SOCKETCLIENTINFO_POOL,MEM_COMMIT,PAGE_READWRITE struct SOCKET_CLIENTINFO ssock dd 0 ; the thing ssend dd 0 srecv dd 0 sbuff dd 0 ends the WM_SLSOCKET modifed Code: .if eax = FD_CLOSE ;stdcall FileWriteLog,[logHandle],<'- FD_CLOSE',CR,LF> invoke closesocket,[wparam] stdcall SocketFree,[wparam] .elseif eax = FD_ACCEPT ;stdcall FileWriteLog,[logHandle],<'- FD_ACCEPT',CR,LF> invoke accept,[wparam],NULL,NULL inc [memSocketClientCount] push eax invoke WSAAsyncSelect,eax,[hwnd],WM_SLSOCKET,FD_READ + FD_CLOSE pop eax stdcall SocketNew,eax .elseif eax = FD_READ stdcall FileWriteLog,[logHandle],<'- FD_READ',CR,LF> stdcall SocketGetClient,[wparam] invoke recv,[wparam],[eax + SOCKET_CLIENTINFO.sbuff],4095,0 ; we do some process here then send() without doing FD_WRITE fttb invoke send,[wparam],defaultResponse,<invoke lstrlen,defaultResponse>,0 stdcall FileWriteLog,[logHandle],buffSocketClient stdcall FileWriteLog,[logHandle],<CR,LF> .endif Code: proc SocketNew ssock stdcall FileWriteLog,[logHandle],<'- SocketNew',CR,LF> stdcall SocketGetClient,0 mov edx,[ssock] mov [eax + SOCKET_CLIENTINFO.ssock],edx mov [eax + SOCKET_CLIENTINFO.sbuff],buffSocketClient ret endp proc SocketGetClient val stdcall FileWriteLog,[logHandle],<'- SocketGetClient',CR,LF> mov eax,[memSocketClientInfo] mov edx,[val] .while DWORD [eax] <> edx add eax,sizeof.SOCKET_CLIENTINFO .endw ret endp proc SocketFree ssock stdcall FileWriteLog,[logHandle],<'- SocketFree',CR,LF> stdcall SocketGetClient,[ssock] mov [eax + SOCKET_CLIENTINFO.sbuff],0 ret endp and the defaultResponse is Code: db "HTTP/1.0 200 OK",13,10 db "Server : Gserver",13,10 db "Content-Type: text/html; charset=UTF-8",13,10 db "Content-Length: 13",13,10 db "Connection: close",13,10,13,10 db "<h1>Fasm</h1>",0 |
|||
10 Feb 2012, 08:24 |
|
sleepsleep 10 Feb 2012, 08:36
next is how to parse the recv data http request data
is it CR,LF for windows browser, CR from linux or, CR,LF is universal? i was thinking reading only up to 0xFF, if no CR,LF then, closesocket is there any available Find String or Find CR LF function? thanks. |
|||
10 Feb 2012, 08:36 |
|
sleepsleep 11 Feb 2012, 10:27
ok,
i manage to do a few updates. i add this Code: SOCKETCLIENTINFO_POOL = 1000 SOCKETCLIENT_HTTPBUFF = 0xFFF SOCKETCLIENT_HTTPBUFF_POOL = 7 the HTTPBUFF defined the size of memory space for recv to use. the HTTPBUFF_POOL * HTTBUFF is the total size we allocate under one time VirtualAlloc. but there is a bug there, i haven't manage to find it eg. first few connection will return http response, but then failed for 1 or 2 connection, then ok back, Last edited by sleepsleep on 11 Feb 2012, 16:01; edited 1 time in total |
|||
11 Feb 2012, 10:27 |
|
sleepsleep 11 Feb 2012, 14:20
ok, i think i nail the bug already, somewhere i forgot to put a RET in a proc...
so, i got a buffer space already for RECV, now is parsing the HTTP receive header, anyone want to chip in a PROC was thinking about using FASMLIB since everything is written already in there i guess. |
|||
11 Feb 2012, 14:20 |
|
sleepsleep 11 Feb 2012, 15:54
i think i just always update the latest in the first post, instead of user scrolling hell to lower page...
|
|||
11 Feb 2012, 15:54 |
|
JohnFound 11 Feb 2012, 17:03
If you want to create serious project, it is good idea to use some version control system. I personally prefer fossil. You can host fossil repositories for free on http://chiselapp.com/
|
|||
11 Feb 2012, 17:03 |
|
asmhack 11 Feb 2012, 17:50
Code: proc FindCRLF lpBuffer mov eax, -1 mov esi, [lpBuffer] test esi, esi jz .notfound .scan: inc eax cmp eax, SOCKETCLIENT_HTTPBUFF ja .notfound cmp word [esi + eax], 0x0a0d jnz .scan ret .notfound: mov eax, -1 ret endp ;;eax=length in bytes, else -1 Last edited by asmhack on 12 Feb 2012, 18:56; edited 1 time in total |
|||
11 Feb 2012, 17:50 |
|
sleepsleep 12 Feb 2012, 06:05
thanks asmhack, i will put it under webserver_string.asm
|
|||
12 Feb 2012, 06:05 |
|
sleepsleep 12 Feb 2012, 18:04
it seems that
Code: cmp word [esi + eax], 0xd0a doesn't work but Code: cmp word [esi + eax],0x0a0d works. |
|||
12 Feb 2012, 18:04 |
|
asmhack 12 Feb 2012, 18:54
Thanks for labeling that out. I'll edit my post.
|
|||
12 Feb 2012, 18:54 |
|
sleepsleep 13 Feb 2012, 13:58
we could parsing GET filename now, here is little bit of the snippet, it is highly inefficient asm code, so please try improve it by all means.
Code: buffHttpRequestFilename db 0xFFF dup (0) stdcall StringGetCrlf, [ssockbuff] cmp eax,-1 je .noCRLF mov edx,[ssockbuff] cmp DWORD [edx],'GET ' jne .noGET add edx,4 cmp BYTE [edx],'/' jne .noGET cmp WORD [edx],'/ ' je .goGETDefault inc edx mov ecx,eax sub ecx,5 mov ebx,buffHttpRequestFilename pusha .copypad0: mov al, byte [edx] mov byte [ebx],al inc edx inc ebx cmp byte [edx],' ' je .pad0 loop .copypad0 .pad0: popa mov byte [ebx],0 |
|||
13 Feb 2012, 13:58 |
|
f0dder 29 Feb 2012, 17:25
Why did you go for the WSAAsyncSelect model?
It might be relatively simple and all, but it's very poor performance (doesn't matter until you need many clients and/or high throughput, but then you'll regret your choice), and there's lots of situations where you don't need a GUI for a server app. |
|||
29 Feb 2012, 17:25 |
|
Goto page 1, 2, 3 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.