summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2015-09-24 11:11:16 -0700
committerAdam Ierymenko <adam.ierymenko@gmail.com>2015-09-24 11:11:16 -0700
commit557d2b3b0d7bc2bc120e12ad5455ce3ab30a504e (patch)
tree94ba1fdde06cd4d9ae4f05919fedb4920878776e
parentfbde40d1fc8767e4b6e9fcf0b078a8a4eb0646bd (diff)
downloadinfinitytier-557d2b3b0d7bc2bc120e12ad5455ce3ab30a504e.tar.gz
infinitytier-557d2b3b0d7bc2bc120e12ad5455ce3ab30a504e.zip
Make LWIPStack clean up properly.
-rw-r--r--netcon/LWIPStack.hpp24
-rw-r--r--netcon/NetconEthernetTap.cpp1
2 files changed, 19 insertions, 6 deletions
diff --git a/netcon/LWIPStack.hpp b/netcon/LWIPStack.hpp
index a938dd1e..9bf3b613 100644
--- a/netcon/LWIPStack.hpp
+++ b/netcon/LWIPStack.hpp
@@ -97,13 +97,21 @@ typedef ip_addr ip_addr_t;
#define NETIF_SET_UP_SIG struct netif *netif
#define NETIF_POLL_SIG struct netif *netif
-
-
-class LWIPStack{
+/**
+ * Loads an instance of liblwip.so in a private memory arena
+ *
+ * This uses dlmopen() to load an instance of the LWIP stack into its
+ * own private memory space. This is done to get around the stack's
+ * lack of thread-safety or multi-instance support. The alternative
+ * would be to massively refactor the stack so everything lives in a
+ * state object instead of static memory space.
+ */
+class LWIPStack
+{
+private:
void* libref;
public:
-
void (*lwip_init)();
err_t (*tcp_write)(TCP_WRITE_SIG);
void (*tcp_sent)(TCP_SENT_SIG);
@@ -141,8 +149,6 @@ public:
void (*netif_set_up)(NETIF_SET_UP_SIG);
void (*netif_poll)(NETIF_POLL_SIG);
-
-
LWIPStack(const char* path)
{
libref = dlmopen(LM_ID_NEWLM, path, RTLD_NOW);
@@ -188,6 +194,12 @@ public:
netif_set_up = (void(*)(NETIF_SET_UP_SIG))dlsym(libref, "netif_set_up");
netif_poll = (void(*)(NETIF_POLL_SIG))dlsym(libref, "netif_poll");
}
+
+ ~LWIPStack()
+ {
+ if (lebref)
+ dlclose(libref);
+ }
};
#endif
diff --git a/netcon/NetconEthernetTap.cpp b/netcon/NetconEthernetTap.cpp
index 0895cb44..eb3067f2 100644
--- a/netcon/NetconEthernetTap.cpp
+++ b/netcon/NetconEthernetTap.cpp
@@ -96,6 +96,7 @@ NetconEthernetTap::~NetconEthernetTap()
_phy.whack();
Thread::join(_thread);
_phy.close(_unixListenSocket,false);
+ delete lwipstack;
}
void NetconEthernetTap::setEnabled(bool en)