示例#1
0
文件: plug.c 项目: easymc/easymc
int emc_connect(int plug, ushort mode, const char * ip, const ushort port){
	struct easymc_plug * pg = (struct easymc_plug *)global_get_plug(plug);
	if(!pg){
		errno = ENOPLUG;
		return -1;
	}
	if(pg->ipc_ || pg->tcp_){
		errno = EREBIND;
		return -1;
	}
	if(EMC_PUB == mode)mode = EMC_SUB;
	if(EMC_REP == mode)mode = EMC_REQ;
	pg->mode = mode;
	if(!get_device_tcp_mgr(pg->device)){
		set_device_tcp_mgr(pg->device, create_tcp_mgr(pg->device, get_device_thread(pg->device)));
	}
	if(!get_device_tcp_mgr(pg->device)){
		return -1;
	}
	if(!ip || check_local_machine(inet_addr(ip))){
		pg->ipc_ = create_ipc(inet_addr(ip), port, pg->device, plug, mode, EMC_REMOTE);
		if(!pg->ipc_){
			return -1;
		}
	}else{
		pg->tcp_ = add_tcp(inet_addr(ip), port, mode, EMC_REMOTE, plug, get_device_tcp_mgr(pg->device));
		if(!pg->tcp_){
			delete_tcp(pg->tcp_);
			pg->tcp_ = NULL;
			return -1;
		}
	}
	return 0;
}
示例#2
0
文件: plug.c 项目: easymc/easymc
int emc_bind(int plug, const char * ip, const ushort port){
	struct easymc_plug * pg = (struct easymc_plug *)global_get_plug(plug);
	if(!pg){
		errno = ENOPLUG;
		return -1;
	}
	if(pg->ipc_ || pg->tcp_){
		errno = EREBIND;
		return -1;
	}
	if(!get_device_tcp_mgr(pg->device)){
		set_device_tcp_mgr(pg->device, create_tcp_mgr(pg->device, get_device_thread(pg->device)));
	}
	if(!get_device_tcp_mgr(pg->device)){
		return -1;
	}
	pg->tcp_ = add_tcp(ip?inet_addr(ip):0, port, EMC_NONE, EMC_LOCAL, plug, get_device_tcp_mgr(pg->device));
	if(!pg->tcp_){
		return -1;
	}
	pg->ipc_ = create_ipc(ip?inet_addr(ip):0, port, pg->device, plug, EMC_NONE, EMC_LOCAL);
	if(!pg->ipc_){
		return -1;
	}
	return 0;
}
示例#3
0
static int add_socket(struct configuration* cfg)
{
  switch(cfg->cfg_protocol) {
  case IPPROTO_UDP:
    return add_udp(cfg);
  case IPPROTO_TCP:
    return add_tcp(cfg);
  default:
    printf("Unsupported protocol %d\n", cfg->cfg_protocol);
    exit(-1);
  }
}