Esempio n. 1
0
primitiveValidateCompressedBuffer(void)
{
	const char*compressed;
	size_t compressedLength;
	sqInt compressedObj;
	char* ptr;
	snappy_status status;

	if (!((interpreterProxy->methodArgumentCount()) == 1)) {
		interpreterProxy->primitiveFail(); return;
	}
	compressedObj = interpreterProxy->stackValue(0);
	/* begin charPointerFor: */
	if (!(interpreterProxy->isBytes(compressedObj))) {
		compressed = ((char*) null);
		goto l1;
	}
	ptr = ((char*) (interpreterProxy->firstIndexableField(compressedObj)));
	compressed = ((char*) ptr);
l1:	/* end charPointerFor: */;
	if (!(compressed)) {
		interpreterProxy->primitiveFail(); return;
	}
	compressedLength = interpreterProxy->byteSizeOf(compressedObj);
	status = snappy_validate_compressed_buffer(compressed, compressedLength);
	interpreterProxy->pop((interpreterProxy->methodArgumentCount()) + 1);
	interpreterProxy->pushInteger(status);
}
Esempio n. 2
0
static hg_return_t
snappy_pull_cb(const struct hg_bulk_cb_info *hg_bulk_cb_info)
{
    struct snappy_transfer_args *snappy_transfer_args =
            (struct snappy_transfer_args *) hg_bulk_cb_info->arg;
    hg_return_t ret = HG_SUCCESS;
    void *input;
    size_t input_length;
    size_t source_length = HG_Bulk_get_size(snappy_transfer_args->local_input_bulk_handle);

    /* Get pointer to input buffer from local handle */
    HG_Bulk_access(hg_bulk_cb_info->local_handle, 0, source_length,
            HG_BULK_READ_ONLY, 1, &input, &input_length, NULL);
    printf("Transferred input buffer of length: %zu\n", input_length);
    print_buf(20, (int *) input);

    /* Allocate compressed buffer for compressing input data */
    snappy_transfer_args->compressed_length = snappy_max_compressed_length(input_length);
    snappy_transfer_args->compressed = malloc(snappy_transfer_args->compressed_length);

    /* Compress data */
    printf("Compressing buffer...\n");
    snappy_transfer_args->ret = snappy_compress(input, input_length,
            snappy_transfer_args->compressed, &snappy_transfer_args->compressed_length);
    printf("Return value of snappy_compress is: %d\n", snappy_transfer_args->ret);
    printf("Compressed buffer length is: %zu\n", snappy_transfer_args->compressed_length);
    print_buf(5, (int *) snappy_transfer_args->compressed);

    /* Free bulk handles */
    HG_Bulk_free(snappy_transfer_args->local_input_bulk_handle);

    if (snappy_validate_compressed_buffer(snappy_transfer_args->compressed,
            snappy_transfer_args->compressed_length) == SNAPPY_OK) {
        printf("Compressed buffer validated: compressed successfully\n");
    }

    /* Now set up bulk transfer for "push to origin" callback */
    HG_Bulk_create(HG_Get_info(snappy_transfer_args->handle)->hg_bulk_class, 1,
            &snappy_transfer_args->compressed, &snappy_transfer_args->compressed_length,
            HG_BULK_WRITE_ONLY, &snappy_transfer_args->local_compressed_bulk_handle);

    HG_Bulk_transfer(HG_Get_info(snappy_transfer_args->handle)->bulk_context,
            snappy_push_cb, snappy_transfer_args,
            HG_BULK_PUSH, HG_Get_info(snappy_transfer_args->handle)->addr,
            snappy_transfer_args->snappy_compress_input.compressed_bulk_handle, 0, /* origin */
            snappy_transfer_args->local_compressed_bulk_handle, 0, /* local */
            snappy_transfer_args->compressed_length, HG_OP_ID_IGNORE);

    return ret;
}
Esempio n. 3
0
primitiveRawValidateCompressedBuffer(void)
{
	const char*compressed;
	size_t compressedLength;
	sqInt compressedObj;
	sqInt num;
	sqInt num1;
	size_t offset;
	char* ptr;
	snappy_status status;

	if (!((interpreterProxy->methodArgumentCount()) == 3)) {
		interpreterProxy->primitiveFail(); return;
	}
	compressedObj = interpreterProxy->stackValue(2);
	/* begin charPointerFor: */
	if (!(interpreterProxy->isBytes(compressedObj))) {
		compressed = ((char*) null);
		goto l1;
	}
	ptr = ((char*) (interpreterProxy->firstIndexableField(compressedObj)));
	compressed = ((char*) ptr);
l1:	/* end charPointerFor: */;
	if (!(compressed)) {
		interpreterProxy->primitiveFail(); return;
	}
	/* begin stackPositiveIntegerValue: */
	num = interpreterProxy->stackValue(1);
	if ((interpreterProxy->isIntegerValue(num))
	 && (num < 0)) {
		offset = ((sqInt) null);
		goto l2;
	}
	offset = ((sqInt) (interpreterProxy->positive32BitValueOf(num)));
l2:	/* end stackPositiveIntegerValue: */;
	/* begin stackPositiveIntegerValue: */
	num1 = interpreterProxy->stackValue(0);
	if ((interpreterProxy->isIntegerValue(num1))
	 && (num1 < 0)) {
		compressedLength = ((sqInt) null);
		goto l3;
	}
	compressedLength = ((sqInt) (interpreterProxy->positive32BitValueOf(num1)));
l3:	/* end stackPositiveIntegerValue: */;
	status = snappy_validate_compressed_buffer(compressed + offset, compressedLength);
	interpreterProxy->pop((interpreterProxy->methodArgumentCount()) + 1);
	interpreterProxy->pushInteger(status);
}
Esempio n. 4
0
/* This routine gets executed after a call to HG_Trigger and
 * the RPC has completed */
