development a breeze. Given that SWI and Yap are working together to
> I'm tyring to develop a (very) basic web server, using yap-prolog
> but I
> experience a very slow throughput using the socket functions. The
> following program is just an excerpt of a bigger program, but
> it experiences the same problem.
> It sends a small file (test.txt) about 40kb in size, regardless of the
> input query.
>
> To try it just create a text file called test.txt, about 40/50 kb in
> size, load the program in yap, open a browser and query
http://127.0.0.1>
> I've tried it with different files, both text files than images (gif
> and
> png). In the console window you can see two messages, 'before' and
> 'after', issued just before and after the sending of the file.
> You will notice the delay.
> Then try with a bigger file (200/300 kb).
> The delay becomes intollerable.
>
>
> Any suggestion?
>
> Regards
> Maurizio.
>
> %----------------------------------------------------------------------%
> % global
> include %
> %----------------------------------------------------------------------%
>
> :- use_module(library(system)).
> :- use_module(library(lists)).
> :- use_module(library(charsio)).
> :- use_module(library(readutil)).
> :- set_prolog_flag(unknown,error).
>
> %----------------------------------------------------------------------%
> % i/o
> handling %
> %----------------------------------------------------------------------%
>
>
>
> send_message(Sout,Rcode,Contype,Message):-
> send_message_header(Sout,Rcode,Contype,"",Message).
>
> send_message_header(Sout,Rcode,Contype,Header,Message):-
> put_bytes("HTTP/1.0 ",Sout), put_bytes(Rcode,Sout),
> put_bytes("\r\n",Sout),
> put_bytes("Content-Type: ",Sout), put_bytes(Contype,Sout),
> put_bytes("\r\n",Sout),
> put_bytes(Header,Sout),
> code_len(Message,Size),
> put_bytes("Content-Length: ",Sout), put_bytes(Size,Sout),
> put_bytes("\r\n\r\n",Sout),
> put_bytes(Message,Sout).
>
> code_len(Message,Len):-
> length(Message,Size),
> number_codes(Size,Len).
>
> put_bytes([],_Sout).
> put_bytes([C|R],Sout):- put_byte(Sout,C), put_bytes(R,Sout).
>
>
> read_in_list(Name,List):-
> open(Name,read,S,[type(binary)]),
> read_stream_to_codes(S,List),
> close(S).
>
> send_file(Filename,Type,Sout):-
> read_in_list(Filename,L),
> write(before),nl,
> send_message(Sout,"200 OK",Type,L),
> write(after),nl.
>
>
>
> %----------------------------------------------------------------------%
> %
> main %
> %----------------------------------------------------------------------%
>
> :- initialization(go).
>
>
> go:-
> socket('AF_INET',Sock),
> socket_bind(Sock,'AF_INET'(_,80)),
> socket_listen(Sock,5),
> main_loop(Sock).
>
> main_loop(Sock) :-
> repeat,
> socket_accept(Sock,Sin),
> send_file('test.txt',"text/plain",Sin),
> flush_output(Sin),
> close(Sin),
> fail.
>
> ------------------------------------------------------------------------------
> Stay on top of everything new and different, both inside and
> around Java (TM) technology - register by April 22, and save
> $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
> 300 plus technical and hands-on sessions. Register today.
> Use priority code J9JMT32.
http://p.sf.net/sfu/p> _______________________________________________
> Yap-users mailing list
>
Yap-users@...
>
https://lists.sourceforge.net/lists/listinfo/yap-users>
Conference from O'Reilly Media. Velocity features a full day of
leaders in dedicated Performance & Operations tracks. Use code vel09scf
and Save an extra 15% before 5/3.