Пример #1
0
void handle_read(struct request *req, int val){
    aiob *aio = req->aio;
    close(aio->aio_fildes);
    if(val){
        FREE(aio->aio_buf);
        push_number(val);
        set_eval(max_cost);
        safe_call_efun_callback(req->fun, 1);
        return;
    }
    val = aio_return(aio);
    if(val < 0){
        FREE(aio->aio_buf);
        push_number(val);
        set_eval(max_cost);
        safe_call_efun_callback(req->fun, 1);
        return;
    }
    char *file = new_string(val, "read_file_async: str");
    memcpy(file, (char *)(aio->aio_buf), val);
    file[val]=0;
    push_malloced_string(file);
    FREE(aio->aio_buf);
    set_eval(max_cost);
    safe_call_efun_callback(req->fun, 1);
}
Пример #2
0
void handle_write(struct request *req){
	free_svalue(&req->tmp, "handle_write");
	int val = req->ret;
	if(val < 0){
		push_number(val);
		set_eval(max_cost);
		safe_call_efun_callback(req->fun, 1);
		return;
	}
	push_undefined();
	set_eval(max_cost);
	safe_call_efun_callback(req->fun, 1);
}
Пример #3
0
void handle_getdir(struct request *req, int val){
    aiob *aio = req->aio;
    close(aio->aio_fildes);
    val = aio_return(aio);
    array_t *ret = allocate_empty_array(val);
    int i;
    if(val > -1)
    {
        struct linux_dirent *de = (struct linux_dirent *)aio->aio_buf;
        for(i=0; ((char *)de) - (char *)(aio->aio_buf) < val; i++)
        {
            svalue_t *vp = &(ret->item[i]);
            vp->type = T_STRING;
            vp->subtype = STRING_MALLOC;
            //printf("%s ", de->d_name);
            vp->u.string = string_copy(de->d_name, "encode_stat");
            de = (struct linux_dirent *)(((char *)de) + de->d_reclen);
        }
    }
    ret = RESIZE_ARRAY(ret, i);
    ret->size = i;
    push_refed_array(ret);
    set_eval(max_cost);
    safe_call_efun_callback(req->fun, 1);
}
Пример #4
0
void handle_getdir(struct request *req){
	int val = req->ret;
	if(val>MAX_ARRAY_SIZE)
		val = MAX_ARRAY_SIZE;
	array_t *ret = allocate_empty_array(val);
	int i=0;
	if(val > 0)
	{
		struct linux_dirent *de = (struct linux_dirent *)req->buf;
		for(i=0; i<MAX_ARRAY_SIZE && ((char *)de) - (char *)(req->buf) < val; i++)
		{
			svalue_t *vp = &(ret->item[i]);
			vp->type = T_STRING;
			vp->subtype = STRING_MALLOC;
			vp->u.string = string_copy(de->d_name, "encode_stat");
			de = (struct linux_dirent *)(((char *)de) + de->d_reclen);
		}
	}
	ret = resize_array(ret, i);
	ret->size = i;
	push_refed_array(ret);
	FREE((void *)req->buf);
	set_eval(max_cost);
	safe_call_efun_callback(req->fun, 1);
}
Пример #5
0
void handle_read(struct request *req){
	int val = req->ret;
	if(val < 0){
		FREE((void *)req->buf);
		push_number(val);
		set_eval(max_cost);
		safe_call_efun_callback(req->fun, 1);
		return;
	}
	char *file = new_string(val, "read_file_async: str");
	memcpy(file, (char *)(req->buf), val);
	file[val]=0;
	push_malloced_string(file);
	FREE((void *)req->buf);
	set_eval(max_cost);
	safe_call_efun_callback(req->fun, 1);
}
Пример #6
0
void handle_db_exec(struct request *req){
	free_svalue(&req->tmp, "handle_db_exec");
	int val = req->ret;
	if(val == -1){
		copy_and_push_string(req->path);
	}
	else
		push_number(val);
	set_eval(max_cost);
	safe_call_efun_callback(req->fun, 1);
}
Пример #7
0
void handle_write(struct request *req, int val){
    aiob *aio = req->aio;
    close(aio->aio_fildes);
    free_svalue(&req->tmp, "handle_write");
    if(val){
        push_number(val);
        set_eval(max_cost);
        safe_call_efun_callback(req->fun, 1);
        return;
    }
    val = aio_return(aio);
    if(val < 0){
        push_number(val);
        set_eval(max_cost);
        safe_call_efun_callback(req->fun, 1);
        return;
    }
    push_undefined();
    set_eval(max_cost);
    safe_call_efun_callback(req->fun, 1);
}