static hg_return_t
snappy_compress_rpc_cb(const struct hg_cb_info *callback_info)
{
    struct snappy_compress_rpc_args *snappy_compress_rpc_args =
            (struct snappy_compress_rpc_args *) callback_info->arg;
    hg_handle_t handle = callback_info->info.forward.handle;

    int *input;
    size_t source_length;

    void *compressed;
    size_t compressed_length;

    int *uncompressed;
    size_t uncompressed_length;

    snappy_compress_out_t snappy_compress_output;
    snappy_status ret;

    /* Get output */
    printf("Received output from target\n");
    HG_Get_output(handle, &snappy_compress_output);

    /* Get Snappy output parameters */
    ret = snappy_compress_output.ret;
    compressed_length = snappy_compress_output.compressed_length;
    compressed = snappy_compress_rpc_args->compressed;
    input = snappy_compress_rpc_args->input;
    source_length = snappy_compress_rpc_args->input_length;

    /* Check ret */
    if (ret != SNAPPY_OK) {
        fprintf(stderr, "Error: snappy_compressed failed with ret %d\n", ret);
    }

    /* The output data is now in the bulk buffer */
    printf("Compressed buffer length is: %zu\n", compressed_length);
    print_buf(5, (int *)compressed);
    if (snappy_validate_compressed_buffer(compressed, compressed_length) == SNAPPY_OK) {
        printf("Compressed buffer validated: compressed successfully\n");
    }

    uncompressed_length = source_length * sizeof(int);
    uncompressed = (int *) malloc(uncompressed_length);

    /* Uncompress data and check uncompressed_length */
    printf("Uncompressing buffer...\n");
    snappy_uncompress(compressed, compressed_length,
            (char *) uncompressed, &uncompressed_length);
    printf("Uncompressed buffer length is: %zu\n", uncompressed_length);
    print_buf(20, uncompressed);

    /* Free output and handles */
    HG_Free_output(handle, &snappy_compress_output);
    HG_Bulk_free(snappy_compress_rpc_args->input_bulk_handle);
    HG_Bulk_free(snappy_compress_rpc_args->compressed_bulk_handle);

    /* Free data */
    free(uncompressed);
    free(compressed);
    free(input);
    free(snappy_compress_rpc_args);

    /* We're done */
    snappy_compress_done_g = HG_TRUE;

    return HG_SUCCESS;
}
Esempio n. 5
0
/*
 * ./test -u uri -r request_size -a total_size
 * uri: /tmp/testenv/testfs
 * request_size: 4096bytes
 * total_size: 409600bytes
 */
