|
|
| Author |
Message |
|
| garyng |
Posted: Sat Aug 18, 2007 4:28 am |
|
|
|
Joined: 15 Aug 2007
Posts: 7
|
Hi,
Suppose I have 2 processes which shares the same socket(tcp_reader/tcp_writer) where the tcp_reader read the request from the socket then gen_server:cast() to tcp_writer to let it handle the sending.
So it is possible that tcp_writer may have a number of requests in the queue. Now if the reader process get a "shutdown" from the client, it would send a message to the writer and let it stop as well(to get in front of all the queued send request), after it has finished the one on hand.
If I implement the receive loop, I can use the timeout == 0 tricks but not sure how it should be done in gen_server. |
|
|
| Back to top |
|
| francesco |
Posted: Mon Aug 20, 2007 7:20 am |
|
|
|
User
Joined: 07 Jul 2006
Posts: 249
Location: London
|
Unfortunately, OTP behaviors (Including gen_servers and FSMs) lack selective receives (And thereof priorities). The only way to solve the selective receive problem in a clean way is to implement your own behavior. (See Ulf Wiger's presentation at the EUC two years ago, http://www.erlang.se/euc/05/1500Wiger.ppt ) or search on selective receive in the search field on the bottom left.
To solve your problem, however, I would look into using exit signals and links, as that is the way it is usually solved.
If you want dirty workarounds for selective receives in gen_servers, let me know. It will however have to be after lunch, as I will loose my appetite
Francesco
--
http://www.erlang-consulting.com |
|
|
| Back to top |
|
| Jan Henry Nystrom |
Posted: Mon Aug 20, 2007 8:13 am |
|
|
|
User
Joined: 09 Oct 2006
Posts: 28
Location: Uppsala, Sweden
|
garyng wrote: Hi,
[Snip]
If I implement the receive loop, I can use the timeout == 0 tricks but not sure how it should be done in gen_server.
Hi,
I hope you forgive the self promotion nature of this, but I have a generic server version that does the selective receive (fiendishly expensive which is was puts Francesco off his food). It will be presented at the Erlang Workshop in October with a discussion on general issues concerning selective receive. I will release the code on trap exit as soon as I have the time to write the proper documentation.
/Cheers Henry |
_________________ Jan Henry Nystrom
Training & Research Manager @ Erlang Training and Consulting Ltd
http://www.erlang-consulting.com |
|
| Back to top |
|
| garyng |
Posted: Mon Aug 20, 2007 10:07 am |
|
|
|
Joined: 15 Aug 2007
Posts: 7
|
francesco wrote:
To solve your problem, however, I would look into using exit signals and links, as that is the way it is usually solved.
Can I have a pointer on how to do it that way ? |
|
|
| Back to top |
|
| number |
Posted: Mon Jun 04, 2012 8:38 am |
|
|
|
User
Joined: 04 Jun 2012
Posts: 18
|
|
| Back to top |
|
|
|
All times are GMT
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|
|