示例#1
0
/**
	socket_set_timeout : 'socket -> timout:number? -> void
	<doc>Set the socket send and recv timeout in seconds to the given value (or null for blocking)</doc>
**/
static value socket_set_timeout( value o, value t ) {
	SOCKET sock = val_sock(o);
#ifdef NEKO_WINDOWS
	int time;
	if( val_is_null(t) )
		time = 0;
	else {
		val_check(t,number);
		time = (int)(val_number(t) * 1000);
	}
#else
	struct timeval time;
	if( val_is_null(t) ) {
		time.tv_usec = 0;
		time.tv_sec = 0;
	} else {
		val_check(t,number);
		init_timeval(val_number(t),&time);
	}
#endif
   gc_enter_blocking();
	if( setsockopt(sock,SOL_SOCKET,SO_SNDTIMEO,(char*)&time,sizeof(time)) != 0 )
   {
      gc_exit_blocking();
		return alloc_null();
   }
	if( setsockopt(sock,SOL_SOCKET,SO_RCVTIMEO,(char*)&time,sizeof(time)) != 0 )
   {
      gc_exit_blocking();
		return alloc_null();
   }
   gc_exit_blocking();
	return alloc_bool(true);
}
示例#2
0
文件: thread.c 项目: ConstNW/neko
/**
	tls_set : 'tls -> any -> void
	<doc>
	Set the value of the TLS for the local thread.
	</doc>
**/
static value tls_set( value v, value content ) {
	vtls *t;
	value *r;
	val_check_kind(v,k_tls);
	t = val_tls(v);
#	ifdef NEKO_WINDOWS
	r = (value*)TlsGetValue(t->tls);
#	else
	r = (value*)pthread_getspecific(t->key);
#	endif
	if( r == NULL ) {
		if( val_is_null(content) )
			return val_null;
		r = alloc_root(1);
#		ifdef NEKO_WINDOWS
		TlsSetValue(t->tls,r);
#		else
		pthread_setspecific(t->key,r);
#		endif
	} else if( val_is_null(content) ) {
		free_root(r);
#		ifdef NEKO_WINDOWS
		TlsSetValue(t->tls,NULL);
#		else
		pthread_setspecific(t->key,NULL);
#		endif
		return val_null;
	}
	*r = content;
	return val_null;
}
示例#3
0
static value key_from_pem(value data, value pub, value pass){
	mbedtls_pk_context *pk;
	int r, len;
	value v;
	unsigned char *buf;
	val_check(data, string);
	val_check(pub, bool);
	if (!val_is_null(pass)) val_check(pass, string);
	len = val_strlen(data)+1;
	buf = (unsigned char *)alloc(len);
	memcpy(buf, val_string(data), len-1);
	buf[len-1] = '\0';
	pk = (mbedtls_pk_context *)alloc(sizeof(mbedtls_pk_context));
	mbedtls_pk_init(pk);
	if( val_bool(pub) )
		r = mbedtls_pk_parse_public_key( pk, buf, len );
	else if( val_is_null(pass) )
		r = mbedtls_pk_parse_key( pk, buf, len, NULL, 0 );
	else
		r = mbedtls_pk_parse_key( pk, buf, len, (const unsigned char*)val_string(pass), val_strlen(pass) );
	if( r != 0 ){
		mbedtls_pk_free(pk);
		return ssl_error(r);
	}
	v = alloc_abstract(k_pkey,pk);
	val_gc(v,free_pkey);
	return v;
}
示例#4
0
文件: socket.c 项目: motion-twin/neko
/**
	socket_set_timeout : 'socket -> timout:number? -> void
	<doc>Set the socket send and recv timeout in seconds to the given value (or null for blocking)</doc>
**/
static value socket_set_timeout( value o, value t ) {
#ifdef NEKO_WINDOWS
	int time;
	val_check_kind(o,k_socket);
	if( val_is_null(t) )
		time = 0;
	else {
		val_check(t,number);
		time = (int)(val_number(t) * 1000);
	}
#else
	struct timeval time;
	val_check_kind(o,k_socket);
	if( val_is_null(t) ) {
		time.tv_usec = 0;
		time.tv_sec = 0;
	} else {
		val_check(t,number);
		init_timeval(val_number(t),&time);
	}
#endif
	if( setsockopt(val_sock(o),SOL_SOCKET,SO_SNDTIMEO,(char*)&time,sizeof(time)) != 0 )
		neko_error();
	if( setsockopt(val_sock(o),SOL_SOCKET,SO_RCVTIMEO,(char*)&time,sizeof(time)) != 0 )
		neko_error();
	return val_true;
}
示例#5
0
static value conf_set_verify( value config, value b ) {
	val_check_kind(config, k_ssl_conf);
	if( !val_is_null(b) ) val_check(b, bool);
	if( val_is_null(b) )
		mbedtls_ssl_conf_authmode(val_conf(config), MBEDTLS_SSL_VERIFY_OPTIONAL);
	else if( val_bool(b) )
		mbedtls_ssl_conf_authmode(val_conf(config), MBEDTLS_SSL_VERIFY_REQUIRED);
	else
		mbedtls_ssl_conf_authmode(val_conf(config), MBEDTLS_SSL_VERIFY_NONE);
	return val_true;
}
示例#6
0
文件: socket.c 项目: motion-twin/neko
/**
	socket_select : read : 'socket array -> write : 'socket array -> others : 'socket array -> timeout:number? -> 'socket array array
	<doc>Perform the [select] operation. Timeout is in seconds or [null] if infinite</doc>
**/
static value socket_select( value rs, value ws, value es, value timeout ) {
	struct timeval tval;
	struct timeval *tt;
	SOCKET n = 0;
	fd_set rx, wx, ex;
	fd_set *ra, *wa, *ea;
	value r;
	POSIX_LABEL(select_again);
	ra = make_socket_array(rs,val_array_size(rs),&rx,&n);
	wa = make_socket_array(ws,val_array_size(ws),&wx,&n);
	ea = make_socket_array(es,val_array_size(es),&ex,&n);
	if( ra == &INVALID || wa == &INVALID || ea == &INVALID )
		neko_error();
	if( val_is_null(timeout) )
		tt = NULL;
	else {
		val_check(timeout,number);
		tt = &tval;
		init_timeval(val_number(timeout),tt);
	}
	if( select((int)(n+1),ra,wa,ea,tt) == SOCKET_ERROR ) {
		HANDLE_EINTR(select_again);
		neko_error();
	}
	r = alloc_array(3);
	val_array_ptr(r)[0] = make_array_result(rs,ra);
	val_array_ptr(r)[1] = make_array_result(ws,wa);
	val_array_ptr(r)[2] = make_array_result(es,ea);
	return r;
}
示例#7
0
文件: main.c 项目: robinp/neko
static void report( neko_vm *vm, value exc, int isexc ) {
	int i;
	buffer b = alloc_buffer(NULL);
	value st = neko_exc_stack(vm);
	for(i=0;i<val_array_size(st);i++) {
		value s = val_array_ptr(st)[i];
		buffer_append(b,"Called from ");
		if( val_is_null(s) )
			buffer_append(b,"a C function");
		else if( val_is_string(s) ) {
			buffer_append(b,val_string(s));
			buffer_append(b," (no debug available)");
		} else if( val_is_array(s) && val_array_size(s) == 2 && val_is_string(val_array_ptr(s)[0]) && val_is_int(val_array_ptr(s)[1]) ) {
			val_buffer(b,val_array_ptr(s)[0]);
			buffer_append(b," line ");
			val_buffer(b,val_array_ptr(s)[1]);
		} else
			val_buffer(b,s);
		buffer_append_char(b,'\n');
	}
	if( isexc )
		buffer_append(b,"Uncaught exception - ");
	val_buffer(b,exc);
#	ifdef NEKO_STANDALONE
	neko_standalone_error(val_string(buffer_to_string(b)));
#	else
	fprintf(stderr,"%s\n",val_string(buffer_to_string(b)));
#	endif
}
示例#8
0
AudioBuffer::AudioBuffer (value audioBuffer) {

    if (!init) {

        id_bitsPerSample = val_id ("bitsPerSample");
        id_channels = val_id ("channels");
        id_data = val_id ("data");
        id_sampleRate = val_id ("sampleRate");
        init = true;

    }

    if (!val_is_null (audioBuffer)) {

        bitsPerSample = val_int (val_field (audioBuffer, id_bitsPerSample));
        channels = val_int (val_field (audioBuffer, id_channels));
        data = new ArrayBufferView (val_field (audioBuffer, id_data));
        sampleRate = val_int (val_field (audioBuffer, id_sampleRate));

    } else {

        bitsPerSample = 0;
        channels = 0;
        data = new ArrayBufferView ();
        sampleRate = 0;

    }

    mValue = audioBuffer;

}
示例#9
0
// DECL: static void set(Level level, void (*logFunction) (Level, const char*));
void hx_Logger_static_set_Int_Func(value level, value _logFunction)
{
    Logger::Level _level;
    ValueToEnum(level, _level);

    // Obtain a pointer to the callback wrapper.
    //

    void (*func) (Logger::Level, const char*) = NULL;
    if (!val_is_null(_logFunction))
        func = logFunction;

    // Clear or set the GC root for the Haxe callback.
    //

    if (func == NULL && clbkLogFunction != NULL)
    {
        SAFE_DELETE(clbkLogFunction);
        clbkLogFunction = NULL;
    }
    if (func != NULL)
    {
        if (clbkLogFunction == NULL)
            clbkLogFunction = new AutoGCRoot(_logFunction);
        else
            clbkLogFunction->set(_logFunction);
    }

    Logger::set(_level, func);
}
示例#10
0
	value lime_image_data_util_copy_pixels (value *arg, int nargs) {
		
		enum { image, sourceImage, sourceRect, destPoint, alphaImage, alphaPoint, mergeAlpha };
		
		Image _image = Image (arg[image]);
		Image _sourceImage = Image (arg[sourceImage]);
		Rectangle _sourceRect = Rectangle (arg[sourceRect]);
		Vector2 _destPoint = Vector2 (arg[destPoint]);
		
		if (val_is_null (arg[alphaImage])) {
			
			ImageDataUtil::CopyPixels (&_image, &_sourceImage, &_sourceRect, &_destPoint, 0, 0, val_bool (arg[mergeAlpha]));
			
		} else {
			
			Image _alphaImage = Image (arg[alphaImage]);
			Vector2 _alphaPoint = Vector2 (arg[alphaPoint]);
			
			ImageDataUtil::CopyPixels (&_image, &_sourceImage, &_sourceRect, &_destPoint, &_alphaImage, &_alphaPoint, val_bool (arg[mergeAlpha]));
			
		}
		
		return alloc_null ();
		
	}
