int kr_ogg_io_destroy(kr_ogg_io **ogg_io) { if ((ogg_io != NULL) && (*ogg_io != NULL)) { if ((*ogg_io)->wrote_header == 1) { kr_ogg_io_eos_track((*ogg_io), 0); } kr_io2_destroy (&(*ogg_io)->io); if ((*ogg_io)->file != NULL) { kr_file_close (&(*ogg_io)->file); } if ((*ogg_io)->stream != NULL) { kr_stream_destroy (&(*ogg_io)->stream); } /* if ((*mkv)->transmission != NULL) { kr_transmission_destroy ((*mkv)->transmission); (*mkv)->transmission = NULL; } */ kr_ogg_destroy (&(*ogg_io)->ogg); free (*ogg_io); *ogg_io = NULL; return 0; } return -1; }
static krad_stream_t *kr_stream_connect (char *host, int port) { krad_stream_t *stream; int ret; int flags; char port_string[6]; struct in6_addr serveraddr; struct addrinfo hints; struct addrinfo *res; res = NULL; if ((host == NULL) || ((port < 0) || (port > 65535))) { return NULL; } stream = calloc (1, sizeof(krad_stream_t)); memset (&hints, 0, sizeof(hints)); hints.ai_flags = AI_NUMERICSERV; hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; ret = inet_pton (AF_INET, host, &serveraddr); if (ret == 1) { hints.ai_family = AF_INET; hints.ai_flags |= AI_NUMERICHOST; } else { ret = inet_pton (AF_INET6, host, &serveraddr); if (ret == 1) { hints.ai_family = AF_INET6; hints.ai_flags |= AI_NUMERICHOST; } } snprintf (port_string, 6, "%d", port); ret = getaddrinfo (host, port_string, &hints, &res); if (ret != 0) { kr_stream_destroy (&stream); return NULL; } stream->sd = socket (res->ai_family, res->ai_socktype, res->ai_protocol); if (stream->sd < 0) { kr_stream_destroy (&stream); } else { flags = fcntl (stream->sd, F_GETFL, 0); if (flags == -1) { failfast ("Krad System: error on syscall fcntl F_GETFL"); } else { flags |= O_NONBLOCK; ret = fcntl (stream->sd, F_SETFL, flags); if (ret == -1) { failfast ("Krad System: error on syscall fcntl F_SETFL"); } else { ret = connect (stream->sd, res->ai_addr, res->ai_addrlen); if ((ret < 0) && (errno != EINPROGRESS)) { kr_stream_destroy (&stream); } } } } if (res != NULL) { freeaddrinfo (res); } return stream; }