: bharatvaj/forwarder

commit c838c26a5446eaa67b7831dc5338f9e10f3a454c
parent 4fcb05617b4f574aa6fc75f05d60497932c7a2c2
Author: Dinesh Kumar M <dine15122.cs@rmkec.ac.in>
Date: Tue, 22 Jan 2019 19:58:13 +0530

Corrected thread bug, bluetooth errors rectified
2 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/forwarder/forwarder.cpp b/forwarder/forwarder.cpp
@@ -21,8 +21,6 @@ std::thread *t2 = nullptr;
 void exit_handler(int sig){
   cout << "Forwarder ended" << endl;
   f->stop();
-  t1->join();
-  t2->join();
   delete w;
   delete b;
   exit(EXIT_SUCCESS);

@@ -38,6 +36,8 @@ int main(int argc, char *argv[])
   t2 = new std::thread([](){
     b = new Bluetooth();
   });
+  t1->join();
+  t2->join();
   try {
   f = new Forwarder(w, c);
   } catch(const char *err){
diff --git a/forwarder/include/Bluetooth.hpp b/forwarder/include/Bluetooth.hpp
@@ -1,10 +1,11 @@
 #ifndef _BLUETOOTH_H
 #define _BLUETOOTH_H
 
+#include <stdio.h>
+#include <unistd.h>
 #include <sys/socket.h>
 #include <bluetooth/bluetooth.h>
-#include <bluetooth/hci.h>
-#include <bluetooth/hci_lib.h>
+#include <bluetooth/rfcomm.h>
 
 #include <Network.hpp>
 

@@ -12,6 +13,7 @@ namespace wa {
   class Bluetooth : public Network {
   private:
       int client;
+      //baddr_t *a = nullptr;
   public:
     Bluetooth(){}
 

@@ -29,7 +31,7 @@ namespace wa {
     // bind socket to port 1 of the first available
     // local bluetooth adapter
     loc_addr.rc_family = AF_BLUETOOTH;
-    loc_addr.rc_bdaddr = *BDADDR_ANY;
+    //loc_addr.rc_bdaddr = *BDADDR_ANY;
     loc_addr.rc_channel = (uint8_t) 1;
     bind(s, (struct sockaddr *)&loc_addr, sizeof(loc_addr));
 

@@ -38,6 +40,7 @@ namespace wa {
 
     // accept one connection
     client = accept(s, (struct sockaddr *)&rem_addr, &opt);
+    close(s);
     if(client < 0){
       return false;
     }

@@ -63,7 +66,6 @@ namespace wa {
     ~Bluetooth(){
           // close connection
           close(client);
-          close(s);
     }
   };
 }