示例#11
0
文件: ZLib.cpp 项目: delahee/hxlibc
/**
	inflate_end : 'istream -> void
	<doc>Close a decompression stream</doc>
**/
static value inflate_end( value s ) {
	if (val_is_null(s))
		return alloc_null();
	val_check_kind(s,k_stream_inf);
	free_stream_inf(s);
	return alloc_null();
}
示例#12
0
    value snow_assets_audio_read_bytes_pcm( value _info, value _start, value _len ) {

        QuickVec<unsigned char> buffer;

        value _handle = property_value(_info, id_handle);

        snow::assets::audio::PCM_file_source* pcm_source = snow::from_hx<snow::assets::audio::PCM_file_source>(_handle);

        if( !val_is_null(_handle) && pcm_source ) {

            bool complete = snow::assets::audio::read_bytes_pcm( pcm_source, buffer, val_int(_start), val_int(_len) );

            ByteArray data(buffer);

            value _object = alloc_empty_object();

                alloc_field( _object, id_bytes, data.mValue );
                alloc_field( _object, id_complete, alloc_bool(complete) );

            return _object;

        } else {

            return alloc_null();

        }

    } DEFINE_PRIM(snow_assets_audio_read_bytes_pcm, 3);
示例#13
0
        value snow_iosrc_file_write(value _handle, value _data, value _size, value _num) {

            snow::io::iosrc_file* iosrc = snow::from_hx<snow::io::iosrc_file>( _handle );

            if( iosrc ) {

                if(!val_is_null(_data)) {

                    ByteArray data(_data);

                    long size = val_int(_size);
                    long num = val_int(_num);
                    long len = size * num;

                    if(data.Size() != len) {
                        data.Resize(len);
                    }

                    int res = snow::io::write(iosrc->file_source, data.Bytes(), size, num);

                    return alloc_int(res);

                } //data != null

            } //object from hx

            return alloc_int(-1);

        } DEFINE_PRIM(snow_iosrc_file_write, 4);
