{Fraud?} {Disarmed} Re: Socket handling seems to acquire and loose system resources.
Daniel Diaz <[email protected]> Thu, 12 Mar 2009 17:07:56 +0100
| Newsgroups | gmane.comp.gnu.prolog.bugs |
|---|---|
| Message-ID | <[email protected]> |
Maurizio, It seems there is no problem on my machine (maybe the problems appears on windows). I have slightly modified your code to display some information. Could you test it on your machine ? Normally all displayed lines should be the same. In particular the number of atoms should no increase. NB: I have changed the port (here it is 7000) so change it to 80 or use localhost:7000. Sorry I cannot do much more. Daniel Ferreira Maurizio a écrit : Messaggio You should start the program, than open a browser (internet explorer, firefox or whatever) than connect to MailScanner warning: numerical links are often malicious: http://127.0.0.1 . my test program simply ignore what the browser tells it, but it responds with "ok". sometimes the connection fails (I suppose because my program don't read the query from the browser and closes the connection) but this is not an issue in the real program. Keep refreshing the page until you see the answer. Best regards. Maurizio. -----Messaggio originale----- Da: Daniel Diaz [ mailto:[email protected] ] Inviato: giovedì 12 marzo 2009 15.50 A: Ferreira Maurizio Oggetto: Re: R: Socket handling seems to acquire and loose system resources. Maurizio, I cannot simply execute your program since it sends data via a socket and the receiver part is missing. If you provide me this part I could try to reproduce the problem. Daniel Ferreira Maurizio a écrit : If you simply save the program to a file, consult it and execute, it should exibit the reported behaviour. I've verified it both using the developement environment than a compiled version. I'm using a binary stream because the full program should read and output also binary data (mostly images). Thanks for your suggestion. Regards Maurizio. -----Messaggio originale----- Da: Daniel Diaz [ mailto:[email protected] ] Inviato: giovedì 12 marzo 2009 11.25 A: Ferreira Maurizio Cc: [email protected] Oggetto: Re: Socket handling seems to acquire and loose system resources. Hello Maurizio It seems you notice a memory leak. However I don't see anything which could at the source of this leak. Could you provide me a way to reproduce the problem ? BTW: why do you use a binary stream ? With a text stream, you could simplify a lot your code. Also, in order to benefit from prolog clause indexing (on the 1st argument) you shoud reverse the arguments of put_bytes/2 : put_bytes([], _Sout). put_bytes([C|R],Sout):- put_byte(Sout,C), put_bytes(R,Sout). (but this has nothing to do with the leak). Daniel Ferreira Maurizio a écrit : The following program (a little excerpt from a bigger program) seems to loose system resources at every invocation from a browser. Looking at the program with Windows task manager, I see that the program memory continues to grow, and that the program acquires a system handle every time it receives a request from the browser. However the statistic function does not shows any memory growth. I'm using GNU Prolog 1.3.1 under Windows 2000, on a Pentium 4, dual core, 2.80 GHz, 1Gb ram. Is this a program error or a bug ? Regards Maurizio. :- initialization(go). go:- socket('AF_INET',Sock), socket_bind(Sock,'AF_INET'(_,80)), socket_listen(Sock,10), main_loop(Sock). main_loop(Sock) :- repeat, socket_accept(Sock,Sin,Sout), set_stream_type(Sout,binary), try_comunications(Sin,Sout), close(Sin), close(Sout), fail. try_comunications(_Sin,Sout):- %%%%%% ...... Skipped reading and analizing request ...... send_text(Sout,"OK"). %% ------------------------------------------------------ %% send_text(Sout,Message):- send_message(Sout,"200 OK","Text/Html",Message). send_message(Sout,Rcode,Contype,Message):- send_message_header(Sout,Rcode,Contype,Message,""). send_message_header(Sout,Rcode,Contype,Message,Header):- put_bytes(Sout,"HTTP/1.0 "), put_bytes(Sout,Rcode), put_bytes(Sout,"\r\n"), put_bytes(Sout,"Content-Type: "), put_bytes(Sout,Contype), put_bytes(Sout,"\r\n"), put_bytes(Sout,Header), code_len(Message,Size), put_bytes(Sout,"Content-Length: "), put_bytes(Sout,Size), put_bytes(Sout,"\r\n\r\n"), put_bytes(Sout,Message). code_len(Message,Len):- length(Message,Size),number_codes(Size,Len). put_bytes(_Sout,[]). put_bytes(Sout,[C|R]):- put_byte(Sout,C), put_bytes(Sout,R). _______________________________________________ Bug-prolog mailing list [email protected] http://lists.gnu.org/mailman/listinfo/bug-prolog -- Ce message a été vérifié par MailScanner pour des virus ou des polluriels et rien de suspect n'a été trouvé. _______________________________________________ Bug-prolog mailing list [email protected] http://lists.gnu.org/mailman/listinfo/bug-prolog
x.pl
(application/x-perl, 1.5 KB)
:- initialization(go).
count_atom(_) :-
g_assign(c, 0),
current_atom(_),
g_inc(c),
fail.
count_atom(X) :-
g_read(c, X).
go:-
socket('AF_INET',Sock),
socket_bind(Sock,'AF_INET'(localhost,7000)),
socket_listen(Sock,10),
main_loop(Sock).
main_loop(Sock) :-
repeat,
socket_accept(Sock,Sin,Sout),
stream_property(Sin, file_name(Fin)),
stream_property(Sout, file_name(Fout)),
count_atom(At),
format('sock=~d ~w=~a ~w=~a atoms=~d~n', [Sock, Sin, Fin, Sout, Fout, At]),
set_stream_type(Sout,binary),
try_comunications(Sin,Sout),
close(Sin),
close(Sout),
fail.
try_comunications(_Sin,Sout):-
%%%%%% ...... Skipped reading and analizing request ......
send_text(Sout,"OK").
%% ------------------------------------------------------ %%
send_text(Sout,Message):-
send_message(Sout,"200 OK","Text/Html",Message).
send_message(Sout,Rcode,Contype,Message):-
send_message_header(Sout,Rcode,Contype,Message,"").
send_message_header(Sout,Rcode,Contype,Message,Header):-
put_bytes(Sout,"HTTP/1.0 "), put_bytes(Sout,Rcode),
put_bytes(Sout,"\r\n"),
put_bytes(Sout,"Content-Type: "), put_bytes(Sout,Contype),
put_bytes(Sout,"\r\n"),
put_bytes(Sout,Header),
code_len(Message,Size),
put_bytes(Sout,"Content-Length: "), put_bytes(Sout,Size),
put_bytes(Sout,"\r\n\r\n"),
put_bytes(Sout,Message).
code_len(Message,Len):-
length(Message,Size),number_codes(Size,Len).
put_bytes(_Sout,[]).
put_bytes(Sout,[C|R]):- put_byte(Sout,C), put_bytes(Sout,R).