Exemplo n.º 1
0
static int
lconnect(lua_State *L) {
	size_t sz = 0;
	const char * addr = luaL_checklstring(L,1,&sz);
	char tmp[sz];
	int port;
	const char * host;
	if (lua_isnoneornil(L,2)) {
		const char * sep = strchr(addr,':');
		if (sep == NULL) {
			return luaL_error(L, "Connect to invalid address %s.",addr);
		}
		memcpy(tmp, addr, sep-addr);
		tmp[sep-addr] = '\0';
		host = tmp;
		port = strtoul(sep+1,NULL,10);
	} else {
		host = addr;
		port = luaL_checkinteger(L,2);
	}
	struct skynet_context * ctx = lua_touserdata(L, lua_upvalueindex(1));
	int id = skynet_socket_connect(ctx, host, port);
	lua_pushinteger(L, id);

	return 1;
}
Exemplo n.º 2
0
static int
_connect_to(struct harbor *h, const char *ipaddress, bool blocking)
{
    char * port = strchr(ipaddress, ':');
    if (port == NULL)
    {
        return -1;
    }
    int sz = port - ipaddress;
    char tmp[sz + 1];
    memcpy(tmp, ipaddress, sz);
    tmp[sz] = '\0';

    int portid = strtol(port + 1, NULL, 10);

    skynet_error(h->ctx, "Harbor(%d) connect to %s:%d", h->id, tmp, portid);

    if (blocking)
    {
        return skynet_socket_block_connect(h->ctx, tmp, portid);
    }
    else
    {
        return skynet_socket_connect(h->ctx, tmp, portid);
    }
}
Exemplo n.º 3
0
static int
lconnect(lua_State *L) {
	size_t sz = 0;
	const char * addr = luaL_checklstring(L,1,&sz);
	char tmp[sz];
	int port = 0;
	const char * host = address_port(L, tmp, addr, 2, &port);
	if (port == 0) {
		return luaL_error(L, "Invalid port");
	}
	struct skynet_context * ctx = lua_touserdata(L, lua_upvalueindex(1));
	int id = skynet_socket_connect(ctx, host, port);
	lua_pushinteger(L, id);

	return 1;
}
Exemplo n.º 4
0
static void
_connect_to(struct master *m, int id) {
	assert(m->connected[id] == false);
	struct skynet_context * ctx = m->ctx;
	const char *ipaddress = m->remote_addr[id];
	char * portstr = strchr(ipaddress,':');
	if (portstr==NULL) {
		skynet_error(ctx, "Harbor %d : address invalid (%s)",id, ipaddress);
		return;
	}
	int sz = portstr - ipaddress;
	char tmp[sz + 1];
	memcpy(tmp,ipaddress,sz);
	tmp[sz] = '\0';
	int port = strtol(portstr+1,NULL,10);
	m->remote_fd[id] = skynet_socket_connect(ctx, tmp, port);
}