### Home Classes Methods

### In Files

- lib/xmpp4r/bytestreams/helper/ibb/base.rb

### Parent

Object

### Methods

- ::new
- #active?
- #close
- #flush
- #read
- #write

### Files

- CHANGELOG
- COPYING
- LICENSE
- README.rdoc
- README_ruby19.txt

### Class/Module Index

Quicksearch

- Jabber
- Jabber::ArgumentError
- Jabber::Bytestreams
- Jabber::Bytestreams::IBB
- Jabber::Bytestreams::IBBInitiator
- Jabber::Bytestreams::IBBQueueItem
- Jabber::Bytestreams::IBBTarget
- Jabber::Bytestreams::IqQueryBytestreams
- Jabber::Bytestreams::IqSi
- Jabber::Bytestreams::IqSiFile
- Jabber::Bytestreams::IqSiFileRange
- Jabber::Bytestreams::SOCKS5Bytestreams
- Jabber::Bytestreams::SOCKS5BytestreamsInitiator
- Jabber::Bytestreams::SOCKS5BytestreamsPeer
- Jabber::Bytestreams::SOCKS5BytestreamsServer
- Jabber::Bytestreams::SOCKS5BytestreamsServerStreamHost
- Jabber::Bytestreams::SOCKS5BytestreamsTarget
- Jabber::Bytestreams::SOCKS5Socket
- Jabber::Bytestreams::StreamHost
- Jabber::Bytestreams::StreamHostUsed
- Jabber::Callback
- Jabber::CallbackList
- Jabber::Caps
- Jabber::Caps::C
- Jabber::Caps::Helper
- Jabber::Client
- Jabber::ClientAuthenticationFailure
- Jabber::Command
- Jabber::Command::IqCommand
- Jabber::Command::Responder
- Jabber::Component
- Jabber::ComponentAuthenticationFailure
- Jabber::Connection
- Jabber::Connection::SSLSocketUTF8
- Jabber::Dataforms
- Jabber::Dataforms::XData
- Jabber::Dataforms::XDataField
- Jabber::Dataforms::XDataInstructions
- Jabber::Dataforms::XDataReported
- Jabber::Dataforms::XDataTitle
- Jabber::Delay
- Jabber::Delay::XDelay
- Jabber::Discovery
- Jabber::Discovery::Feature
- Jabber::Discovery::Helper
- Jabber::Discovery::Identity
- Jabber::Discovery::IqQueryDiscoInfo
- Jabber::Discovery::IqQueryDiscoItems
- Jabber::Discovery::Item
- Jabber::Discovery::Responder
- Jabber::EntityTime
- Jabber::EntityTime::IqTime
- Jabber::EntityTime::Responder
- Jabber::ErrorResponse
- Jabber::FeatureNegotiation
- Jabber::FeatureNegotiation::IqFeature
- Jabber::FileTransfer
- Jabber::FileTransfer::FileSource
- Jabber::FileTransfer::Helper
- Jabber::FileTransfer::TransferSource
- Jabber::Framework
- Jabber::Framework::Base
- Jabber::Framework::Bot
- Jabber::HTTPBinding
- Jabber::HTTPBinding::Client
- Jabber::IdGenerator
- Jabber::InvalidChatState
- Jabber::Iq
- Jabber::IqQuery
- Jabber::JID
- Jabber::JabberError
- Jabber::LastActivity
- Jabber::LastActivity::Helper
- Jabber::LastActivity::IqQueryLastActivity
- Jabber::MUC
- Jabber::MUC::IqQueryMUCAdmin
- Jabber::MUC::IqQueryMUCAdminItem
- Jabber::MUC::IqQueryMUCOwner
- Jabber::MUC::MUCBrowser
- Jabber::MUC::MUCClient
- Jabber::MUC::SimpleMUCClient
- Jabber::MUC::UserItem
- Jabber::MUC::XMUC
- Jabber::MUC::XMUCUser
- Jabber::MUC::XMUCUserInvite
- Jabber::MUC::XMUCUserItem
- Jabber::Message
- Jabber::NoNameXmlnsRegistered
- Jabber::NotConnected
- Jabber::Observable
- Jabber::Observable::Contact
- Jabber::Observable::PubSub
- Jabber::Observable::PubSub::AlreadySet
- Jabber::Observable::PubSub::NoService
- Jabber::Observable::Subscriptions
- Jabber::Presence
- Jabber::PubSub
- Jabber::PubSub::Configuration
- Jabber::PubSub::Event
- Jabber::PubSub::EventItem
- Jabber::PubSub::EventItems
- Jabber::PubSub::IqPubSub
- Jabber::PubSub::IqPubSubOwner
- Jabber::PubSub::Item
- Jabber::PubSub::Items
- Jabber::PubSub::NodeBrowser
- Jabber::PubSub::NodeConfig
- Jabber::PubSub::NodeHelper
- Jabber::PubSub::OAuthPubSubStreamHelper
- Jabber::PubSub::OAuthServiceHelper
- Jabber::PubSub::OwnerNodeConfig
- Jabber::PubSub::Publish
- Jabber::PubSub::Retract
- Jabber::PubSub::ServiceHelper
- Jabber::PubSub::Subscription
- Jabber::PubSub::SubscriptionConfig
- Jabber::PubSub::Unsubscribe
- Jabber::RPC
- Jabber::RPC::Client
- Jabber::RPC::IqQueryRPC
- Jabber::RPC::Server
- Jabber::Reliable
- Jabber::Reliable::Connection
- Jabber::Reliable::Listener
- Jabber::Roster
- Jabber::Roster::Helper
- Jabber::Roster::Helper::RosterItem
- Jabber::Roster::IqQueryRoster
- Jabber::Roster::RosterItem
- Jabber::Roster::RosterX
- Jabber::Roster::RosterXItem
- Jabber::Roster::XRoster
- Jabber::Roster::XRosterItem
- Jabber::SASL
- Jabber::SASL::Anonymous
- Jabber::SASL::Base
- Jabber::SASL::DigestMD5
- Jabber::SASL::Plain
- Jabber::SOCKS5Error
- Jabber::Semaphore
- Jabber::ServerDisconnected
- Jabber::Stream
- Jabber::Stream::ThreadBlock
- Jabber::StreamParser
- Jabber::Test
- Jabber::Test::ListenerMocker
- Jabber::UserLocation
- Jabber::UserLocation::Helper
- Jabber::UserLocation::Location
- Jabber::UserTune
- Jabber::UserTune::Helper
- Jabber::UserTune::Tune
- Jabber::Vcard
- Jabber::Vcard::Helper
- Jabber::Vcard::IqVcard
- Jabber::Version
- Jabber::Version::IqQueryVersion
- Jabber::Version::Responder
- Jabber::Version::SimpleResponder
- Jabber::X
- Jabber::XHTML
- Jabber::XHTML::Body
- Jabber::XHTML::HTML
- Jabber::XMPPElement
- Jabber::XMPPStanza
- Jabber::XParent
- REXML
- REXML::Element
- REXML::IOSource
- XMLRPC
- XMLRPC::Create
- Base64
- ObservableThing
- QObserver
- ThreadStore

