Hi all,
I'm searching for a faster TXMLConfig.
The current implementation is very slow, when a node contains more than 10 elements.
Mattias Gaertner

Mailing lists / fpc-pascal / 2002-03
16 messages · 7 people · –
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
Hi all,
I'm searching for a faster TXMLConfig.
The current implementation is very slow, when a node contains more than 10 elements.
Mattias Gaertner
Hi all,
I already asked the for a faster TXMLConfig.
But before I implement a new one, I ask twice.
TXMLConfig in xmlcfg.pp is a very easy component to handle config files. Since these files are in xml, which is nowadays a format for everything, I wonder, if there are some other implementations, which do not linear searches.
Can anyone give me a hint/link for other xml implementation?
Maybe the DOM implementation can be enhanced with some dynamic hash tables?
Mattias Gaertner
Note that XML is mainly a format for files that usually don't need human editing.
Can anyone give me a hint/link for other xml implementation?
Maybe Jedi has something. There is some DOM work going on there.
I already asked the for a faster TXMLConfig. But before I implement a new one, I ask…
I think that this is the better approach; Improving the DOM implementation and thus the existing TXMLConfig is of more benefit to anyone. Do you know where the exact problem is ?
hash tables or so should not be hard to implement; But I would like this to be based on a more general hash class, if possible... We need that anyhow in the FCL.
Michael.
Note that XML is mainly a format for files that usually don't need human editing. Maybe…
ok, after a lot of homework and some help from this list, i have got my telnet server working correctly - it can accept multiple client connections and pass communication to and from the clients. (i have only tested it locally, but that is all i need.) in order to make my proxy complete, the SAME program has to connect to another telnet server and pass the information to the other clients. so my program needs to be a server AND a client.
i tried to write a stand-alone client just to get the feel of how to write functional client code, and i have come to an impasse. i have a telnet server running on my pc on port 23, and i would like to connect to that server using my client. so far it compiles fine, and runs fine, but gethostbyname ('localhost') returns nil. here's my code (the error handling is infantile, i know):
__________________________________
program client;
uses
winsock, crt, strings;
var
wsadata : twsadata;
sockfd : tsocket;
server : phostent;
serveraddr : tsockaddr;
n: integer;
name : pchar;
buffer : array[0..256] of char;
function buildaddr(family: smallint; port: u_short; addr: u_long):
tsockaddr;
var
a: tsockaddr;
begin
a.sin_family:=family;
a.sin_port:=htons(port);
a.sin_addr.s_addr:=addr;
buildaddr:=a;
end;
begin
getmem(name,sizeof('localhost')+1);
strcopy(name,'localhost');
writeln('retrieving socket....');
sockfd := socket(AF_INET, SOCK_STREAM, 0);
if (sockfd = INVALID_SOCKET) then halt;
writeln('getting host name....',name);
server := gethostbyname(name);
if server=nil then halt; // PROGRAM HALTS HERE
writeln('building address....');
serveraddr:=buildaddr(AF_INET, 23, u_long(server^.h_addr));
writeln('connecting socket....');
if (connect(sockfd,serveraddr,sizeof(serveraddr))<0) then halt;
n:=recv(sockfd,buffer,255,0);
writeln(buffer);
closesocket(sockfd);
freemem(name);
wsacleanup;
end.
__________________________________why doesn't it find the host for 'localhost' - isn't that a correct host name? also, any other style and/or coding advice not related to gethostbyname would be appreciated.
thanks for the help,
ron wilson.
I think that this is the better approach; Improving the DOM implementation and thus the…
The childs of a DOM node are stored in a chained list. Accessing A/B/C will result in searching the childs of A for B and the childs of B for C. This could be improved, when the first sibling or the parent contains an hash index or a sorted array. Of course this would slow down inserting a node behind another node. But since the user adds nodes via A/B/C := Value this inserting operation does not appear. So, we can only gain.
hash tables or so should not be hard to implement; But I would like this to be based on a more general hash class, if possible... We need that anyhow in the FCL.
Hmm, have to think about that ...
Mattias Gaertner
BTree?
Probably.
Mattias
ok, after a lot of homework and some help from this list, i have got my telnet server…
you have trying to do this under Windows ?
if your dns is missconfigured there is no correspondance with localhost and 127.0.0.1 !
Lionel Drevon
Adeli http://www.adeli.fr
618 Av. Gal de Gaulle Tel 04 78 66 11 85
69760 Limonest Fax 04 78 66 04 33
On Mon, 11 Mar 2002 09:34:40 +0100 (CET) Probably. Mattias
I have the impossibility to post a bug report. Why ? I don't know.
Here it is:
------------ REPORT
I have some inconsistency with sockets under windows. Here the setup: Win (98/nt), Apache, Mod_lisp, a freepascal program. See a minimalist one attached. This one receive the get request, display parameters received and return a static page.
Mod_lisp is a kind of fast-cgi protocol on socket but way easyer than the true fastcgi.
Well, from time to time the first request done to apache is correctly received by the program, but the second transmission is always wrong. I receive garbage caracters...
Note: When I replace the freepascal program with a VB or Lisp one, I have no problem.
I think this problem is linked with the problem 1694, but I am not sure. ------------ SOURCE
Uses Sockets;
Var
lSock : LongInt;
uSock : LongInt;
sAddr : TInetSockAddr;
lLen : LongInt;
sLine : String;
SIn : Text;
SOut : Text;
AAA : Boolean;
Procedure PError (Const S : String);
Begin
Writeln (S, SocketError);
Halt (100);
End;
Begin
lSock:=Socket (AF_Inet, Sock_Stream, PF_Unspec);
If SocketError0 Then PError ('Server : Socket : ');
sAddr.Family:=AF_Inet;
sAddr.Port :=lo (3000) shl 8 or hi (3000);
sAddr.Addr :=(1 shl 24) or 127;
If Not Bind (lSock, sAddr, SizeOf (sAddr)) Then PError ('Server : Bind
: ');
If Not Listen (lSock, 1) Then PError ('Server : Listen : ');
Repeat
Writeln ('Accepting connection...');
lLen :=SizeOf (sAddr);
uSock:=Accept (lSock, sAddr, lLen);
If SocketError0 Then PError ('Server : Accept : ');
Writeln ('Connection accepted...');
Sock2Text (USock, SIn, SOut);
Reset (SIn);
Rewrite (SOut);
AAA:=False;
While Not Eof (SIn) Do
Begin
ReadLn (SIn, sLine);
WriteLn (sLine);
If AAA=True Then
Begin
AAA:=False;
Writeln ('url = ', sLine);
End;
If sLine='url' Then AAA:=True;
If sLine='end' Then Break;
End;
sLine:='<!DOCTYPE HTML PUBLIC "-//IETF//DTD
HTML//EN"><HTML><HEAD></HEAD><BODY><H1>mod_lisp 2.0b2</H1><P>This is a
constant html string sent by Apache + mod_lisp 2.0b2 + FreePascal +
Windows</P></BODY></HTML>';
Writeln (SOut, 'Status');
Writeln (SOut, '200 OK');
Writeln (SOut, 'Content-Type');
Writeln (SOut, 'text/html');
Writeln (SOut, 'Content-Length');
Writeln (SOut, Length (sLine)+2);
Writeln (SOut, 'Keep-Socket');
Writeln (SOut, '0');
writeln (SOut, 'end');
Writeln (SOut, sLine);
Close (Sin);
Close (SOut);
ShutDown (uSock, 2);
Until False;
End.you have trying to do this under Windows ? if your dns is missconfigured there is no…
in a dos window, i can type "ping localhost" and it pings 127.0.0.1 correctly. i am also able to connect to my local telnet server via telnet to 'localhost'. i'm pretty sure it is configured correctly.
regards,
ron wilson.
i'will try your soft when i'have reinstalled the fpc on my win98! newly formated! no crash but new computer...
Lionel Drevon
Adeli http://www.adeli.fr
618 Av. Gal de Gaulle Tel 04 78 66 11 85
69760 Limonest Fax 04 78 66 04 33
I think that this is the better approach; Improving the DOM implementation and thus the…
Hola,
hash tables or so should not be hard to implement; But I would like this to be based on a more general hash class, if possible... We need that anyhow in the FCL.
Barry Kelly has done a small and fast implementation that just needs SysUtils.
License is liberal enough.
http://radweb.borland.com/codecentral/ccweb.exe/listing?id=15171
If you aren't registered, I can send the code (10kb, readme included).
i'will try your soft when i'have reinstalled the fpc on my win98! newly formated! no…
i figured the problem out... it was a silly error on my part - i forgot to initialize the winsock system.
if not(wsastartup($2,wsadata)=0) then sock_error(proxy,'wsastartup()')
after that, i had to figure out what the C bcopy() command did and reverse engineer it. i don't think freepascal has one of those. or maybe it does... can anybody tranlsate this line into freepascal for me? all the type-casting got me lost in fp.
bcopy((char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr,
server->h_length);note: server->h_addr is ^pchar and serv_addr.sin_addr.s_addr is u_long.
the code works great now - i have it pretty much compartmentalized, but i am not bothering to write classes since i don't have any experience doing that in freepascal. i have the client and server portions both working in my proxy program. i can make multiple connections to any telnet server through my proxy.
now all i have to do is the user interface and database engine. i need to parse all the data as it comes in and mine it for relevant data. i'm thinking a simple state-machine would cut down on the overhead a lot. also, i want to avoid using the pos() command for speed. since i'm designing a proxy for a telnet game, speed and reaction time is very important. too many clock cycles on parsing would hurt me. anybody have any suggestions?
regards,
ron wilson.
bcopy is afaik simply move, just with pointers as arguments, since C has no open arrays as params.
note: server->h_addr is ^pchar and serv_addr.sin_addr.s_addr is u_long.
Afaik it is simply:
move (server.h_addr,serv_addr.sin_addr.s_addr,server.length);thanks - i just tried that and it works great. you just have to change one thing, but i'm not sure why the change works. i think it has to do with the h_addr definition as ^pchar, but i'm not sure. i did this:
move(server.h_addr^, serv_addr.sin_addr.s_addr, server.length);also, this gives s_addr in network byte order, so you have to add this line if you need host byte order:
serv_addr.sin_addr.s_addr := htonl(serv_addr.sin_addr.s_addr);here's my function, with old method commented out:
function pchar_to_ulong(s: pchar): u_long;
var
//i: u_short;
rslt: u_long;
begin
//rslt:=0;
//for i:=0 to min(sizeof(s),4)-1 do
// rslt+=u_long(s[i]) shl ((3-i)*8);
move(s^,rslt,min(sizeof(s),4));
rslt:=htonl(rslt);
pchar_to_ulong:=rslt;
end;ron wilson.