示例#14
0
文件: misc.c 项目: MattTuttle/neko
/**
	enable_jit : ?bool -> ?bool
	<doc>Enable or disable the JIT. Calling enable_jit(null) tells if JIT is enabled or not</doc>
**/
static value enable_jit( value b ) {
	if( val_is_null(b) )
		return alloc_bool(neko_vm_jit(neko_vm_current(),-1));
	val_check(b,bool);
	neko_vm_jit(neko_vm_current(),val_bool(b));
	return val_null;
}
示例#15
0
文件: JNI.cpp 项目: restorer/lime
	bool AbstractToJObject (value inValue, jobject &outObject) {
		
		JNIObject *jniobj = 0;
		
		if (AbstractToObject (inValue, jniobj)) {
			
			outObject = jniobj->GetJObject ();
			return true;
			
		}
		
		static int id__jobject = -1;
		
		if (id__jobject < 0) {
			
			id__jobject = val_id ("__jobject");
			
		}
		
		value jobj = val_field (inValue, id__jobject);
		
		if (val_is_null (jobj)) {
			
			return false;
			
		}
		
		return AbstractToJObject (jobj, outObject);
		
	}
示例#16
0
        value snow_iosrc_file_write(value _handle, value _data, value _size, value _num) {

            snow::io::iosrc_file* iosrc = snow::from_hx<snow::io::iosrc_file>( _handle );

            if( iosrc ) {

                if(!val_is_null(_data)) {

                    const unsigned char* data = snow::bytes_from_hx(_data);

                    long size = val_int(_size);
                    long num = val_int(_num);
                    long len = size * num;

                    int res = snow::io::write(iosrc->file_source, data, size, num);

                    return alloc_int(res);

                } //data != null

            } //object from hx

            return alloc_int(-1);

        } DEFINE_PRIM(snow_iosrc_file_write, 4);
