Exemplo n.º 1
0
/**
 * \brief Send the MIH message to the local MIHF asynchronously
 * \param msg MIH message to send
 * \param h Completion callback handler as a function pointer/object
 *
 * After the message is sended, the callback is called to report
 * the success or failure in delivering the message to the MIHF.
 *
 * \remarks This method retuns immediately.
 */
void link::async_send(mih::message& msg, const handler& h)
{
	mih::frame_vla fm;
	void* sbuff;
	size_t slen;

	msg.source(odtone::mih::id("link"));
	msg.destination(odtone::mih::id("local-mihf"));
	msg.get_frame(fm);

	sbuff = fm.get();
	slen = fm.size();

	_sock.async_send(boost::asio::buffer(sbuff, slen),
					 boost::bind(&link::send_handler,
								 this,
								 bindrv(fm),
								 h,
								 boost::asio::placeholders::bytes_transferred,
								 boost::asio::placeholders::error));
}
Exemplo n.º 2
0
/**
 * Asynchronously send a MIH message to the local MIHF.
 * After sending the message, the callback is called to report the
 * success or failure in delivering the message to the local MIHF.
 * This method retuns immediately.
 *
 * @param msg MIH message to send.
 * @param h Response handler function.
 */
void user::async_send_(mih::message& msg, handler&& h)
{
	if (msg.opcode() == mih::operation::request) {
		uint16 id = std::rand() & 0x0FFF; //12 bits transaction id

		boost::mutex::scoped_lock sl(_mutex);
		rmap::iterator ie = _rmap.end();

		if (!_rmap.empty())
			id = uint16(_rmap.rbegin()->first) + 1;
		id = (id >= 0x0FFF) ? 1 : id;

		while (_rmap.find(id) != ie) {
			id += 1;
			id = (id >= 0x0FFF) ? 1 : id;
		}

		msg.tid(id);
		_rmap[id] = std::move(h);
		h.clear();
	}

	mih::frame_vla fm;
	void* sbuff;
	size_t slen;

	msg.source(_user_id);
	msg.get_frame(fm);

	sbuff = fm.get();
	slen = fm.size();

	_sock.async_send_to(boost::asio::buffer(sbuff, slen),
			    _ep,
					 boost::bind(&user::send_handler,
								 this,
								 bind_rv(fm),
								 std::move(h),
								 boost::asio::placeholders::error));
}
Exemplo n.º 3
0
Arquivo: sap.cpp Projeto: ATNoG/ODTONE
/**
 * Asynchronously send a MIH message to the local MIHF.
 * After sending the message, the callback is called to report the
 * success or failure in delivering the message to the local MIHF.
 * This method retuns immediately.
 *
 * @param msg MIH message to send.
 * @param h Response handler function.
 */
void test::async_send_mihf1(mih::message& msg, const handler& h)
{
	mih::frame_vla fm;
	void* sbuff;
	size_t slen;

	msg.source(_link_id);

	msg.get_frame(fm);

	sbuff = fm.get();
	slen = fm.size();

	_sock.async_send_to(boost::asio::buffer(sbuff, slen),
			    _ep1,
			    boost::bind(&test::send_handler,
					this,
					bind_rv(fm),
					h,
					boost::asio::placeholders::bytes_transferred,
					boost::asio::placeholders::error));
}