socket.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. \file socket.h
  3. \author Seung Geol Choi
  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 Socket Implementation
  17. */
  18. #ifndef __SOCKET_H__BY_SGCHOI
  19. #define __SOCKET_H__BY_SGCHOI
  20. #include <cstdint>
  21. #include <memory>
  22. #include <mutex>
  23. #include <string>
  24. class CSocket {
  25. public:
  26. CSocket(bool verbose=false);
  27. ~CSocket();
  28. uint64_t getSndCnt() const;
  29. uint64_t getRcvCnt() const;
  30. void ResetSndCnt();
  31. void ResetRcvCnt();
  32. bool Socket();
  33. void Close();
  34. std::string GetIP() const;
  35. uint16_t GetPort() const;
  36. bool Bind(const std::string& address = "", uint16_t port = 0);
  37. bool Listen(int nQLen = 5);
  38. std::unique_ptr<CSocket> Accept();
  39. bool Connect(const std::string& host, uint16_t port);
  40. size_t Receive(void* buf, size_t bytes);
  41. size_t Send(const void* buf, size_t bytes);
  42. private:
  43. struct CSocketImpl;
  44. std::unique_ptr<CSocketImpl> impl_;
  45. uint64_t send_count_, recv_count_;
  46. mutable std::mutex send_count_mutex_;
  47. mutable std::mutex recv_count_mutex_;
  48. bool verbose_;
  49. };
  50. #endif //SOCKET_H__BY_SGCHOI