2017-10-23 23:03:38 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2017-10-25 17:28:53 +00:00
|
|
|
#include "multiaddr/multiaddr.h"
|
2017-10-23 23:03:38 +00:00
|
|
|
#include "libp2p/net/stream.h"
|
|
|
|
|
|
|
|
struct Stream* libp2p_stream_new() {
|
|
|
|
struct Stream* stream = (struct Stream*) malloc(sizeof(struct Stream));
|
|
|
|
if (stream != NULL) {
|
|
|
|
stream->address = NULL;
|
|
|
|
stream->close = NULL;
|
|
|
|
stream->parent_stream = NULL;
|
|
|
|
stream->peek = NULL;
|
|
|
|
stream->read = NULL;
|
|
|
|
stream->read_raw = NULL;
|
|
|
|
stream->socket_mutex = NULL;
|
|
|
|
stream->stream_context = NULL;
|
|
|
|
stream->write = NULL;
|
|
|
|
}
|
|
|
|
return stream;
|
|
|
|
}
|
|
|
|
|
|
|
|
void libp2p_stream_free(struct Stream* stream) {
|
|
|
|
if (stream != NULL) {
|
2017-10-25 17:28:53 +00:00
|
|
|
if (stream->socket_mutex != NULL) {
|
|
|
|
free(stream->socket_mutex);
|
|
|
|
stream->socket_mutex = NULL;
|
|
|
|
}
|
|
|
|
if (stream->address != NULL) {
|
|
|
|
multiaddress_free(stream->address);
|
|
|
|
stream->address = NULL;
|
|
|
|
}
|
2017-10-23 23:03:38 +00:00
|
|
|
free(stream);
|
|
|
|
}
|
|
|
|
}
|