how to pass a ubyte[] to c interface?

zhmt via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Mar 12 23:38:18 PDT 2015


I have some source code of vibe.d, it does this in the same way, 
and it works .

void read(ubyte[] dst)
	{
		checkConnected(false);
		acquireReader();
		scope(exit) releaseReader();
		while (dst.length > 0) {
			checkConnected(false);
			logTrace("evbuffer_read %d bytes (fd %d)", dst.length, 
m_ctx.socketfd);
			auto nbytes = bufferevent_read(m_ctx.event, dst.ptr, 
dst.length);
			logTrace(" .. got %d bytes", nbytes);
			dst = dst[nbytes .. $];

			if( dst.length == 0 ) break;

			checkConnected(false);
			m_ctx.core.yieldForEvent();
		}
		logTrace("read data");
	}


More information about the Digitalmars-d-learn mailing list