示例#17
0
    value snow_assets_audio_read_bytes_wav( value _info, value _start, value _len ) {

        QuickVec<unsigned char> buffer;

        value _handle = property_value(_info, id_handle);

        snow::assets::audio::WAV_file_source* wav_source = snow::from_hx<snow::assets::audio::WAV_file_source>(_handle);

        if( !val_is_null(_handle) && wav_source ) {

            bool complete = snow::assets::audio::read_bytes_wav( wav_source, buffer, val_int(_start), val_int(_len) );

            value data = snow::bytes_to_hx( &buffer[0], buffer.size() );

            value _object = alloc_empty_object();

                alloc_field( _object, id_bytes, data );
                alloc_field( _object, id_complete, alloc_bool(complete) );

            return _object;

        } else {

            return alloc_null();

        }

    } DEFINE_PRIM(snow_assets_audio_read_bytes_wav, 3);
示例#18
0
	value lime_alc_create_context (value device, value attrlist) {
		
		ALCdevice* alcDevice = (ALCdevice*)val_data (device);
		
		ALCint* list = NULL;
		
		if (val_is_null (attrlist) == false) {
			
			int size = val_array_size (attrlist);
			list = new ALCint[size];
			
			for (int i = 0; i < size; ++i) {
				list[i] = (ALCint)val_int( val_array_i (attrlist, i) );
			}
			
		}
		
		ALCcontext* alcContext = alcCreateContext (alcDevice, list);
		
		if (list != NULL) {
			delete[] list;
		}
		
		return CFFIPointer (alcContext);
		
	}
