Comments (5)
This changes the default behavior of ConnectionCreate, which creates the connection, but don't add it, nor start it. As its name states.
So your patch breaks the Liskov substitution principle of OOP.
For a new client connection, ConnectionCreate + Clients.Start() should be called explicitly.
I have modified the source so that
- TAsyncConnections.ThreadClientsConnect can be called to create a new client on need;
- fClients.Start will awake reading thread(s) using the new fClients.OnStart event
from mormot2.
Hello @synopse
Is there any new update related to this issue ?
Thanks.
from mormot2.
So After sometime reading the code I've some concern regards the TAsyncClient.
I think this class should serve the Connection as only a Async ThreadPoll for Read & Write.
So the Idea behind the the aClientsCount should change.
My idea is you should be able to add your own Socket Connection to the TPollAsyncSockets and still works fine.
Take my new code here as example
https://gist.github.com/Coldzer0/c91b6e144ac0c3227f884c3b355326ac
This should work fine But theโFix only works if I add aClientsCount
bigger than 0 And It should be available .
So What I propose is the next change and everything should work as expected.
diff --git a/src/net/mormot.net.async.pas b/src/net/mormot.net.async.pas
index d9a500b7..589196ee 100644
--- a/src/net/mormot.net.async.pas
+++ b/src/net/mormot.net.async.pas
@@ -587,7 +587,8 @@ type
// - will use a TAsyncConnection inherited class to maintain connection state
// of each connected client
TAsyncClient = class(TAsyncConnections)
- protected
+ Protected
+ Function ConnectionCreate(aSocket: TNetSocket; Const aRemoteIp: RawUtf8; out aConnection: TAsyncConnection): Boolean; Override;
procedure Execute; override;
public
/// start the TCP client connections, connecting to the supplied IP server
@@ -1714,12 +1715,7 @@ begin
raise EAsyncConnections.CreateUtf8('%: %:% connection failure (%)',
[self, fThreadClients.Address, fThreadClients.Port, ToText(res)^]);
connection := nil;
- if ConnectionCreate(client, {ip=}'', connection) then
- begin
- if fThreadReadPoll <> nil then
- fThreadReadPoll.fEvent.SetEvent // awake reading thread(s)
- end
- else
+ if not ConnectionCreate(client, {ip=}'', connection) then
client.ShutdownAndClose({rdwr=}false);
end;
@@ -2282,6 +2278,23 @@ begin
aLog, aOptions, aThreadPoolCount);
end;
+function TAsyncClient.ConnectionCreate(aSocket: TNetSocket;
+ const aRemoteIp: RawUtf8; out aConnection: TAsyncConnection): Boolean;
+begin
+ result := false;
+ if not Terminated then
+ begin
+ aConnection := fConnectionClass.Create(self, aRemoteIp);
+ if inherited ConnectionAdd(aSocket, aConnection) then
+ begin
+ result := Clients.Start(aconnection); // assign a new connection to the internal reading poll
+ if Result then
+ if fThreadReadPoll <> nil then
+ fThreadReadPoll.fEvent.SetEvent; // awake reading thread(s)
+ end;
+ end;
+end;
+
procedure TAsyncClient.Execute;
var
notif: TPollSocketResult;
Regards.
from mormot2.
Hello @synopse
Did you check my comment above ?
from mormot2.
Thanks @synopse for the update.
I'm not professional when it's about OOP so excuse my lake of knowledge in this area. (Thanks for the explanation)
The last commit fix the problem
By using Self.Clients.Start(connection);
After connecting.
Or just set the clients count to what we want.
Thanks.
from mormot2.
Related Issues (20)
- Windows API Multiple defined symbols HOT 1
- "AutoFlushTimeOut" property does not work. HOT 4
- While compiling mormot.db.sql.ibx gives compile error on Delphi 12! HOT 2
- Compile issue with test/mormot2tests.dproj on current master branch HOT 3
- TSqlDBOleDBMSSQL2018ConnectionProperties should set fProviderName before calling SetInternalProperties HOT 1
- static-lib unit bug
- Circular Reference Issue in Project04InterfaceBasedServer.dproj in martin-doyle's example 04-InterfacedBasedServices HOT 4
- Exported package threadvar CurrentThreadName HOT 1
- AesNiEncrypt256 and others do not preserve xmm6-xmm15 HOT 2
- Would it be of interest to automated tests run on GitHub Actions? HOT 2
- Cannot compile in Delphi with a Linux 64 target HOT 4
- sqlite3.o: undefined reference to `fcntl64' HOT 4
- Exception in mormot.crypt.core.asmx64.inc._AesNiHashXmm0 HOT 2
- THttpServer - Process ClientSock don't capture RemotePort HOT 1
- THttpServerRequestAbstract - RemoteIP equals 127.0.0.1 HOT 1
- How to use synpdf to add latex or mathml to a PDF? HOT 1
- Not all tests passed HOT 2
- error while compiling mormot.core.test from lazarus package if NOEXCEPTIONINTERCEPT is set HOT 2
- In Windows, setting TSimpleHttpClient.UserAgent does not take effect. HOT 3
- Internal Error: URW1147 HOT 21
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mormot2.