FSocket_Posix.H 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* -*-C++-*-
  2. "$Id: FSocket_Posix.H,v 1.2 2000/05/16 16:58:12 jamespalmer Exp $"
  3. Copyright 1997 GARRET.
  4. Copyright 1999-2000 by the Flek development team.
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Library General Public
  7. License as published by the Free Software Foundation; either
  8. version 2 of the License, or (at your option) any later version.
  9. This library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Library General Public License for more details.
  13. You should have received a copy of the GNU Library General Public
  14. License along with this library; if not, write to the Free Software
  15. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  16. USA.
  17. Please report all bugs and problems to "[email protected]".
  18. */
  19. // FSocket was adapted from K.A. Knizhnik's very nice SAL library.
  20. #ifndef __FSOCKET_POSIX_H__
  21. #define __FSOCKET_POSIX_H__
  22. #include <FLU/FSocket.H>
  23. class FSocket_Posix : public FSocket {
  24. protected:
  25. descriptor_t fd;
  26. int errcode; // error code of last failed operation
  27. char* address; // host address
  28. socket_domain domain; // Unix domain or INET socket
  29. int create_file; // Unix domain sockets use files for connection
  30. enum error_codes {
  31. ok = 0,
  32. not_opened = -1,
  33. bad_address = -2,
  34. connection_failed = -3,
  35. broken_pipe = -4,
  36. invalid_access_mode = -5
  37. };
  38. public:
  39. //
  40. // Directory for Unix Domain socket files. This directory should be
  41. // either empty or be terminated with "/". Dafault value is "/tmp/"
  42. //
  43. static const char* unix_socket_dir;
  44. int open(int listen_queue_size);
  45. int connect(int max_attempts, time_t timeout);
  46. int read(void* buf, size_t min_size, size_t max_size,time_t timeout);
  47. int read(void* buf, size_t size);
  48. int write(void const* buf, size_t size);
  49. int valid();
  50. int shutdown();
  51. int close();
  52. void get_error_text(char* buf, size_t buf_size);
  53. FSocket* accept();
  54. int cancel_accept();
  55. FSocket_Posix(const char* address, socket_domain domain);
  56. FSocket_Posix(int new_fd);
  57. ~FSocket_Posix();
  58. };
  59. #endif