示例#19
0
value AudioBuffer::Value () {

    if (!init) {

        id_bitsPerSample = val_id ("bitsPerSample");
        id_channels = val_id ("channels");
        id_data = val_id ("data");
        id_sampleRate = val_id ("sampleRate");
        init = true;

    }

    if (val_is_null (mValue)) {

        mValue = alloc_empty_object ();

    }

    alloc_field (mValue, id_bitsPerSample, alloc_int (bitsPerSample));
    alloc_field (mValue, id_channels, alloc_int (channels));
    alloc_field (mValue, id_data, data ? data->Value () : alloc_null ());
    alloc_field (mValue, id_sampleRate, alloc_int (sampleRate));
    return mValue;

}
示例#20
0
文件: alloc.c 项目: MattTuttle/neko
EXTERN value alloc_object( value cpy ) {
	vobject *v;
	if( cpy != NULL && !val_is_null(cpy) && !val_is_object(cpy) )
		val_throw(alloc_string("$new")); // 'new' opcode simulate $new
	v = (vobject*)gc_alloc(sizeof(vobject));
	v->t = VAL_OBJECT;
	if( cpy == NULL || val_is_null(cpy) ) {
		v->proto = NULL;
		otable_init(&v->table);

	} else {
		v->proto = ((vobject*)cpy)->proto;
		otable_copy(&((vobject*)cpy)->table,&v->table);
	}
	return (value)v;
}
示例#21
0
文件: mysql.c 项目: bsmr-haxe/neko
/**
	connect : { host => string, port => int, user => string, pass => string, socket => string? } -> 'connection
	<doc>Connect to a database using the connection informations</doc>
**/
static value connect_mysql( value params  ) {
	value host, port, user, pass, socket;
	val_check(params,object);
	host = val_field(params,val_id("host"));
	port = val_field(params,val_id("port"));
	user = val_field(params,val_id("user"));
	pass = val_field(params,val_id("pass"));
	socket = val_field(params,val_id("socket"));
	val_check(host,string);
	val_check(port,int);
	val_check(user,string);
	val_check(pass,string);
	if( !val_is_string(socket) && !val_is_null(socket) )
		neko_error();
	{
		connection *c = (connection*)alloc(sizeof(connection));		
		value v;
		c->m = mysql_init(NULL);
		c->conv_string = NULL;
		c->conv_date = NULL;
		c->conv_bytes = NULL;
		if( mysql_real_connect(c->m,val_string(host),val_string(user),val_string(pass),NULL,val_int(port),val_is_null(socket)?NULL:val_string(socket),0) == NULL ) {
			buffer b = alloc_buffer("Failed to connect to mysql server : ");
			buffer_append(b,mysql_error(c->m));
			mysql_close(c->m);
			bfailure(b);
		}
		v = alloc_abstract(k_connection,c);
		val_gc(v,free_connection);
		return v;
	}
}
示例#22
0
static void dump_module( value v, field f, void *p ) {
	value vname;
	const char *name;
	if( !val_is_kind(v,neko_kind_module) )
		return;
	vname = val_field_name(f);
	name = val_is_null(vname)?"???":val_string(vname);
	((dump_param*)p)->callb( name, (neko_module*)val_data(v), &((dump_param*)p)->tot );
}
示例#23
0
文件: cgi.c 项目: HaxeFoundation/neko
/**
	cgi_set_main : function:0? -> void
	<doc>Set or disable the main entry point function</doc>
**/
static value cgi_set_main( value f ) {
	if( val_is_null(f) ) {
		CONTEXT()->main = NULL;
		return val_true;
	}
	val_check_function(f,0);
	CONTEXT()->main = f;
	return val_true;
}
示例#24
0
文件: socket.c 项目: motion-twin/neko
/**
	socket_set_keepalive : 'socket -> bool -> time:int? -> interval:int? -> void
	<doc>
	Enable or disable TCP_KEEPALIVE flag for the socket
	</doc>
**/
static value socket_set_keepalive( value o, value b, value time, value interval ) {
	int val;
	SOCKET s;
	val_check_kind(o,k_socket);
	val_check(b,bool);
	if( !val_is_null(time) || !val_is_null(interval) ){
		val_check(time,int);
		val_check(interval,int);
	}
	s = val_sock(o);
	if( !val_bool(b) ) {
		val = 0;
		if( setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, (void *)&val, sizeof(val)) != 0 )
			neko_error();
	} else {
		val = 1;
		if( setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, (void *)&val, sizeof(val)) != 0 )
			neko_error();

		if( !val_is_null(time) && !val_is_null(interval) ) {
#			if defined(NEKO_WINDOWS)
			u_long params[3] = { 1, (unsigned long)val_int(time)*1000, (unsigned long)val_int(interval)*1000 };
			if( WSAIoctl(s, SIO_KEEPALIVE_VALS, &params, sizeof(params), NULL, 0, &val, NULL, NULL) != 0 )
				neko_error();
#			else
#			if defined(TCP_KEEPIDLE)
			val = val_int(time);
			if( setsockopt(s, IPPROTO_TCP, TCP_KEEPIDLE, (void *)&val, sizeof(val)) != 0 )
				neko_error();
#			elif defined(TCP_KEEPALIVE)
			val = val_int(time);
			if( setsockopt(s, IPPROTO_TCP, TCP_KEEPALIVE, (void *)&val, sizeof(val)) != 0 )
				neko_error();
#			endif
#			if defined(TCP_KEEPINTVL)
			val = val_int(interval);
			if( setsockopt(s, IPPROTO_TCP, TCP_KEEPINTVL, (void *)&val, sizeof(val)) != 0 )
				neko_error();
#			endif
#			endif
		}
	}
	return val_null;
}
示例#25
0
	void gc_cairo_surface (value handle) {
		
		if (!val_is_null (handle)) {
			
			cairo_surface_t* surface = (cairo_surface_t*)val_data (handle);
			cairo_surface_destroy (surface);
			
		}
		
	}
