Ejemplo n.º 1
0
void uct_node_free_except(UCTNode * self, UCTNode * subtree) {
    if(self->child && self->child != subtree)
        uct_node_free_except(self->child, subtree);
    if(self->next && self->next != subtree)
        uct_node_free_except(self->next, subtree);
    arena_dealloc(UCT_NODE_ARENA, (void *) self);
}
Ejemplo n.º 2
0
nsapi_error_t LWIP::socket_open(nsapi_socket_t *handle, nsapi_protocol_t proto)
{
    // check if network is connected
//    if (lwip_connected == NSAPI_STATUS_DISCONNECTED) {
//        return NSAPI_ERROR_NO_CONNECTION;
//    }

    // allocate a socket
    struct mbed_lwip_socket *s = arena_alloc();
    if (!s) {
        return NSAPI_ERROR_NO_SOCKET;
    }

    enum netconn_type lwip_proto = proto == NSAPI_TCP ? NETCONN_TCP : NETCONN_UDP;

#if LWIP_IPV6
    // Enable IPv6 (or dual-stack)
    lwip_proto = (enum netconn_type)(lwip_proto | NETCONN_TYPE_IPV6);
#endif

    s->conn = netconn_new_with_callback(lwip_proto, &LWIP::socket_callback);

    if (!s->conn) {
        arena_dealloc(s);
        return NSAPI_ERROR_NO_SOCKET;
    }

    netconn_set_recvtimeout(s->conn, 1);
    *(struct mbed_lwip_socket **)handle = s;
    return 0;
}
Ejemplo n.º 3
0
nsapi_error_t LWIP::socket_close(nsapi_socket_t handle)
{
    struct mbed_lwip_socket *s = (struct mbed_lwip_socket *)handle;

    netbuf_delete(s->buf);
    err_t err = netconn_delete(s->conn);
    arena_dealloc(s);
    return err_remap(err);
}
Ejemplo n.º 4
0
nsapi_error_t LWIP::socket_accept(nsapi_socket_t server, nsapi_socket_t *handle, SocketAddress *address)
{
#if LWIP_TCP
    struct mbed_lwip_socket *s = (struct mbed_lwip_socket *)server;
    struct mbed_lwip_socket *ns = arena_alloc();
    if (!ns) {
        return NSAPI_ERROR_NO_SOCKET;
    }

    if (s->conn->pcb.tcp->state != LISTEN) {
        return NSAPI_ERROR_PARAMETER;
    }

    err_t err = netconn_accept(s->conn, &ns->conn);
    if (err != ERR_OK) {
        arena_dealloc(ns);
        return err_remap(err);
    }

    netconn_set_recvtimeout(ns->conn, 1);
    *(struct mbed_lwip_socket **)handle = ns;

    ip_addr_t peer_addr;
    nsapi_addr_t addr;
    u16_t port;
    (void) netconn_peer(ns->conn, &peer_addr, &port);
    convert_lwip_addr_to_mbed(&addr, &peer_addr);

    if (address) {
        address->set_addr(addr);
        address->set_port(port);
    }

    netconn_set_nonblocking(ns->conn, true);

    return 0;
#else
    return NSAPI_ERROR_UNSUPPORTED;
#endif
}
Ejemplo n.º 5
0
void uct_node_free(UCTNode * self) {
    if(self->child) uct_node_free(self->child);
    if(self->next) uct_node_free(self->next);
    arena_dealloc(UCT_NODE_ARENA, (void *) self);
}