Exemplo n.º 1
0
struct sio_rpc_server *sio_rpc_server_new(struct sio_rpc *rpc, const char *ip, uint16_t port)
{
    struct sio_stream *stream = sio_stream_listen(rpc->sio, ip, port, _sio_rpc_dstream_callback, NULL);
    if (!stream)
        return NULL;

    struct sio_rpc_server *server = malloc(sizeof(*server));
    server->conn_id = 0;
    server->rpc = rpc;
    server->stream = stream;
    server->dstreams = shash_new();
    server->methods = shash_new();
    sio_stream_set(rpc->sio, stream, _sio_rpc_dstream_callback, server);
    return server;
}
Exemplo n.º 2
0
fwd_policy_loct_parm *
policy_loct_parm_new(lisp_addr_t *rloc_addr)
{
    fwd_policy_loct_parm *pol_loct = xzalloc(sizeof(fwd_policy_loct_parm));
	pol_loct->rloc_addr = lisp_addr_clone(rloc_addr);
	pol_loct->paramiters = shash_new();
	return (pol_loct);
}
Exemplo n.º 3
0
fwd_policy_map_parm *
policy_map_parm_new(lisp_addr_t *eid_prefix)
{
    fwd_policy_map_parm *pol_map = xzalloc(sizeof(fwd_policy_map_parm));
	pol_map->eid_prefix = lisp_addr_clone(eid_prefix);
	pol_map->paramiters = shash_new();
	pol_map->locators = glist_new_managed((glist_del_fct)policy_loct_parm_del);

	return (pol_map);
}
Exemplo n.º 4
0
struct sio_rpc_client *sio_rpc_client_new(struct sio_rpc *rpc)
{
    struct sio_rpc_client *client = malloc(sizeof(*client));
    client->rpc = rpc;
    client->rr_stream = 0;
    client->upstream_count = 0;
    client->upstreams = NULL;
    assert(client->req_record = shash_new()); /* 所有运行中的rpc request地址都记录, 以便client_free时回收  */
    return client;
}
Exemplo n.º 5
0
void sio_rpc_add_upstream(struct sio_rpc_client *client, const char *ip, uint16_t port)
{
    uint32_t i;
    for (i = 0; i < client->upstream_count; ++i) {
        if (strcmp(client->upstreams[i]->ip, ip) == 0 && client->upstreams[i]->port == port)
            return;
    }

    struct sio_rpc_upstream *upstream = malloc(sizeof(*upstream));
    upstream->ip = strdup(ip);
    upstream->port = port;
    upstream->req_id = 0;
    upstream->conn_delay = 1; /* 最小延迟1秒重连 */
    upstream->last_conn_time = time(NULL);
    upstream->client = client;
    upstream->req_status = shash_new();
    _sio_rpc_upstream_connect(client->rpc->sio, upstream);

    sio_start_timer(client->rpc->sio, &upstream->timer, 1000, _sio_rpc_upstream_timer, upstream);

    client->upstreams = realloc(client->upstreams, ++client->upstream_count * sizeof(*client->upstreams));
    client->upstreams[client->upstream_count - 1] = upstream;
}