No matching classes.

# Jabber::Bytestreams::IBB

In-Band Bytestreams (JEP-0047) implementation

Don't use directly, use IBBInitiator and IBBTarget

In-Band Bytestreams should only be used when transferring very small amounts of binary data, because it is slow and increases server load drastically.

Note that the constructor takes a lot of arguments. In-Band Bytestreams do not specify a way to initiate the stream, this should be done via Stream Initiation.

### Constants

NS_IBB

### Public Class Methods

new(stream, session_id, my_jid, peer_jid) click to toggle source

Create a new bytestream

Will register a <message/> callback to intercept data of this stream. This data will be buffered, you can retrieve it with receive

    # File lib/xmpp4r/bytestreams/helper/ibb/base.rb, line 30
    def initialize(stream, session_id, my_jid, peer_jid)
      @stream = stream
      @session_id = session_id
      @my_jid = (my_jid.kind_of?(String) ? JID.new(my_jid) : my_jid)
      @peer_jid = (peer_jid.kind_of?(String) ? JID.new(peer_jid) : peer_jid)

      @active = false
      @seq_send = 0
      @seq_recv = 0
      @queue = []
      @queue_lock = Mutex.new
      @pending = Semaphore.new
      @sendbuf = ''
      @sendbuf_lock = Mutex.new

      @block_size = 4096  # Recommended by JEP0047
    end

### Public Instance Methods

active?() click to toggle source

    # File lib/xmpp4r/bytestreams/helper/ibb/base.rb, line 48
    def active?
      @active
    end

close() click to toggle source

Close the stream

Waits for acknowledge from peer, may throw ServerError

    # File lib/xmpp4r/bytestreams/helper/ibb/base.rb, line 128
    def close
      if active?
        flush
        deactivate

        iq = Iq.new(:set, @peer_jid)
        close = iq.add REXML::Element.new('close')
        close.add_namespace IBB::NS_IBB
        close.attributes['sid'] = @session_id

        @stream.send_with_id(iq)
      end
    end

flush() click to toggle source

Empty the send-buffer by sending remaining data

    # File lib/xmpp4r/bytestreams/helper/ibb/base.rb, line 72
    def flush
      @sendbuf_lock.synchronize {
        while @sendbuf.size > 0
          send_data(@sendbuf[0..@block_size-1])
          @sendbuf = @sendbuf[@block_size..-1].to_s
        end
      }
    end

read() click to toggle source

Receive data

Will wait until the Message with the next sequence number is in the stanza queue.

    # File lib/xmpp4r/bytestreams/helper/ibb/base.rb, line 86
    def read
      if active?
        res = nil

        while res.nil?
          @queue_lock.synchronize {
            @queue.each { |item|
              # Find next data
              if item.type == :data and item.seq == @seq_recv.to_s
                res = item
                break
              # No data? Find close
              elsif item.type == :close and res.nil?
                res = item
              end
            }

            @queue.delete_if { |item| item == res }
          }

          # No data? Wait for next to arrive...
          @pending.wait unless res
        end

        if res.type == :data
          @seq_recv += 1
          @seq_recv = 0 if @seq_recv > 65535
          res.data
        elsif res.type == :close
          deactivate
          nil # Closed
        end
      else
        nil
      end
    end

write(buf) click to toggle source

Send data

Data is buffered to match block_size in each packet. If you need the data to be sent immediately, use flush afterwards.

buf

String

    # File lib/xmpp4r/bytestreams/helper/ibb/base.rb, line 59
    def write(buf)
      @sendbuf_lock.synchronize {
        @sendbuf += buf

        while @sendbuf.size >= @block_size
          send_data(@sendbuf[0..@block_size-1])
          @sendbuf = @sendbuf[@block_size..-1].to_s
        end
      }
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.