Debugging fun



  • I don't think this needs much explanation... enjoy:

      def start
        @run = true
        1.upto(@num_threads) do |i|
          @tg.add(
            Thread.new do
              Thread.current[:name] = "WorkerThread-"+i.to_s
              while @run
                msg = @q.pop
                #@ilog.debug("Message #{msg} picked up from queue") if @ilog.debug?
                @ilog.info("Message picked from queue, now parsing") if @ilog.info?
                r = Message.parse(msg)
                2.times do  # one optional retry
                  case r
                  when Request
                    @ilog.debug("REQUEST RECEIVED #{r}") if @ilog.debug?
                    logsip("I", r.rcvd_from_info[3], r.rcvd_from_info[1], r.rcvd_at_info[0], r.rcvd_at_info[1], r.rcvd_at_info[2], r)
                    if r.to_tag && !r.attributes[:_sipper_initial]
                      # call_id, local, remote
                      s = SessionManager.find_session(r.call_id, r.to_tag, r.from_tag) 
                      if s
                        s.on_message r
                        break
                      else
                        if hndlr = SIP::StrayMessageManager.stray_message_handler
                          @ilog.debug("Found a stray message handler for the request, invoking it") if @ilog.debug?
                          ret = hndlr.handle(r)
                          case ret[0]
                          when SIP::StrayMessageHandler::SMH_DROP
                            @ilog.warn("A stray request #{r.method} being dropped by SMH") if @ilog.warn?
    ...

    One function. Goes up to 14 levels of indentation in one place. 199 lines, 3 (!) of them empty. Contains: new threads, if, while, unless, .upto (block), .each (block), case, single and double letter variables. At level 8 of indentation you can spot some uses of 'break' and 'next'.

    Operates on shared resources, factory/locator, timer callbacks, parser, text constants, magic values (ret = ....; ret[0], ret[1]?), dispatches resulting objects. And of course does the obvious "2.times do  # one optional retry" when operating on a message (still not sure why). And of course is written in Ruby, so you never know if something is a class method, attribute, constant or other element.

    Ah yeah - and I think there's a bug somewhere in there... I'm trying to fix it....



  • VoIP call management in Ruby?  weeps



  • Looks like line noise.  I thought Ruby code was supposed to be beautiful?



  •  @morbiuswilters said:

    VoIP call management in Ruby?  weeps

     Almost - SIP testing framework... The weirdest piece of software I've ever seen. I love to hate it. Unfortunately there's nothing better out there (which sets the standard on a rather low level)



  • @viraptor said:

    And of course is written in Ruby, so you never know if something is a class method, attribute, constant or other element.

    Hey, at least you know if it's a local, instance, class or global variable. Also, <omitting blindfold rant against the OP>



  • @Iago said:

    Looks like line noise.  I thought Ruby code was supposed to be beautiful?

    A lie propagated by the Ruby Lobby.



  • @morbiuswilters said:

    @Iago said:
    Looks like line noise.  I thought Ruby code was supposed to be beautiful?
    An undeniable truth.

    FTFY


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.