Automatically reconnect a Haskell Network connection in an idiomatic way -


i've worked way through don stewart's roll own irc bot tutorial, , playing around extensions it. current code same "the monadic, stateful, exception-handling bot in glory"; it's bit long paste here unless requests it.

being comcast subscriber, it's particularly important bot able reconnect after periods of poor connectivity. approach time ping requests server, , if goes without seeing ping time, try reconnecting.

so far, best solution i've found wrap hgetline in listen loop system.timeout.timeout. however, seems require defining custom exception catch in main can call main again, rather return (). seems quite fragile specify timeout value each individual hgetline.

is there better solution, perhaps wraps io a bracket , catch entire main can handle network timeouts without overhead of new exception type?

how running separate thread performs reading , writing , takes care of periodically reconnecting handle?

something this

 input  :: chan char  output :: chan char   putchar c = writechan output c   keepalive = forever $      h <- connecttoserver      catch          (forever $               c <- readchan output; timeout 4000 (hputchar h c); return ())          (\_ -> return ()) 

the idea encapsulate difficulty periodically reconnecting separate thread.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -