Added Transport close method
diff --git a/ndn-cpp/c/transport/SocketTransport.c b/ndn-cpp/c/transport/SocketTransport.c
index 187f0da..ee1f72a 100644
--- a/ndn-cpp/c/transport/SocketTransport.c
+++ b/ndn-cpp/c/transport/SocketTransport.c
@@ -98,3 +98,17 @@
return 0;
}
+
+ndn_Error ndn_SocketTransport_close(struct ndn_SocketTransport *self)
+{
+ if (self->socketDescriptor < 0)
+ // Already closed. Do nothing.
+ return 0;
+
+ if (close(self->socketDescriptor) != 0)
+ return NDN_ERROR_SocketTransport_error_in_close;
+
+ self->socketDescriptor = -1;
+
+ return 0;
+}
diff --git a/ndn-cpp/c/transport/SocketTransport.h b/ndn-cpp/c/transport/SocketTransport.h
index a5e89f7..6973d19 100644
--- a/ndn-cpp/c/transport/SocketTransport.h
+++ b/ndn-cpp/c/transport/SocketTransport.h
@@ -34,6 +34,8 @@
ndn_Error ndn_SocketTransport_receive
(struct ndn_SocketTransport *self, unsigned char *buffer, unsigned int bufferLength, unsigned int *nBytes);
+ndn_Error ndn_SocketTransport_close(struct ndn_SocketTransport *self);
+
#ifdef __cplusplus
}
#endif
diff --git a/ndn-cpp/c/transport/TcpTransport.h b/ndn-cpp/c/transport/TcpTransport.h
index ec43806..6421d4b 100644
--- a/ndn-cpp/c/transport/TcpTransport.h
+++ b/ndn-cpp/c/transport/TcpTransport.h
@@ -39,6 +39,11 @@
return ndn_SocketTransport_receive(&self->base, buffer, bufferLength, nBytes);
}
+static inline ndn_Error ndn_TcpTransport_close(struct ndn_TcpTransport *self)
+{
+ return ndn_SocketTransport_close(&self->base);
+}
+
#ifdef __cplusplus
}
#endif
diff --git a/ndn-cpp/c/transport/UdpTransport.h b/ndn-cpp/c/transport/UdpTransport.h
index 262d5ec..ef113b2 100644
--- a/ndn-cpp/c/transport/UdpTransport.h
+++ b/ndn-cpp/c/transport/UdpTransport.h
@@ -39,6 +39,11 @@
return ndn_SocketTransport_receive(&self->base, buffer, bufferLength, nBytes);
}
+static inline ndn_Error ndn_UdpTransport_close(struct ndn_UdpTransport *self)
+{
+ return ndn_SocketTransport_close(&self->base);
+}
+
#ifdef __cplusplus
}
#endif