Client type handling and counting change.
This commit is contained in:
parent
08db592f3d
commit
6025728cf3
1 changed files with 36 additions and 13 deletions
49
lweb.pbi
49
lweb.pbi
|
@ -68,6 +68,14 @@ Module lhs_web
|
||||||
#SRV_DO_ClientDisconnect ;Beenden des Threads Client hat verbindung getrennt.
|
#SRV_DO_ClientDisconnect ;Beenden des Threads Client hat verbindung getrennt.
|
||||||
EndEnumeration
|
EndEnumeration
|
||||||
|
|
||||||
|
Enumeration e_type_client 1
|
||||||
|
#client_HTTP
|
||||||
|
#client_HTTPS
|
||||||
|
EndEnumeration
|
||||||
|
|
||||||
|
#client_add = 1
|
||||||
|
#client_remove = -1
|
||||||
|
|
||||||
#http_method_get = "GET"
|
#http_method_get = "GET"
|
||||||
#http_method_post = "POST"
|
#http_method_post = "POST"
|
||||||
#http_method_put = "PUT"
|
#http_method_put = "PUT"
|
||||||
|
@ -100,7 +108,7 @@ Module lhs_web
|
||||||
client_id.i
|
client_id.i
|
||||||
client_do_cli.i
|
client_do_cli.i
|
||||||
client_do_srv.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_mutex.i
|
||||||
client_thread.i
|
client_thread.i
|
||||||
List datenbuffer.s_client_memory()
|
List datenbuffer.s_client_memory()
|
||||||
|
@ -127,6 +135,8 @@ Module lhs_web
|
||||||
Global.i server_HTTP_id
|
Global.i server_HTTP_id
|
||||||
Global.i server_HTTPS_id
|
Global.i server_HTTPS_id
|
||||||
Global.i server_mutex = CreateMutex() ;Dieser Mutex dient zu der Sicherheit der Element Liste.
|
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_mutex = CreateMutex()
|
||||||
Global.i file_cache_semaphore = CreateSemaphore()
|
Global.i file_cache_semaphore = CreateSemaphore()
|
||||||
Global.i file_cache_semaphore_thread = 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_Header_to_JSONMap(String.s)
|
||||||
Declare.s Work_Post_ToJSON_x_www_form_urlencoded(ContentLength.i, MemorSize.i, Memory.i)
|
Declare.s Work_Post_ToJSON_x_www_form_urlencoded(ContentLength.i, MemorSize.i, Memory.i)
|
||||||
Declare.s GetFileFromCache(FileName.s, MemoryID.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")
|
Procedure set_config(parameter.i=#conf_defaultfile, setting.s="index.html")
|
||||||
Select parameter
|
Select parameter
|
||||||
|
@ -293,10 +304,10 @@ Module lhs_web
|
||||||
m_clients(Str(client_id))\client_id = client_id
|
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_cli = #CLI_DO_WaitDataReceive
|
||||||
m_clients(Str(client_id))\client_do_srv = #SRV_DO_DataReceive
|
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
|
;Thread erstellen
|
||||||
m_clients(Str(client_id))\client_thread = CreateThread(@client(), client_id)
|
m_clients(Str(client_id))\client_thread = CreateThread(@client(), client_id)
|
||||||
count_HTTPS_client + 1
|
count_client(#client_HTTPS, #client_add)
|
||||||
Else
|
Else
|
||||||
Debug "Max HTTPS Clients reached..."
|
Debug "Max HTTPS Clients reached..."
|
||||||
ltls::CloseTLSSocket(client_id)
|
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_id = client_id
|
||||||
m_clients(Str(client_id))\client_do_cli = #CLI_DO_WaitDataReceive
|
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_do_srv = #SRV_DO_DataReceive
|
||||||
m_clients(Str(client_id))\client_ssl = 0
|
m_clients(Str(client_id))\client_type = #client_HTTP
|
||||||
;Thread erstellen
|
;Thread erstellen
|
||||||
m_clients(Str(client_id))\client_thread = CreateThread(@client(), client_id)
|
m_clients(Str(client_id))\client_thread = CreateThread(@client(), client_id)
|
||||||
count_HTTP_client + 1
|
count_client(#client_HTTP, #client_add)
|
||||||
Else
|
Else
|
||||||
Debug "Max HTTP Clients reached..."
|
Debug "Max HTTP Clients reached..."
|
||||||
lsocket::CloseSocket(client_id)
|
lsocket::CloseSocket(client_id)
|
||||||
|
@ -389,6 +400,7 @@ Module lhs_web
|
||||||
Define NewMap Response.s()
|
Define NewMap Response.s()
|
||||||
Define NewMap Post.s()
|
Define NewMap Post.s()
|
||||||
|
|
||||||
|
|
||||||
Debug "Client Thread Started. ID:" + Str(network_client_id)
|
Debug "Client Thread Started. ID:" + Str(network_client_id)
|
||||||
Repeat
|
Repeat
|
||||||
;Prüfen ob der Thread was zu tun hat.
|
;Prüfen ob der Thread was zu tun hat.
|
||||||
|
@ -407,8 +419,7 @@ Module lhs_web
|
||||||
Debug "Buffer Initialisierung fehlgeschlagen."
|
Debug "Buffer Initialisierung fehlgeschlagen."
|
||||||
Break
|
Break
|
||||||
EndIf
|
EndIf
|
||||||
;TODO: SSL Read
|
If m_clients(Str(thread_cli_id))\client_type = #client_HTTPS
|
||||||
If m_clients(Str(thread_cli_id))\client_ssl = 1
|
|
||||||
temp_receivelength = ltls::ReadTLSSocket(thread_cli_id, m_clients(Str(thread_cli_id))\datenbuffer()\Buffer, 65536)
|
temp_receivelength = ltls::ReadTLSSocket(thread_cli_id, m_clients(Str(thread_cli_id))\datenbuffer()\Buffer, 65536)
|
||||||
Else
|
Else
|
||||||
temp_receivelength = lsocket::ReadSocket(thread_cli_id, m_clients(Str(thread_cli_id))\datenbuffer()\Buffer, 65536)
|
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."
|
Debug "Buffer Initialisierung fehlgeschlagen."
|
||||||
Break 2
|
Break 2
|
||||||
EndIf
|
EndIf
|
||||||
;TODO: SSL Read 2
|
If m_clients(Str(thread_cli_id))\client_type = #client_HTTPS
|
||||||
If m_clients(Str(thread_cli_id))\client_ssl = 1
|
|
||||||
temp_receivelength = ltls::ReadTLSSocket(thread_cli_id, m_clients(Str(thread_cli_id))\datenbuffer()\Buffer, 65536)
|
temp_receivelength = ltls::ReadTLSSocket(thread_cli_id, m_clients(Str(thread_cli_id))\datenbuffer()\Buffer, 65536)
|
||||||
Else
|
Else
|
||||||
temp_receivelength = lsocket::ReadSocket(thread_cli_id, m_clients(Str(thread_cli_id))\datenbuffer()\Buffer, 65536)
|
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.
|
;Send the data in memory to client.
|
||||||
sent_total = thread_data_size+(thread_buffer_offset-thread_buffer)
|
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_length = sent_total
|
||||||
sent_buffer_address = thread_buffer
|
sent_buffer_address = thread_buffer
|
||||||
sent_total = 0
|
sent_total = 0
|
||||||
|
@ -885,12 +895,12 @@ Module lhs_web
|
||||||
DeleteElement(m_clients(Str(thread_cli_id))\datenbuffer())
|
DeleteElement(m_clients(Str(thread_cli_id))\datenbuffer())
|
||||||
EndIf
|
EndIf
|
||||||
Wend
|
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)
|
ltls::CloseTLSSocket(thread_cli_id)
|
||||||
count_HTTPS_client - 1
|
count_client(#client_HTTPS, #client_remove)
|
||||||
Else
|
Else
|
||||||
lsocket::CloseSocket(thread_cli_id)
|
lsocket::CloseSocket(thread_cli_id)
|
||||||
count_HTTP_client - 1
|
count_client(#client_HTTP, #client_remove)
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
DeleteMapElement(m_clients(), Str(thread_cli_id))
|
DeleteMapElement(m_clients(), Str(thread_cli_id))
|
||||||
|
@ -1279,6 +1289,19 @@ Module lhs_web
|
||||||
|
|
||||||
EndProcedure
|
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
|
EndModule
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue