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.

105 lines
3.2KB

  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 __JackNetWinSocket__
  16. #define __JackNetWinSocket__
  17. #include "JackNetSocket.h"
  18. #ifdef __MINGW32__
  19. #include <winsock2.h>
  20. #include <ws2tcpip.h>
  21. #endif
  22. namespace Jack
  23. {
  24. #define E(code, s) { code, s }
  25. #define NET_ERROR_CODE WSAGetLastError()
  26. #define StrError PrintError
  27. typedef uint32_t uint;
  28. typedef int SOCKLEN;
  29. SERVER_EXPORT const char* PrintError ( int error );
  30. //JeckNetWinSocket***************************************************************************
  31. class SERVER_EXPORT JackNetWinSocket
  32. {
  33. private:
  34. int fSockfd;
  35. int fPort;
  36. SOCKADDR_IN fSendAddr;
  37. SOCKADDR_IN fRecvAddr;
  38. public:
  39. JackNetWinSocket();
  40. JackNetWinSocket ( const char* ip, int port );
  41. JackNetWinSocket ( const JackNetWinSocket& );
  42. ~JackNetWinSocket();
  43. JackNetWinSocket& operator= ( const JackNetWinSocket& );
  44. //socket management
  45. int NewSocket();
  46. int Bind();
  47. int BindWith ( const char* ip );
  48. int BindWith ( int port );
  49. int Connect();
  50. int ConnectTo ( const char* ip );
  51. void Close();
  52. void Reset();
  53. bool IsSocket();
  54. //IP/PORT management
  55. void SetPort ( int port );
  56. int GetPort();
  57. //address management
  58. int SetAddress ( const char* ip, int port );
  59. char* GetSendIP();
  60. char* GetRecvIP();
  61. //utility
  62. int GetName ( char* name );
  63. int JoinMCastGroup ( const char* mcast_ip );
  64. //options management
  65. int SetOption ( int level, int optname, const void* optval, SOCKLEN optlen );
  66. int GetOption ( int level, int optname, void* optval, SOCKLEN* optlen );
  67. //timeout
  68. int SetTimeOut ( int usec );
  69. //disable local loop
  70. int SetLocalLoop();
  71. //network operations
  72. int SendTo ( const void* buffer, size_t nbytes, int flags );
  73. int SendTo ( const void* buffer, size_t nbytes, int flags, const char* ip );
  74. int Send ( const void* buffer, size_t nbytes, int flags );
  75. int RecvFrom ( void* buffer, size_t nbytes, int flags );
  76. int Recv ( void* buffer, size_t nbytes, int flags );
  77. int CatchHost ( void* buffer, size_t nbytes, int flags );
  78. //error management
  79. net_error_t GetError();
  80. };
  81. }
  82. #endif