bug-prolog
[Top][All Lists]
Advanced

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

Socket handling seems to acquire and loose system resources.


From: Ferreira Maurizio
Subject: Socket handling seems to acquire and loose system resources.
Date: Thu, 12 Mar 2009 09:48:17 +0100

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).





reply via email to

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