# File ruby/bstream.rb, line 774
        def shutdown
          dputs ":shutdown message arived."
          @socket_lock.synchronize do
                return if @socket_state == :socket_not_connected
                @socket_state = :socket_closing
                @sending_queue.push nil # wakeup sender thread

          end
          dputs ":waiting for termination of threads..."
          scount = 0
          loop {
                break if @socket_state == :socket_not_connected
                @socket_lock.synchronize do
                  @socket_waiter.wait(0.5)
                end
                scount += 1
                if scount > 3 then
                  @socket.close
                  break
                end
          }
          if @sending_queue.size > 0 then
                dputs ": sending queue: #{@sending_queue.size} messages are remained."
          end
          dputs ":shutdowned."
        end