• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ HASH_ID函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中HASH_ID函数的典型用法代码示例。如果您正苦于以下问题:C++ HASH_ID函数的具体用法?C++ HASH_ID怎么用?C++ HASH_ID使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了HASH_ID函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: start_socket

// 启动socket,加入事件循环
// 成功时返回SOCKET_OPEN
static int
start_socket(struct socket_server *ss, struct request_start *request, struct socket_message *result) {
	int id = request->id;
	result->id = id;
	result->opaque = request->opaque;
	result->ud = 0;
	result->data = NULL;
	struct socket *s = &ss->slot[HASH_ID(id)];
	if (s->type == SOCKET_TYPE_INVALID || s->id !=id) {
		result->data = "invalid socket";
		return SOCKET_ERROR;
	}
	if (s->type == SOCKET_TYPE_PACCEPT || s->type == SOCKET_TYPE_PLISTEN) {
		// 套接字加入事件循环
		if (sp_add(ss->event_fd, s->fd, s)) {
			force_close(ss, s, result);
			result->data = strerror(errno);
			return SOCKET_ERROR;
		}
		// SOCKET_TYPE_PACCEPT -> SOCKET_TYPE_CONNECTED
		// SOCKET_TYPE_PLISTEN -> SOCKET_TYPE_LISTEN
		s->type = (s->type == SOCKET_TYPE_PACCEPT) ? SOCKET_TYPE_CONNECTED : SOCKET_TYPE_LISTEN;
		s->opaque = request->opaque;
		result->data = "start";
		return SOCKET_OPEN;
	} else if (s->type == SOCKET_TYPE_CONNECTED) {
		// todo: maybe we should send a message SOCKET_TRANSFER to s->opaque
		s->opaque = request->opaque;
		result->data = "transfer";
		return SOCKET_OPEN;
	}
	// if s->type == SOCKET_TYPE_HALFCLOSE , SOCKET_CLOSE message will send later
	return -1;
}
开发者ID:puXiaoyi,项目名称:skynet,代码行数:36,代码来源:socket_server.c


示例2: socket_server_udp_send

int64_t 
socket_server_udp_send(struct socket_server *ss, int id, const struct socket_udp_address *addr, const void *buffer, int sz) {
	struct socket * s = &ss->slot[HASH_ID(id)];
	if (s->id != id || s->type == SOCKET_TYPE_INVALID) {
		free_buffer(ss, buffer, sz);
		return -1;
	}

	struct request_package request;
	request.u.send_udp.send.id = id;
	request.u.send_udp.send.sz = sz;
	request.u.send_udp.send.buffer = (char *)buffer;

	const uint8_t *udp_address = (const uint8_t *)addr;
	int addrsz;
	switch (udp_address[0]) {
	case PROTOCOL_UDP:
		addrsz = 1+2+4;		// 1 type, 2 port, 4 ipv4
		break;
	case PROTOCOL_UDPv6:
		addrsz = 1+2+16;	// 1 type, 2 port, 16 ipv6
		break;
	default:
		free_buffer(ss, buffer, sz);
		return -1;
	}

	memcpy(request.u.send_udp.address, udp_address, addrsz);	

	send_request(ss, &request, 'A', sizeof(request.u.send_udp.send)+addrsz);
	return s->wb_size;
}
开发者ID:puXiaoyi,项目名称:skynet,代码行数:32,代码来源:socket_server.c


示例3: new_fd

// 创建新的socket实例
// id,通过reserve_id分配的alloc_id
// fd, 通过socket创建的套接字
// add, true则加入事件循环
static struct socket *
new_fd(struct socket_server *ss, int id, int fd, int protocol, uintptr_t opaque, bool add) {
	struct socket * s = &ss->slot[HASH_ID(id)];
	// 正常情况下,socket已在reserve_id中赋值为保留类型
	assert(s->type == SOCKET_TYPE_RESERVE);

	if (add) {
		// 加入事件循环
		if (sp_add(ss->event_fd, fd, s)) {
			// 如果加入失败,socket重置为初始类型	
			s->type = SOCKET_TYPE_INVALID;
			return NULL;
		}
	}

	// 初始化变量
	s->id = id;
	s->fd = fd;
	s->protocol = protocol;
	s->p.size = MIN_READ_BUFFER;
	s->opaque = opaque;
	s->wb_size = 0;
	check_wb_list(&s->high);
	check_wb_list(&s->low);
	return s;
}
开发者ID:puXiaoyi,项目名称:skynet,代码行数:30,代码来源:socket_server.c


示例4: socket_req_start

