Evan Martin (evan) wrote in evan_tech,
Evan Martin

found my bug!

Not too interesting, but this has been bugging me for a week.

Been working on a toy program that proxies a TCP connection. It was working fine for some and then would mysteriously corrupt others; I spent a long time looking and it finally hit me, painfully obvious.

I had threads going in each way doing this in a loop:
 forward :: Socket -> Socket -> IO ByteString
 forward src dst = do
   buf <- recv src (16 * 2^10)
   send dst buf
   return buf
Network.Socket.ByteString.send of course returns an integer of how many bytes were actually sent; you need to loop if you want to be sure to send it all. (I had imagined this higher-level API was handling this looping for me, but it makes more sense that it wouldn't. It does however handle EINTR, so when I had glanced at the source in my desperation I did notice a loop, throwing me off the scent.) Sticking a loop around the send fixed everything.
Tags: haskell

  • münchen

    On that note: I'm living in Munich for the next week plus a few days. Do I know anyone around here? (PS: The LJ → PubSubHubbub → Reader…

  • deb/rpm diffing tools

    Dear Linux hackers, Chrome tends to push minor updates (often security) pretty frequently. We'd like to operate as a good member of the Linux…

  • emacs

    I've been using vim for a very long time -- over ten years -- but over those years I've envied more and more the way emacs integrates other software.…

  • Post a new comment


    default userpic
    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.