예제 #1
0
static void
_update_address(struct skynet_context * context, struct master *m, int harbor_id, const char * buffer, size_t sz) {
	if (m->remote_fd[harbor_id] >= 0) {
		close(m->remote_fd[harbor_id]);
		m->remote_fd[harbor_id] = -1;
	}
	free(m->remote_addr[harbor_id]);
	char * addr = malloc(sz+1);
	memcpy(addr, buffer, sz);
	addr[sz] = '\0';
	m->remote_addr[harbor_id] = addr;
	int fd = _connect_to(addr);
	if (fd<0) {
		skynet_error(context, "Can't connect to harbor %d : %s", harbor_id, addr);
		return;
	}
	m->remote_fd[harbor_id] = fd;
	_broadcast(context, m, addr, sz, harbor_id);

	int i;
	for (i=1;i<REMOTE_MAX;i++) {
		if (i == harbor_id)
			continue;
		const char * addr = m->remote_addr[i];
		if (addr == NULL) {
			continue;
		}
		_send_to(fd, addr, strlen(addr), i);
	}
}
예제 #2
0
static void
_broadcast(struct master *m, const char *name, size_t sz, uint32_t handle) {
	int i;
	for (i=1;i<REMOTE_MAX;i++) {
		int fd = m->remote_fd[i];
		if (fd < 0 || m->connected[i]==false)
			continue;
		_send_to(m, i , name, sz, handle);
	}
}
예제 #3
0
static void
on_connected(struct master *m, int id) {
	_broadcast(m, m->remote_addr[id], strlen(m->remote_addr[id]), id);
	m->connected[id] = true;
	int i;
	for (i=1;i<REMOTE_MAX;i++) {
		if (i == id)
			continue;
		const char * addr = m->remote_addr[i];
		if (addr == NULL || m->connected[i] == false) {
			continue;
		}
		_send_to(m, id , addr, strlen(addr), i);
	}
}
예제 #4
0
static void
_broadcast(struct skynet_context * context, struct master *m, const char *name, size_t sz, uint32_t handle) {
	int i;
	for (i=1;i<REMOTE_MAX;i++) {
		int fd = m->remote_fd[i];
		if (fd < 0)
			continue;
		int err = _send_to(fd, name, sz, handle);
		if (err) {
			close(fd);
			fd = _connect_to(m->remote_addr[i]);
			if (fd < 0) {
				m->remote_fd[i] = -1;
				skynet_error(context, "Reconnect to harbor %d : %s faild", i, m->remote_addr[i]);
			}
			else {
				if (_send_to(fd, name, sz, handle)) {
					close(fd);
					m->remote_fd[i] = -1;
				}
			}
		}
	}
}