try... after and clean-up

Joel Reymont joelr1@REDACTED
Thu Jan 5 14:29:47 CET 2006


Folks,

In the code below I can get exceptions from util:connect_script,  
util:connect or the very last run(..., handle( ... )) line. I'm  
opening 3 sockets in this code. Two of those sockets are in passive  
mode and have reader processes since the data I receive has the  
length of the packet in little-endian format and Erlang expects big- 
endian.

I would like to clean up open sockets and socket reader processes  
when my exception is thrown. I thought that I could just enclose the  
block starting with Bot1 in a try... after but...

Do I refer to Bot3 in the 'after' code? What if it did not get to  
Bot3 and an exception was thrown after Bot1?

Any suggestions?

	Thanks, Joel

---
run(Args)
   when is_record(Args, bot_args) ->
     Bot = #bot {
       poker_server = Args#bot_args.host,
       dispatchers = [{"script",
		      Args#bot_args.script,
		      Args#bot_args.script_args
		     }],
       log = Args#bot_args.log,
       ignored = Args#bot_args.ignored,
       lobby_bot = Args#bot_args.lobby_bot
      },
     Bot1 = notrace(Bot, [cl_ssl_handshake_data,
			 srv_ssl_handshake_data,
			 srv_update_hint_text,
			 cl_handshake,
			 srv_handshake,
			 srv_news]),
     UtilSock = util:connect_script_server(),
     Bot2 = Bot1#bot {
	     util_sock = UtilSock
	    },
     Bot3 = util:connect(Bot2,
			[lobby_con_wrap(),
			 lobby_handle_wrap(),
			 connected]), % event to post
     run(Bot3, handle(Bot3, handshake)).


--
http://wagerlabs.com/








More information about the erlang-questions mailing list