commit 399c0897dab03bddef652f636f02cb8087cab12f
parent dae85ad9227aa68f637ef864ea5f68d853846f11
Author: Bharatvaj H <bharatvaj@yahoo.com>
Date: Fri, 29 Mar 2019 02:03:35 +0530
parent dae85ad9227aa68f637ef864ea5f68d853846f11
Author: Bharatvaj H <bharatvaj@yahoo.com>
Date: Fri, 29 Mar 2019 02:03:35 +0530
Added disconnect functionality
3 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/include/NetworkController.hpp b/include/NetworkController.hpp @@ -78,7 +78,8 @@ public: } Device *d2 = destNetwork->connect(bi->params); if (d2 == nullptr) { - fmt::print("Destination not found\n"); + fmt::print("Destination not found\n"); + d.disconnect(); // TODO ERROR HANDLE return; }
diff --git a/include/device/Device.hpp b/include/device/Device.hpp @@ -6,6 +6,8 @@ namespace wa { class Device : public DeviceInfo { public: Device() {} + // disconnects the device from the network + virtual void disconnect() {} virtual int read(char *message, int bytesToRead) = 0; virtual int write(char *message, int bytesToWrite) = 0; };
diff --git a/include/device/IPDevice.hpp b/include/device/IPDevice.hpp @@ -30,6 +30,10 @@ public: return ::write(fd, str, bytesToSend); } + void disconnect(){ + ::close(fd); + } + ~IPDevice() { comm_close_socket(fd); } }; } // namespace wa
: bharatvaj/forwarder