Beispiel #1
0
value hxfcgi_get_method(value hreq) {
	val_check_kind(hreq,hxRequest);
	hxfcgi::BasicData d;
	char *ret = d.getMethod();
	if (ret == NULL)
		hx_failure("This seems not to be a HTTP Request");
	return alloc_string(ret);	
}
void HaxeScreenDisplayer::complete()
{
    if (!initialized)
        hx_failure("The \"run\" method was not yet called.");
    else
    {
        delete screenDisplayer;
        screenDisplayer = NULL;
    }
}
void HaxeScreenDisplayer::run(const value& method, void *cookie, unsigned long time)
{
    if (initialized)
        hx_failure("The \"run\" method was already called.");

    screenDisplayer = new ScreenDisplayer();
    initialized = true;
    clbkMethod = &method;

    screenDisplayer->run(this, &HaxeScreenDisplayer::delegateCall, cookie, time);
}
Beispiel #4
0
value hxfcgi_create_request() {
	try {
		hxfcgi::Request *req = new hxfcgi::Request();
		value ret = alloc_abstract(hxRequest,req);
		return ret;
	}
	catch (string error) {
		hx_failure(error.c_str());
	}
	return val_null;	
}
Beispiel #5
0
/**
	inflate_buffer : 'istream -> src:string -> srcpos:int -> dst:string -> dstpos:int -> { done => bool, read => int, write => int }
**/
static value inflate_buffer( value s, value src, value srcpos, value dst, value dstpos ) {
	z_stream *z;
	int err;
	value o;
	val_check_kind(s,k_stream_inf);
	val_check(srcpos,int);

	buffer src_buf = val_to_buffer(src);
	if (!src_buf)
	   hx_failure("invalid source buffer");
	buffer dst_buf = val_to_buffer(dst);
	if (!dst_buf)
	   hx_failure("invalid destination buffer");

	int slen = buffer_size(src_buf);
	int dlen = buffer_size(dst_buf);

	val_check(dstpos,int);
	z = val_stream(s);
	if( val_int(srcpos) < 0 || val_int(dstpos) < 0 )
		return alloc_null();
	slen -= val_int(srcpos);
	dlen -= val_int(dstpos);
	if( slen < 0 || dlen < 0 )
		return alloc_null();

	z->next_in = (Bytef*)buffer_data(src_buf) + val_int(srcpos);
	z->next_out = (Bytef*)buffer_data(dst_buf) + val_int(dstpos);
	z->avail_in = slen;
	z->avail_out = dlen;
	if( (err = inflate(z,val_flush(z))) < 0 )
		zlib_error(z,err);
	z->next_in = NULL;
	z->next_out = NULL;
	o = alloc_empty_object();
	alloc_field(o,id_done,alloc_bool(err == Z_STREAM_END));
	alloc_field(o,id_read,alloc_int((int)(slen - z->avail_in)));
	alloc_field(o,id_write,alloc_int((int)(dlen - z->avail_out)));
	return o;
}
Beispiel #6
0
value hxfcgi_cache_module(value func) {
	val_check_function(func,1);
	hxfcgi::Request *req;
	while (true) {
		try {
			if(FCGX_IsCGI()) break;
			req = new hxfcgi::Request();
			val_call1(func,alloc_abstract(hxRequest,req));
			delete req;
		}
		catch (string error) {
			hx_failure(error.c_str());
			break;
		}
	}
	return val_null;
	
}
Beispiel #7
0
/**
	socket_send : 'socket -> buf:string -> pos:int -> len:int -> int
	<doc>Send up to [len] bytes from [buf] starting at [pos] over a connected socket.
	Return the number of bytes sent.</doc>
**/
static value socket_send( value o, value data, value pos, value len ) {
	int p,l,dlen;
	SOCKET sock = val_sock(o);
	val_check(pos,int);
	val_check(len,int);
        buffer buf = val_to_buffer(data);
        if (!buf)
           hx_failure("not bytebuffer");
	p = val_int(pos);
	l = val_int(len);
	dlen = buffer_size(buf);
	if( p < 0 || l < 0 || p > dlen || p + l > dlen )
		return alloc_null();
	gc_enter_blocking();
	dlen = send(sock, buffer_data(buf) + p , l, MSG_NOSIGNAL);
	if( dlen == SOCKET_ERROR )
		return block_error();
	gc_exit_blocking();
	return alloc_int(dlen);
}
HaxeScreenDisplayer::~HaxeScreenDisplayer()
{
    if (initialized && screenDisplayer != NULL)
        hx_failure("You must invoke \"complete\" after calling \"run\".");
}