コード例 #1
0
ファイル: tcp.c プロジェクト: allisonmobley/frozen
static int tcp_configure(machine_t *machine, hash_t *config){ // {{{
	ssize_t                ret;
	tcp_userdata          *userdata          = (tcp_userdata *)machine->userdata;
	
	hash_data_convert(ret, TYPE_STRINGT, userdata->tcp_addr, config, HK(addr));
	hash_data_get    (ret, TYPE_UINTT,   userdata->tcp_port, config, HK(port));
	hash_data_get    (ret, TYPE_HASHT,   userdata->machine,  config, HK(machine));
	
	tcp_control_start(machine);
	return 0;
} // }}}
コード例 #2
0
ファイル: main_gzip.c プロジェクト: x86-64/frozen-gzip
static ssize_t gzip_new(gzip_t **pfdata, config_t *config){ // {{{
	ssize_t                ret;
	char                  *filepath;
	gzip_t                *fdata;
	
	hash_data_convert(ret, TYPE_STRINGT, filepath, config, HK(filename));
	if(ret != 0)
		return error("filename not supplied");
	
	fdata = seekgzip_open(filepath, 0);
	if( (ret = seekgzip_error(fdata)) != SEEKGZIP_SUCCESS)
		return error("seekgzip_open failed");
	
	*pfdata = fdata;
	return 0;
} // }}}
コード例 #3
0
ファイル: pcre.c プロジェクト: samuell/frozen
static ssize_t pcre_t_new(pcre_t **pfdata, config_t *config){ // {{{
	ssize_t                ret;
	char                  *cfg_regexp        = NULL;
	int                    options           = 0;
	int                    erroffset;
	const char            *errmsg;
	pcre_t                *fdata;
	
	if( (fdata = calloc(1, sizeof(pcre_t))) == NULL)
		return error("calloc returns null");
	
	hash_data_convert(ret, TYPE_STRINGT, cfg_regexp, config, HDK(regexp));
	if(ret != 0){
		ret = error("regexp not supplied");
		goto error;
	}
	
	if( (fdata->re = pcre_compile(
		cfg_regexp,
		options,
		&errmsg,
		&erroffset,
		NULL)) == NULL
	){
		ret = error("regexp compile failed");
		goto error;
	}
	
	fdata->options = 0;
	fdata->data    = NULL;
	data_set_void(&fdata->freeit);
	
	*pfdata = fdata;
	free(cfg_regexp);
	return 0;
	
error:
	free(fdata);
	return ret;
} // }}}
コード例 #4
0
ファイル: ipc_shmem.c プロジェクト: shalstvedt/frozen
ssize_t ipc_shmem_init    (ipc_t *ipc, config_t *config){ // {{{
	ssize_t                ret;
	int                    shmid;
	uint32_t               shmkey;
	size_t                 shmsize;
	size_t                 nitems            = NITEMS_DEFAULT;
	size_t                 item_size         = ITEM_SIZE_DEFAULT;
	uintmax_t              f_async           = 0;
	uintmax_t              f_sync            = 0;
	char                  *role_str          = NULL;
	ipc_shmem_userdata    *userdata          = (ipc_shmem_userdata *)ipc->userdata;
	
	userdata->buffer        = HK(buffer);
	userdata->return_result = 1;
	
	hash_data_get(ret, TYPE_UINT32T, shmkey,     config, HK(key));  if(ret != 0) return error("no key supplied");
	hash_data_convert(ret, TYPE_STRINGT, role_str,   config, HK(role)); if(ret != 0) return error("no role supplied");
	hash_data_get(ret, TYPE_SIZET,   item_size,  config, HK(item_size));
	hash_data_get(ret, TYPE_SIZET,   nitems,     config, HK(size));
	hash_data_get(ret, TYPE_UINTT,   f_async,    config, HK(force_async));
	hash_data_get(ret, TYPE_UINTT,   f_sync,     config, HK(force_sync));
	hash_data_get(ret, TYPE_HASHKEYT, userdata->buffer,   config, HK(buffer));
	hash_data_get(ret, TYPE_UINTT,    userdata->return_result, config, HK(return_result));
	
	if( (userdata->role = ipc_string_to_role(role_str)) == ROLE_INVALID)
		return error("invalid role supplied");
	
	free(role_str);
	
	shmsize = nitems * sizeof(ipc_shmem_block) + nitems * item_size + sizeof(ipc_shmem_header); 
	
	if( (shmid = shmget(shmkey, shmsize, IPC_CREAT | 0666)) < 0)
		return error("shmget failed");
	
	if( (userdata->shmaddr = shmat(shmid, NULL, 0)) == (void *)-1)
		return error("shmat failed");
	
	if( (f_async != 0 && f_sync != 0) )
		return error("force_async with force_sync");
	
	userdata->shmblocks = (ipc_shmem_block *)((void *)userdata->shmaddr   + sizeof(ipc_shmem_header));
	userdata->shmdata   = (void *)           ((void *)userdata->shmblocks + nitems * sizeof(ipc_shmem_block));
	userdata->inited    = 1;
	
	userdata->forced_state = FORCE_NONE;
	if(f_async != 0) userdata->forced_state = FORCE_ASYNC;
	if(f_sync  != 0) userdata->forced_state = FORCE_SYNC;
	
	if(userdata->role == ROLE_SERVER){
		userdata->shmaddr->item_size = item_size;
		userdata->shmaddr->nitems    = nitems;
		
		if(shmem_init(userdata) != 0)
			return error("shmem_init failed");
		
		// start threads
		if(pthread_create(&userdata->server_thr, NULL, &ipc_shmem_listen, ipc) != 0)
			return error("pthread_create failed");
	}
	return 0;
} // }}}