示例#26
0
	void gc_cairo_pattern (value handle) {
		
		if (!val_is_null (handle)) {
			
			cairo_pattern_t* pattern = (cairo_pattern_t*)val_data (handle);
			cairo_pattern_destroy (pattern);
			
		}
		
	}
示例#27
0
	void gc_cairo_font_options (value handle) {
		
		if (!val_is_null (handle)) {
			
			cairo_font_options_t* options = (cairo_font_options_t*)val_data (handle);
			cairo_font_options_destroy (options);
			
		}
		
	}
示例#28
0
	void gc_cairo_font_face (value handle) {
		
		if (!val_is_null (handle)) {
			
			cairo_font_face_t* face = (cairo_font_face_t*)val_data (handle);
			cairo_font_face_destroy (face);
			
		}
		
	}
示例#29
0
	void gc_cairo (value handle) {
		
		if (!val_is_null (handle)) {
			
			cairo_t* cairo = (cairo_t*)val_data (handle);
			cairo_destroy (cairo);
			
		}
		
	}
示例#30
0
static int sni_callback( void *arg, mbedtls_ssl_context *ctx, const unsigned char *name, size_t len ){
	if( name && arg ){
	 	value ret = val_call1((value)arg, alloc_string((const char*)name)) ;
		if( !val_is_null(ret) ){
			// TODO authmode and ca
			return mbedtls_ssl_set_hs_own_cert( ctx, val_cert(val_field(ret, val_id("cert"))), val_pkey(val_field(ret, val_id("key"))) );
		}
	}
	return -1;
}