(I forgot to cc the mailing list)

---------- Forwarded message ----------
From: Greg Burri <greg.burri@gmail.com >
Date: Nov 17, 2007 1:13 AM
Subject: Re: [Erlyaws-list] Socket question
To: Claes Wikstrom <klacke@tail-f.com>


Thanks for you answer.
If I receive a event from mnesia after waiting for either a closed message or an mnesia event I have to send a HTTP respond. Actually I just return {content, "text/xml", SomeXML} from out/1.

If I use inet:setopts() to take the control of the socket then I have to build my own HTTP header and so one... not so funny ;).

Is it possible to add a "closed" message from yaws to my process like just {closed, Reason} ? It seems to be useful in some cases. Or is there any other way to solve this problem ?


Greg


On Nov 17, 2007 12:12 AM, Claes Wikstrom <klacke@tail-f.com > wrote:

> I was saying that I knew about the #arg.clisock but I didn't know how
> can I receive the message {tcp_closed, S}.
> here is the doc about inet and {tcp_socket, S}


All yaws socket are in passive mode, this means that once your
out(Arg) function returns, the yaws server will invoke gen_tcp:recv()
on the socket.

In your case, where you ajaxyy, want more control over the
socket and in particular when it gets closed, you need to tell
the socket to go into active mode by invoking inet:setopts()
on the socket.

However, be aware, if you receive regular HTTP traffic on the socket
you will either have to process the data yourself or .... well
no remedy.

However if all you expect is the closed message you should be fine.
Once you have receive the closed you can call exit(normal) and all will
be fine. An alternative is to return 'ok' , but then yaws will subsequently
invoke gen_tcp:recv() which will fail and this might result in an a
log entry which you don't want, thus call exit(normal) once you
have picked upp the closed message.




/klacke