rcvthread.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /**
  2. \file rcvthread.h
  3. \author michael.zohner@ec-spride.de
  4. \copyright ABY - A Framework for Efficient Mixed-protocol Secure Two-party Computation
  5. Copyright (C) 2019 ENCRYPTO Group, TU Darmstadt
  6. This program is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU Lesser General Public License as published
  8. by the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. ABY is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU Lesser General Public License for more details.
  14. You should have received a copy of the GNU Lesser General Public License
  15. along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. \brief Receiver Thread Implementation
  17. */
  18. #ifndef RCV_THREAD_H_
  19. #define RCV_THREAD_H_
  20. #include "constants.h"
  21. #include "thread.h"
  22. #include <array>
  23. #include <cstdint>
  24. #include <memory>
  25. #include <mutex>
  26. #include <queue>
  27. class CSocket;
  28. struct rcv_ctx {
  29. uint8_t *buf;
  30. uint64_t rcvbytes;
  31. };
  32. class RcvThread: public CThread {
  33. public:
  34. RcvThread(CSocket* sock, CLock* glock);
  35. ~RcvThread();
  36. CLock* getlock() const;
  37. void setlock(CLock *glock);
  38. void flush_queue(uint8_t channelid);
  39. void remove_listener(uint8_t channelid);
  40. std::queue<rcv_ctx*>* add_listener(uint8_t channelid, CEvent* rcv_event, CEvent* fin_event);
  41. std::mutex& get_listener_mutex(uint8_t channelid);
  42. void ThreadMain();
  43. private:
  44. //A receive task listens to a particular id and writes incoming data on that id into rcv_buf and triggers event
  45. struct rcv_task {
  46. std::queue<rcv_ctx*> rcv_buf;
  47. std::mutex rcv_buf_mutex;
  48. //std::queue<uint64_t> rcvbytes;
  49. CEvent* rcv_event;
  50. CEvent* fin_event;
  51. bool inuse;
  52. bool forward_notify_fin;
  53. };
  54. CLock* rcvlock;
  55. CSocket* mysock;
  56. std::array<rcv_task, MAX_NUM_COMM_CHANNELS> listeners;
  57. };
  58. #endif /* RCV_THREAD_H_ */