Ejemplo n.º 1
0
  bool
  Sink::try_send_first_cached(bool last) throw(ZmqErrorType)
  {
    assert(state_ == NOTSENT);
    assert(cached_.valid());
    bool blocked = false;

    try
    {
      if (options_ & OutOptions::EMULATE_BLOCK_SENDS)
      {
        blocked = true;
        ZMQMESSAGE_LOG_STREAM
          << "Emulating blocking send!" << ZMQMESSAGE_LOG_TERM;
      }
      else
      {
        blocked = !do_send_one_non_strict(cached_, last);
      }
    }
    catch (const ZmqErrorType& e)
    {
      cached_.mark_invalid();
      ZMQMESSAGE_LOG_STREAM <<
        "Cannot send first outgoing message: error: " << e.what() <<
        ZMQMESSAGE_LOG_TERM;
      throw;
    }

    if (blocked)
    {
      if (options_ & OutOptions::CACHE_ON_BLOCK)
      {
        ZMQMESSAGE_LOG_STREAM
          << "Cannot send first outgoing message: would block: start caching"
          << ZMQMESSAGE_LOG_TERM;
        state_ = QUEUEING;
        outgoing_queue_.reset(new QueueContainer(init_queue_len));
        add_to_queue(cached_);
      }
      else if (options_ & OutOptions::DROP_ON_BLOCK)
      {
        ZMQMESSAGE_LOG_STREAM <<
          "Cannot send first outgoing message: would block: dropping" <<
          ZMQMESSAGE_LOG_TERM;
        state_ = DROPPING;
      }
      else
      {
        ZMQMESSAGE_LOG_STREAM <<
          "Cannot send first outgoing message: would block: throwing error" <<
          ZMQMESSAGE_LOG_TERM;
        throw_zmq_exception(zmq::error_t());
      }
      return false;
    }

    state_ = SENDING;
    return true;
  }
Ejemplo n.º 2
0
 /**
  * Copy contents of one message part to another
  */
 inline void
 copy_msg(zmq::message_t& target, zmq::message_t& source)
   throw(ZmqErrorType)
 {
   try
   {
     target.copy(&source);
   }
   catch (const zmq::error_t& e)
   {
     throw_zmq_exception(e);
   }
 }
Ejemplo n.º 3
0
 /**
  * Try to receive message part from socket.
  * @return false if would block
  */
 inline bool
 try_recv_msg(zmq::socket_t& sock, zmq::message_t& msg,
   int flags = ZMQ_NOBLOCK) throw(ZmqErrorType)
 {
   bool res = false;
   try
   {
     res = sock.recv(&msg, flags);
   }
   catch (const zmq::error_t& e)
   {
     throw_zmq_exception(e);
   }
   return res;
 }
Ejemplo n.º 4
0
 /**
  * Send message part to socket with specified flags
  */
 inline void
 send_msg(zmq::socket_t& sock, zmq::message_t& msg, int flags)
   throw(ZmqErrorType)
 {
   try
   {
     if (!sock.send(msg, flags))
     {
       throw zmq::error_t();
     }
   }
   catch (const zmq::error_t& e)
   {
     throw_zmq_exception(e);
   }
 }
 void
 init_msg(const void* t, size_t sz, zmq::message_t& msg)
 {
   try
   {
     void *data = ::malloc(sz);
     if (!data)
     {
       throw zmq::error_t();
     }
     ::memcpy(data, t, sz);
     msg.rebuild(data, sz, &zmqmessage_free, 0);
   }
   catch (const zmq::error_t& e)
   {
     throw_zmq_exception(e);
   }
 }
Ejemplo n.º 6
0
 /**
  * Receive message part from socket
  */
 ZMQMESSAGE_DLL_PUBLIC
 inline
 void
 recv_msg(zmq::socket_t& sock, zmq::message_t& msg,
   int flags = 0) throw(ZmqErrorType)
 {
   try
   {
     if (!sock.recv(&msg, flags))
     {
       throw zmq::error_t();
     }
   }
   catch (const zmq::error_t& e)
   {
     throw_zmq_exception(e);
   }
 }
Ejemplo n.º 7
0
  bool
  Sink::do_send_one_non_strict(
    Part& msg, bool last)
    throw (ZmqErrorType)
  {
    const int flags = get_send_flags(last);
    notify_on_send(msg, flags);

    bool ok = false;
    try
    {
      ok = dst_.send(msg, flags);
    }
    catch (const zmq::error_t& e)
    {
      throw_zmq_exception(e);
    }

    if (ok && pending_routing_parts_ > 0)
    {
      --pending_routing_parts_;
    }
    return ok;
  }