Problems in Windows with HTTP-REST API Skeleton

Just starting out? Need help? Post your questions and find answers here.
jakobssystems
User
User
Posts: 12
Joined: Thu Apr 10, 2025 5:17 pm

Re: Problems in Windows with HTTP-REST API Skeleton

Post by jakobssystems »

infratec wrote: Fri Apr 11, 2025 6:18 pm It does not crash here at the CloseConnection() line (WIn10 x64 PB 621b2 x86)
But it crashed once in Select NetworkServerEvent()
So I modified it a bit and then it runs smooth:
Adopted your modification but it still keeps crashing here. The first request/response runs, but then it fails.
I am on 64iBit on Win2019

I've made two Screenshots in Windows:
Image

And one in Wine on GNU/Linux. At least there is more information:
Image
infratec
Always Here
Always Here
Posts: 7618
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Problems in Windows with HTTP-REST API Skeleton

Post by infratec »

Your PeekS() usage is wrong:

Code: Select all

Header = PeekS(*buffer, headerEndPos, #PB_UTF8)
Body = PeekS(*buffer + headerEndPos + 4, totalReceived - headerEndPos - 4, #PB_UTF8)
Should be:

Code: Select all

Header = PeekS(*buffer, headerEndPos, #PB_UTF8|#PB_ByteLength)
Body = PeekS(*buffer + headerEndPos + 4, totalReceived - headerEndPos - 4, #PB_UTF8|#PB_ByteLength)
also later:

Code: Select all

body + PeekS(*tempBuffer, received, #PB_UTF8|#PB_ByteLength)
And have you enabled the purifier and set the granularity to 1,1,1,1

Code: Select all

PurifierGranularity(1, 1, 1, 1)
infratec
Always Here
Always Here
Posts: 7618
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Problems in Windows with HTTP-REST API Skeleton

Post by infratec »

In general, your handling is wrong.

You don't wait if the client disconnects after all.
You don't wait for further network events of the same client.
You close the network connection directly after sending the Hello. This can be wrong, since the network stack is asynchron,
and I don't know if the send operation is already finished when you close the connection.

You should use a client map and check for each incoming network event if the client is already available or not.
f he sends a disconnect, then close the connection. Or close it after a timeout after the last data received.
Then you don't run in a to early closing.
User avatar
idle
Always Here
Always Here
Posts: 5897
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Problems in Windows with HTTP-REST API Skeleton

Post by idle »

you can take a look here, it uses a similar pattern to infratec's suggestion
https://github.com/idle-PB/atomic_webserver_3
look at
https://github.com/idle-PB/atomic_webse ... erver3.pbi
Atomic_Server_Thread
Atomic_Server_ProcessRequest

There's rather a lot going on in the code but you should be able to find the salient bits and how it's handling it.

[/code]
jakobssystems
User
User
Posts: 12
Joined: Thu Apr 10, 2025 5:17 pm

Re: Problems in Windows with HTTP-REST API Skeleton

Post by jakobssystems »

First thank you all for your input.. right now i am rewriting my thread handling this weekend... so please give some time to answer.
jakobssystems
User
User
Posts: 12
Joined: Thu Apr 10, 2025 5:17 pm

Re: Problems in Windows with HTTP-REST API Skeleton

Post by jakobssystems »

Update: Windows version is up and running after a partial rewrite of the Threadmodel.

Thank you @infrate, you pushed me into the right Direction.

And @idle I took a peek into the Atomic Webserver but this is directly using the Socket in Windows. It tries to be a fully blown Webserver and has a lot of dependencies. My aim is different. I want a minimalistic REST API Server, a single-exeecutable.
Post Reply