int network_close(struct network *net, const char *addr, uint16_t port) { endpoint_array_t *ep_array = map_get(&net->endpoints, addr); if (ep_array == NULL) { return kr_error(ENOENT); } /* Close endpoint in array. */ for (size_t i = ep_array->len; i--;) { struct endpoint *ep = ep_array->at[i]; if (ep->port == port) { close_endpoint(ep); array_del(*ep_array, i); break; } } /* Collapse key if it has no endpoint. */ if (ep_array->len == 0) { free(ep_array); map_del(&net->endpoints, addr); } return kr_ok(); }
int network_listen(struct network *net, const char *addr, uint16_t port, uint32_t flags) { if (net == NULL || addr == 0 || port == 0) { return kr_error(EINVAL); } /* Parse address. */ int ret = 0; struct sockaddr_storage sa; if (strchr(addr, ':') != NULL) { ret = uv_ip6_addr(addr, port, (struct sockaddr_in6 *)&sa); } else { ret = uv_ip4_addr(addr, port, (struct sockaddr_in *)&sa); } if (ret != 0) { return ret; } /* Bind interfaces */ struct endpoint *ep = malloc(sizeof(*ep)); memset(ep, 0, sizeof(*ep)); ep->flags = NET_DOWN; ep->port = port; ret = open_endpoint(net, ep, (struct sockaddr *)&sa, flags); if (ret == 0) { ret = insert_endpoint(net, addr, ep); } if (ret != 0) { close_endpoint(ep); } return ret; }
static void audio_close_output_stream(struct audio_hw_device *dev, struct audio_stream_out *stream) { struct a2dp_audio_dev *a2dp_dev = (struct a2dp_audio_dev *) dev; struct a2dp_stream_out *out = (struct a2dp_stream_out *) stream; DBG(""); close_endpoint(a2dp_dev->out->ep); free(out->downmix_buf); free(stream); a2dp_dev->out = NULL; }