static int socket_req_start(struct _start_req *req, struct socket_message *msg) {
	struct socket *sock;
	msg->id = req->id;
	msg->ud = req->ud;
	sock = &S.slot[HASH_ID(req->id)];
	if (sock->type == SOCKET_TYPE_INVALID || sock->id != req->id) {
		msg->data = "socket invalid id";
		return SOCKET_ERR;
	}
	if (sock->type == SOCKET_TYPE_PACCEPT || sock->type == SOCKET_TYPE_PLISTEN) {
		if (event_add(S.event_fd, sock->fd, sock)) {
			sock->type = SOCKET_TYPE_INVALID;
			msg->data = strerror(errno);		
			return SOCKET_ERR;
		}
		sock->type = (sock->type == SOCKET_TYPE_PACCEPT) ? SOCKET_TYPE_OPENED : SOCKET_TYPE_LISTEN;
		sock->ud = req->ud;
		msg->data = "start";
		return SOCKET_OPEN;
	} else if (sock->type == SOCKET_TYPE_OPENED) {
		sock->ud = req->ud;
		msg->data = "transfer";
		return SOCKET_OPEN;
	}
	return -1;
}
开发者ID:zhoukk,项目名称:routine,代码行数:26,代码来源:socket.c


示例5: reserve_id

// 递增分配id进行hash,并返回匹配的socket
static int
reserve_id(struct socket_server *ss) {
	int i;
	for (i=0;i<MAX_SOCKET;i++) {
		// 递增
		int id = ATOM_INC(&(ss->alloc_id));
		if (id < 0) {
			// 回绕
			id = ATOM_AND(&(ss->alloc_id), 0x7fffffff);
		}
		// 哈希匹配
		struct socket *s = &ss->slot[HASH_ID(id)];
		if (s->type == SOCKET_TYPE_INVALID) {
			// 如果是初始类型,修改为保留类型
			if (ATOM_CAS(&s->type, SOCKET_TYPE_INVALID, SOCKET_TYPE_RESERVE)) {
				s->id = id;
				s->fd = -1;
				return id;
			} else {
				// 否则,重试
				// retry
				--i;
			}
		}
	}
	return -1;
}
开发者ID:puXiaoyi,项目名称:skynet,代码行数:28,代码来源:socket_server.c


示例6: socket_udpsend

long socket_udpsend(int id, const struct socket_udp_address *address, const void *data, int size) {
	const uint8_t *udp_address;
	int addrsize;
	struct socket_req req;
	struct socket * sock = &S.slot[HASH_ID(id)];
	if (sock->id != id || sock->type == SOCKET_TYPE_INVALID) {
		freebuffer((void *)data, size);
		return -1;
	}
	memset(&req, 0, sizeof req);
	req.req = SOCKET_REQ_SENDUDP;
	req.u.send.id = id;
	req.u.send.data = (char *)data;
	req.u.send.size = size;
	udp_address = (const uint8_t *)address;
	switch (udp_address[0]) {
	case PROTOCOL_UDP:
		addrsize = 1 + 2 + 4;
		break;
	case PROTOCOL_UDPv6:
		addrsize = 1 + 2 + 16;
		break;
	default:
		freebuffer((void *)data, size);
		return -1;
	}
	memcpy(req.u.sendudp.address, udp_address, addrsize);
	socket_send_req(&req);
	return sock->wb_size;
}
开发者ID:zhoukk,项目名称:routine,代码行数:30,代码来源:socket.c


示例7: close_socket

static int
close_socket(struct socket_server *ss, struct request_close *request, struct socket_message *result) {
	int id = request->id;
	struct socket * s = &ss->slot[HASH_ID(id)];
	if (s->type == SOCKET_TYPE_INVALID || s->id != id) {
		result->id = id;
		result->opaque = request->opaque;
		result->ud = 0;
		result->data = NULL;
		return SOCKET_CLOSE;
	}
	if (!send_buffer_empty(s)) { 
		int type = send_buffer(ss,s,result);
		if (type != -1)
			return type;
	}
	if (send_buffer_empty(s)) {
		force_close(ss,s,result);
		result->id = id;
		result->opaque = request->opaque;
		return SOCKET_CLOSE;
	}
	s->type = SOCKET_TYPE_HALFCLOSE;

	return -1;
}
开发者ID:Lvshen,项目名称:company_coc,代码行数:26,代码来源:socket_server.c


示例8: start_socket

