Example #1
0
void websocket::handle_data_v8(shared_buffer data, bool is_binary)
{
	v8::Isolate* isolate = v8::Isolate::GetCurrent();
	v8::HandleScope scope(isolate);

	v8::Local<v8::Value> self = v8pp::to_v8(isolate, this);
	if (!self.IsEmpty())
	{
		v8::Handle<v8::Value> args[2];
		args[1] = v8pp::to_v8(isolate, is_binary);
		if ( is_binary )
		{
			v8_core::buffer* buf = new v8_core::buffer;
			buf->swap(*data);
			args[0] = v8pp::class_<v8_core::buffer>::import_external(isolate, buf);
		}
		else
		{
			char const* const chars = reinterpret_cast<char const*>(data->empty()? nullptr : &*(data->begin()));
			int const length = static_cast<int>(data->size());
			args[0] = v8pp::to_v8(isolate, chars, length);
		}
		emitter_->emit(isolate, "data", self->ToObject(), 2, args);
	}
}
Example #2
0
    package_ptr typed_pkg_hub::get_pkg(const shared_buffer & buf){
        const char *pBuf = buf.buffer();
        uint32_t iTypeID;
        ffnet::deseralize(pBuf, iTypeID);
        LOG(INFO)<<"typed_pkt_hub::get_pkg(), buf is "<<print_buf(pBuf, buf.length());

        if (m_oPkgCreatorContainer.find(iTypeID) == m_oPkgCreatorContainer.end()) {
            LOG(ERROR) << "TypedPkgHub::get_pkg() " << "can't find the type id:" << iTypeID;
            assert(0 && "can't find the type id in service recv pkg set!");
            return package_ptr();
        }
        pkg_creator_t pkg_creator = m_oPkgCreatorContainer[iTypeID];
        package_ptr pPkg = pkg_creator();
        marshaler d(const_cast<const char *>(pBuf), buf.length(), marshaler::deseralizer);
        pPkg->arch(d);
        LOG(INFO) << "TypedPkgHub::get_pkg(), a pkg with id:" << pPkg->type_id() <<
                        " is forward to user";
        return pPkg;
    }
Example #3
0
 void start_timer( timer* timer, shared_buffer buffer, Handler handler ) const
 {
     if ( ! timeouts_enabled() )
         delete timer;
     else
     {
         if ( timer != NULL )
         {
             if ( timeout_type_ == TimePerKilobyte)
                 timer->wait( (buffer->size() / 1024.0) * timeout_milliseconds_,
                              handler);
             else
                 timer->wait( timeout_milliseconds_, handler);
         }
     }
 }
Example #4
0
void websocket_hybi_17::on_write_completed(shared_buffer buf, error_code err, size_t bytes_transferred)
{
	check_err(!err && bytes_transferred >= buf->size(), "async send");
}