Client type handling and counting change.

This commit is contained in:
René Linder 2020-12-01 08:53:53 +01:00
parent 08db592f3d
commit 6025728cf3

View file

@ -68,6 +68,14 @@ Module lhs_web
#SRV_DO_ClientDisconnect ;Beenden des Threads Client hat verbindung getrennt.
EndEnumeration
Enumeration e_type_client 1
#client_HTTP
#client_HTTPS
EndEnumeration
#client_add = 1
#client_remove = -1
#http_method_get = "GET"
#http_method_post = "POST"
#http_method_put = "PUT"
@ -100,7 +108,7 @@ Module lhs_web
client_id.i
client_do_cli.i
client_do_srv.i
client_ssl.i ;Client ist von einem SSL Server
client_type.i ;What type of Client.
client_mutex.i
client_thread.i
List datenbuffer.s_client_memory()
@ -127,6 +135,8 @@ Module lhs_web
Global.i server_HTTP_id
Global.i server_HTTPS_id
Global.i server_mutex = CreateMutex() ;Dieser Mutex dient zu der Sicherheit der Element Liste.
Global.i count_HTTP_mutex = CreateMutex()
Global.i count_HTTPS_mutex = CreateMutex()
Global.i file_cache_mutex = CreateMutex()
Global.i file_cache_semaphore = CreateSemaphore()
Global.i file_cache_semaphore_thread = CreateSemaphore()
@ -163,6 +173,7 @@ Module lhs_web
Declare.s Work_Header_to_JSONMap(String.s)
Declare.s Work_Post_ToJSON_x_www_form_urlencoded(ContentLength.i, MemorSize.i, Memory.i)
Declare.s GetFileFromCache(FileName.s, MemoryID.i)
Declare count_client(Type.i, Countchange.i)
Procedure set_config(parameter.i=#conf_defaultfile, setting.s="index.html")
Select parameter
@ -293,10 +304,10 @@ Module lhs_web
m_clients(Str(client_id))\client_id = client_id
m_clients(Str(client_id))\client_do_cli = #CLI_DO_WaitDataReceive
m_clients(Str(client_id))\client_do_srv = #SRV_DO_DataReceive
m_clients(Str(client_id))\client_ssl = 1
m_clients(Str(client_id))\client_type = #client_HTTPS
;Thread erstellen
m_clients(Str(client_id))\client_thread = CreateThread(@client(), client_id)
count_HTTPS_client + 1
count_client(#client_HTTPS, #client_add)
Else
Debug "Max HTTPS Clients reached..."
ltls::CloseTLSSocket(client_id)
@ -326,10 +337,10 @@ Module lhs_web
m_clients(Str(client_id))\client_id = client_id
m_clients(Str(client_id))\client_do_cli = #CLI_DO_WaitDataReceive
m_clients(Str(client_id))\client_do_srv = #SRV_DO_DataReceive
m_clients(Str(client_id))\client_ssl = 0
m_clients(Str(client_id))\client_type = #client_HTTP
;Thread erstellen
m_clients(Str(client_id))\client_thread = CreateThread(@client(), client_id)
count_HTTP_client + 1
count_client(#client_HTTP, #client_add)
Else
Debug "Max HTTP Clients reached..."
lsocket::CloseSocket(client_id)
@ -389,6 +400,7 @@ Module lhs_web
Define NewMap Response.s()
Define NewMap Post.s()
Debug "Client Thread Started. ID:" + Str(network_client_id)
Repeat
;Prüfen ob der Thread was zu tun hat.
@ -407,8 +419,7 @@ Module lhs_web
Debug "Buffer Initialisierung fehlgeschlagen."
Break
EndIf
;TODO: SSL Read
If m_clients(Str(thread_cli_id))\client_ssl = 1
If m_clients(Str(thread_cli_id))\client_type = #client_HTTPS
temp_receivelength = ltls::ReadTLSSocket(thread_cli_id, m_clients(Str(thread_cli_id))\datenbuffer()\Buffer, 65536)
Else
temp_receivelength = lsocket::ReadSocket(thread_cli_id, m_clients(Str(thread_cli_id))\datenbuffer()\Buffer, 65536)
@ -429,8 +440,7 @@ Module lhs_web
Debug "Buffer Initialisierung fehlgeschlagen."
Break 2
EndIf
;TODO: SSL Read 2
If m_clients(Str(thread_cli_id))\client_ssl = 1
If m_clients(Str(thread_cli_id))\client_type = #client_HTTPS
temp_receivelength = ltls::ReadTLSSocket(thread_cli_id, m_clients(Str(thread_cli_id))\datenbuffer()\Buffer, 65536)
Else
temp_receivelength = lsocket::ReadSocket(thread_cli_id, m_clients(Str(thread_cli_id))\datenbuffer()\Buffer, 65536)
@ -812,7 +822,7 @@ Module lhs_web
;Send the data in memory to client.
sent_total = thread_data_size+(thread_buffer_offset-thread_buffer)
If m_clients(Str(thread_cli_id))\client_ssl = 1
If m_clients(Str(thread_cli_id))\client_type = #client_HTTPS
sent_length = sent_total
sent_buffer_address = thread_buffer
sent_total = 0
@ -885,12 +895,12 @@ Module lhs_web
DeleteElement(m_clients(Str(thread_cli_id))\datenbuffer())
EndIf
Wend
If m_clients(Str(thread_cli_id))\client_ssl = 1
If m_clients(Str(thread_cli_id))\client_type = #client_HTTPS
ltls::CloseTLSSocket(thread_cli_id)
count_HTTPS_client - 1
count_client(#client_HTTPS, #client_remove)
Else
lsocket::CloseSocket(thread_cli_id)
count_HTTP_client - 1
count_client(#client_HTTP, #client_remove)
EndIf
DeleteMapElement(m_clients(), Str(thread_cli_id))
@ -1279,6 +1289,19 @@ Module lhs_web
EndProcedure
Procedure count_client(Type.i, Countchange.i)
Select Type
Case #client_HTTP
LockMutex(count_HTTP_mutex)
count_HTTP_client + Countchange
UnlockMutex(count_HTTP_mutex)
Case #client_HTTPS
LockMutex(count_HTTPS_mutex)
count_HTTPS_client + Countchange
UnlockMutex(count_HTTPS_mutex)
EndSelect
EndProcedure
EndModule