static int
start_socket(struct socket_server *ss, struct request_start *request, struct socket_message *result) {
	int id = request->id;
	result->id = id;
	result->opaque = request->opaque;
	result->ud = 0;
	result->data = NULL;
	struct socket *s = &ss->slot[HASH_ID(id)];
	if (s->type == SOCKET_TYPE_INVALID || s->id !=id) {
		return SOCKET_ERROR;
	}
	if (s->type == SOCKET_TYPE_PACCEPT || s->type == SOCKET_TYPE_PLISTEN) {
		if (sp_add(ss->event_fd, s->fd, s)) {
			s->type = SOCKET_TYPE_INVALID;
			return SOCKET_ERROR;
		}
		s->type = (s->type == SOCKET_TYPE_PACCEPT) ? SOCKET_TYPE_CONNECTED : SOCKET_TYPE_LISTEN;
		s->opaque = request->opaque;
		result->data = "start";
		return SOCKET_OPEN;
	} else if (s->type == SOCKET_TYPE_CONNECTED) {
		s->opaque = request->opaque;
		result->data = "transfer";
		return SOCKET_OPEN;
	}
	return -1;
}
开发者ID:Lvshen,项目名称:company_coc,代码行数:27,代码来源:socket_server.c


示例9: socket_req_opt

static int socket_req_opt(struct _opt_req *req, struct socket_message *msg) {
	struct socket *sock;
	sock = &S.slot[HASH_ID(req->id)];
	if (sock->type == SOCKET_TYPE_INVALID || sock->id != req->id) {
		return -1;
	}
	setsockopt(sock->fd, IPPROTO_TCP, req->what, (const char *)&req->value, sizeof(req->value));
	return -1;
}
开发者ID:zhoukk,项目名称:routine,代码行数:9,代码来源:socket.c


示例10: setopt_socket

static void
setopt_socket(struct socket_server *ss, struct request_setopt *request) {
	int id = request->id;
	struct socket *s = &ss->slot[HASH_ID(id)];
	if (s->type == SOCKET_TYPE_INVALID || s->id !=id) {
		return;
	}
	int v = request->value;
	setsockopt(s->fd, IPPROTO_TCP, request->what, &v, sizeof(v));
}
开发者ID:Lvshen,项目名称:company_coc,代码行数:10,代码来源:socket_server.c


示例11: socket_server_send_lowpriority

void 
socket_server_send_lowpriority(struct socket_server *ss, int id, const void * buffer, int sz) {
	struct socket * s = &ss->slot[HASH_ID(id)];
	if (s->id != id || s->type == SOCKET_TYPE_INVALID) {
		return;
	}

	struct request_package request;
	request.u.send.id = id;
	request.u.send.sz = sz;
	request.u.send.buffer = (char *)buffer;

	send_request(ss, &request, 'P', sizeof(request.u.send));
}
开发者ID:Lvshen,项目名称:company_coc,代码行数:14,代码来源:socket_server.c


示例12: socket_req_listen

static int socket_req_listen(struct _listen_req *req, struct socket_message *msg) {
	struct socket *sock = socket_new(req->fd, req->id, PROTOCOL_TCP, req->ud, 0);
	if (sock == 0) {
		goto _failed;
	}
	sock->type = SOCKET_TYPE_PLISTEN;
	return -1;
_failed:
	close(req->fd);
	msg->ud = req->ud;
	msg->id = req->id;
	msg->data = "socket limit";
	S.slot[HASH_ID(req->id)].type = SOCKET_TYPE_INVALID;
	return SOCKET_ERR;
}
开发者ID:zhoukk,项目名称:routine,代码行数:15,代码来源:socket.c


示例13: socket_server_send

// return -1 when error
// send_socket HIGH
int64_t 
socket_server_send(struct socket_server *ss, int id, const void * buffer, int sz) {
	struct socket * s = &ss->slot[HASH_ID(id)];
	if (s->id != id || s->type == SOCKET_TYPE_INVALID) {
		free_buffer(ss, buffer, sz);
		return -1;
	}

	struct request_package request;
	request.u.send.id = id;
	request.u.send.sz = sz;
	request.u.send.buffer = (char *)buffer;

	send_request(ss, &request, 'D', sizeof(request.u.send));
	return s->wb_size;
}
开发者ID:puXiaoyi,项目名称:skynet,代码行数:18,代码来源:socket_server.c


示例14: socket_send

long socket_send(int id, const void *data, int size, int priority) {
	struct socket_req req;
	struct socket * sock = &S.slot[HASH_ID(id)];
	if (sock->id != id || sock->type == SOCKET_TYPE_INVALID) {
		freebuffer((void *)data, size);
		return -1;
	}
	memset(&req, 0, sizeof req);
	req.req = SOCKET_REQ_SEND;
	req.u.send.id = id;
	req.u.send.data = (char *)data;
	req.u.send.size = size;
	req.u.send.priority = priority;
	socket_send_req(&req);
	return sock->wb_size;
}
开发者ID:zhoukk,项目名称:routine,代码行数:16,代码来源:socket.c


示例15: add_udp_socket

