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.

102 lines
2.7KB

  1. /*
  2. Copyright (C) 2008 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 General Public License as published by
  5. the Free Software Foundation; either version 2 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 General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, 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 EXPORT JackNetUnixSocket
  32. {
  33. private:
  34. int fSockfd;
  35. int fPort;
  36. struct sockaddr_in fSendAddr;
  37. struct sockaddr_in fRecvAddr;
  38. public:
  39. JackNetUnixSocket();
  40. JackNetUnixSocket ( const char* ip, int port );
  41. ~JackNetUnixSocket();
  42. //socket management
  43. int NewSocket();
  44. int Bind();
  45. int BindWith ( const char* ip );
  46. int BindWith ( int port );
  47. int Connect();
  48. int ConnectTo ( const char* ip );
  49. void Close();
  50. void Reset();
  51. bool IsSocket();
  52. //IP/PORT management
  53. void SetPort ( int port );
  54. int GetPort();
  55. //address management
  56. int SetAddress ( const char* ip, int port );
  57. char* GetSendIP();
  58. char* GetRecvIP();
  59. //utility
  60. int GetName ( char* name );
  61. int JoinMCastGroup ( const char* mcast_ip );
  62. void CopyParams ( JackNetUnixSocket* socket );
  63. //options management
  64. int SetOption ( int level, int optname, const void* optval, socklen_t optlen );
  65. int GetOption ( int level, int optname, void* optval, socklen_t* optlen );
  66. //timeout
  67. int SetTimeOut ( int& msec );
  68. //local loop
  69. int SetLocalLoop();
  70. //network operations
  71. int SendTo ( const void* buffer, size_t nbytes, int flags );
  72. int SendTo ( const void* buffer, size_t nbytes, int flags, const char* ip );
  73. int Send ( const void* buffer, size_t nbytes, int flags );
  74. int RecvFrom ( void* buffer, size_t nbytes, int flags );
  75. int Recv ( void* buffer, size_t nbytes, int flags );
  76. int CatchHost ( void* buffer, size_t nbytes, int flags );
  77. //error management
  78. net_error_t GetError();
  79. };
  80. }
  81. #endif