jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
3.4KB

  1. /*
  2. Copyright (C) 2008-2011 Romain Moret at Grame
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU Lesser General Public License as published by
  5. the Free Software Foundation; either version 2.1 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. #ifndef __JackNetUnixSocket__
  16. #define __JackNetUnixSocket__
  17. #include "JackNetSocket.h"
  18. #include <sys/types.h>
  19. #include <sys/socket.h>
  20. #include <netdb.h>
  21. #include <netinet/in.h>
  22. #include <arpa/inet.h>
  23. namespace Jack
  24. {
  25. #define NET_ERROR_CODE errno
  26. #define SOCKET_ERROR -1
  27. #define StrError strerror
  28. typedef struct sockaddr socket_address_t;
  29. typedef struct in_addr address_t;
  30. //JackNetUnixSocket********************************************
  31. class SERVER_EXPORT JackNetUnixSocket
  32. {
  33. private:
  34. int fSockfd;
  35. int fPort;
  36. int fTimeOut;
  37. struct sockaddr_in fSendAddr;
  38. struct sockaddr_in fRecvAddr;
  39. #if defined(__sun__) || defined(sun)
  40. int WaitRead();
  41. int WaitWrite();
  42. #endif
  43. public:
  44. JackNetUnixSocket();
  45. JackNetUnixSocket(const char* ip, int port);
  46. JackNetUnixSocket(const JackNetUnixSocket&);
  47. ~JackNetUnixSocket();
  48. JackNetUnixSocket& operator=(const JackNetUnixSocket& socket);
  49. //socket management
  50. int NewSocket();
  51. int Bind();
  52. int BindWith(const char* ip);
  53. int BindWith(int port);
  54. int Connect();
  55. int ConnectTo(const char* ip);
  56. void Close();
  57. void Reset();
  58. bool IsSocket();
  59. //IP/PORT management
  60. void SetPort(int port);
  61. int GetPort();
  62. //address management
  63. int SetAddress(const char* ip, int port);
  64. char* GetSendIP();
  65. char* GetRecvIP();
  66. //utility
  67. int GetName(char* name);
  68. int JoinMCastGroup(const char* mcast_ip);
  69. //options management
  70. int SetOption(int level, int optname, const void* optval, socklen_t optlen);
  71. int GetOption(int level, int optname, void* optval, socklen_t* optlen);
  72. //timeout
  73. int SetTimeOut(int us);
  74. //disable local loop
  75. int SetLocalLoop();
  76. bool IsLocal(char* ip);
  77. //network operations
  78. int SendTo(const void* buffer, size_t nbytes, int flags);
  79. int SendTo(const void* buffer, size_t nbytes, int flags, const char* ip);
  80. int Send(const void* buffer, size_t nbytes, int flags);
  81. int RecvFrom(void* buffer, size_t nbytes, int flags);
  82. int Recv(void* buffer, size_t nbytes, int flags);
  83. int CatchHost(void* buffer, size_t nbytes, int flags);
  84. //error management
  85. net_error_t GetError();
  86. void PrintError();
  87. };
  88. }
  89. #endif