bug-prolog
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Socket handling seems to acquire and loose system resources.


From: Daniel Diaz
Subject: Re: Socket handling seems to acquire and loose system resources.
Date: Thu, 12 Mar 2009 11:25:04 +0100
User-agent: Thunderbird 2.0.0.19 (X11/20090105)

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
address@hidden
http://lists.gnu.org/mailman/listinfo/bug-prolog



--
Ce message a ete verifie par MailScanner
pour des virus ou des polluriels et rien de
suspect n'a ete trouve.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]