int main(int argc, char *argv[]){
    if (log4c_init()) {
        g_message("log4c_init error!");
    }
    GError *error = NULL;
    GOptionContext *context;
    context = g_option_context_new("- hlfs test -");
    g_option_context_add_main_entries(context, entries, NULL);
    g_option_context_set_help_enabled(context, TRUE);
    g_option_group_set_error_hook(g_option_context_get_main_group(context),
            (GOptionErrorFunc)error_func);
    if (!g_option_context_parse(context, &argc, &argv, &error)) {
        g_message("option parsing failed: %s", error->message);
        exit(EXIT_FAILURE);
    }
	g_option_context_free(context);
    g_print("TEST: uri is %s, request size is %d, total size is %d\n", uri, request_size, total_size);
    char *content = (char*)g_malloc0(request_size);
    HLFS_CTRL * ctrl = init_hlfs(uri);
    g_assert(ctrl != NULL);
    uint64_t ret = 0;
    ret = hlfs_open(ctrl,1);
    g_assert(ret == 0);
    g_print("TEST  hlfs open over \n");
	g_print("test hlfs write\n");
	sleep(2);
    int offset = 0;
    while(offset < total_size){
        ret = hlfs_write(ctrl,content,request_size,offset);
        g_assert(ret==request_size);
        offset +=request_size;
        printf("offset:%d\n",offset);
    }
    g_print("TEST  hlfs write over \n");
	g_print("test hlfs read\n");
	sleep(2);
    offset = 0;
    while(offset < total_size){
        ret = hlfs_read(ctrl,content,request_size,offset);
        g_assert(ret==request_size);
        offset +=request_size;
        printf("offset:%d\n",offset);
    }

	g_print("again ------------------------\n");
    offset = 0;
/******************************************************************************************************************************************/



	int fdd;
	int len;
	int rett;
	int i;
	//char read_buf[409600];
	char *contentt = (char*)g_malloc0(40960);

	if((fdd = open("test.c", O_RDONLY )) == -1){
	my_err("open", __LINE__);
	} else {
		g_print("Open file success\n");
	}

	//if(write(fd, write_buf, strlen(write_buf)) != strlen(write_buf)){
	//	my_err("write", __LINE__);
	//}


	if(lseek(fdd, 0, SEEK_END) == -1){
	my_err("lseek", __LINE__);
	}
	if((len = lseek(fdd, 0, SEEK_CUR)) == -1){
		my_err("lseek", __LINE__);
	}
	if((lseek(fdd, 0, SEEK_SET)) == -1){
		my_err("lseek", __LINE__);
	}

	printf("len: %d\n", len);
	if((rett = read(fdd, contentt, len)) < 0){
		my_err("lseek",__LINE__);
	}
	strcpy(content, contentt);
	//for(i = 0; i< len; i ++){
	g_print("%s ", contentt);
	//}
	g_print("\n");


	g_print("/************************************************/");
	if(lseek(fdd, 10, SEEK_END) == -1){
		my_err("lseek", __LINE__);
	}
	
	
	//close (fdd);
/****************************************************************************************************/
 //FILE* srcFile = NULL;

	int srcLength =  lseek(fdd, 0, SEEK_CUR);
	int SNAPPY_OK = 0;
	char* pSrcBuffer =  (char*)g_malloc0(srcLength);
	read(fdd, pSrcBuffer, srcLength);
 	size_t cbOfCompressed = 32+ srcLength + srcLength/6;
  	char* pCompressedBuffer =  (char*)g_malloc0(cbOfCompressed); 
  	if (snappy_compress(pSrcBuffer, srcLength, pCompressedBuffer, &cbOfCompressed) == SNAPPY_OK)
  {
  	 free(pSrcBuffer);
   	pSrcBuffer = NULL;

   	if (snappy_validate_compressed_buffer(pCompressedBuffer, cbOfCompressed) == SNAPPY_OK)
   {
    	size_t cbDecompress = 0;
    	snappy_uncompressed_length(pCompressedBuffer, cbOfCompressed, &cbDecompress);

    	assert(cbDecompress == srcLength);

    	char* pDecompressedBuffer = (char*)g_malloc0(cbDecompress);
    	snappy_uncompress(pCompressedBuffer, cbOfCompressed, pDecompressedBuffer, (size_t*)&cbDecompress);

    	int file;
    	file = open("test1.txt", O_CREAT | O_RDWR );
    //_wfopen_s(&file, _T("123.pdf"), _T("ab"));
	write(file, pDecompressedBuffer, cbDecompress);
    	close(file);

    	free(pDecompressedBuffer);
    	pDecompressedBuffer = NULL;
   }
  }
 

	close (fdd);


/******************************************************************************************************************************************/
 //   while(offset < total_size){
 //       ret = hlfs_write(ctrl,content,request_size,offset);
  //      g_assert(ret==request_size);
  //      offset +=request_size;
  //      printf("offset:%d\n",offset);
  //  }
  //  g_print("TEST  hlfs write over \n");
//	g_print("test hlfs read\n");
//	sleep(2);
  // offset = 0;
   while(offset < len+1){
        ret = hlfs_read(ctrl,content,len,offset);
        g_assert(ret==len);
        offset +=len;
        printf("offset:%d\n",offset);
    }

	g_free(content);
	g_free(contentt);
	ret = hlfs_close(ctrl);
	deinit_hlfs(ctrl);
	g_print("TEST  hlfs test over \n");
	return 0;
}