static void
add_udp_socket(struct socket_server *ss, struct request_udp *udp) {
    int id = udp->id;
    int protocol;
    if (udp->family == AF_INET6) {
        protocol = PROTOCOL_UDPv6;
    } else {
        protocol = PROTOCOL_UDP;
    }
    struct socket *ns = new_fd(ss, id, udp->fd, protocol, udp->opaque, true);
    if (ns == NULL) {
        close(udp->fd);
        ss->slot[HASH_ID(id)].type = SOCKET_TYPE_INVALID;
        return;
    }
    ns->type = SOCKET_TYPE_CONNECTED;
    memset(ns->p.udp_address, 0, sizeof(ns->p.udp_address));
}
开发者ID:bye-Tyrael,项目名称:skynet,代码行数:18,代码来源:socket_server.c


示例16: socket_req_udp

static int socket_req_udp(struct _udp_req *req, struct socket_message *msg) {
	int id = req->id;
	int protocol;
	struct socket *sock;
	if (req->family == AF_INET6) {
		protocol = PROTOCOL_UDPv6;
	} else {
		protocol = PROTOCOL_UDP;
	}
	sock = socket_new(req->fd, id, protocol, req->ud, 1);
	if (!sock) {
		close(req->fd);
		S.slot[HASH_ID(id)].type = SOCKET_TYPE_INVALID;
		return -1;
	}
	sock->type = SOCKET_TYPE_OPENED;
	memset(sock->p.udp_address, 0, sizeof(sock->p.udp_address));
	return -1;
}
开发者ID:zhoukk,项目名称:routine,代码行数:19,代码来源:socket.c


示例17: new_socket

int socket_server::listen_socket(struct request_listen * request, struct socket_message * result)
{
    int id = request->id;
    int listen_fd = request->fd;
    struct socket * s = new_socket(id, listen_fd, PROTOCOL_TCP, request->opaque, false);
    if (s == nullptr) {
        goto _failed;
    }
    s->type = SOCKET_TYPE_PLISTEN;
    return -1;
_failed:
    close(listen_fd);
    result->opaque = request->opaque;
    result->id = id;
    result->ud = 0;
    result->data = nullptr;
    slot[HASH_ID(id)].type = SOCKET_TYPE_INVALID;
     
    return SOCKET_ERROR;
}
开发者ID:apppur,项目名称:canna,代码行数:20,代码来源:socket_server.cpp


示例18: socket_next_id

static int socket_next_id(void) {
	int i;
	for (i = 0; i < MAX_SOCKET; i++) {
		struct socket *sock;
		int id = atom_inc(&(S.next_id));
		if (id < 0) {
			id = atom_and(&(S.next_id), 0x7fffffff);
		}
		sock = &S.slot[HASH_ID(id)];
		if (sock->type == SOCKET_TYPE_INVALID) {
			if (atom_cas(&(sock->type), SOCKET_TYPE_INVALID, SOCKET_TYPE_RESERVE)) {
				sock->id = id;
				sock->fd = -1;
				return id;
			}
			--i;
		}
	}
	return -1;
}
开发者ID:zhoukk,项目名称:routine,代码行数:20,代码来源:socket.c


示例19: assert

struct socket * socket_server::new_socket(int id, int fd, int protocol, uintptr_t opaque, bool add)
{
    struct socket * s = &slot[HASH_ID(id)];
    assert(s->type == SOCKET_TYPE_RESERVE);

    if (add) {
        if (event_fd.add(fd, s)) {
            s->type = SOCKET_TYPE_INVALID;
            return nullptr;
        }
    }

    s->id = id;
    s->fd = fd;
    s->protocol = protocol;

    s->opaque = opaque;

    return s;
}
开发者ID:apppur,项目名称:canna,代码行数:20,代码来源:socket_server.cpp


示例20: listen_socket

static int
listen_socket(struct socket_server *ss, struct request_listen * request, struct socket_message *result) {
	int id = request->id;
	int listen_fd = request->fd;
	struct socket *s = new_fd(ss, id, listen_fd, request->opaque, false);
	if (s == NULL) {
		goto _failed;
	}
	s->type = SOCKET_TYPE_PLISTEN;
	return -1;
_failed:
	close(listen_fd);
	result->opaque = request->opaque;
	result->id = id;
	result->ud = 0;
	result->data = NULL;
	ss->slot[HASH_ID(id)].type = SOCKET_TYPE_INVALID;

	return SOCKET_ERROR;
}
开发者ID:Lvshen,项目名称:company_coc,代码行数:20,代码来源:socket_server.c



注:本文中的HASH_ID函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ HASH_OF函数代码示例发布时间:2022-05-30
下一篇:
C++ HASH_FIND_STR函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap