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.

112 lines
3.3KB

  1. /*
  2. Copyright (C) 2004-2008 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 __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. typedef struct _win_net_error win_net_error_t;
  30. struct _win_net_error
  31. {
  32. int code;
  33. const char* msg;
  34. };
  35. SERVER_EXPORT const char* PrintError ( int error );
  36. //JeckNetWinSocket***************************************************************************
  37. class SERVER_EXPORT JackNetWinSocket
  38. {
  39. private:
  40. int fSockfd;
  41. int fPort;
  42. SOCKADDR_IN fSendAddr;
  43. SOCKADDR_IN fRecvAddr;
  44. public:
  45. JackNetWinSocket();
  46. JackNetWinSocket ( const char* ip, int port );
  47. JackNetWinSocket ( const JackNetWinSocket& );
  48. ~JackNetWinSocket();
  49. JackNetWinSocket& operator= ( const JackNetWinSocket& );
  50. //socket management
  51. int NewSocket();
  52. int Bind();
  53. int BindWith ( const char* ip );
  54. int BindWith ( int port );
  55. int Connect();
  56. int ConnectTo ( const char* ip );
  57. void Close();
  58. void Reset();
  59. bool IsSocket();
  60. //IP/PORT management
  61. void SetPort ( int port );
  62. int GetPort();
  63. //address management
  64. int SetAddress ( const char* ip, int port );
  65. char* GetSendIP();
  66. char* GetRecvIP();
  67. //utility
  68. int GetName ( char* name );
  69. int JoinMCastGroup ( const char* mcast_ip );
  70. //options management
  71. int SetOption ( int level, int optname, const void* optval, SOCKLEN optlen );
  72. int GetOption ( int level, int optname, void* optval, SOCKLEN* optlen );
  73. //timeout
  74. int SetTimeOut ( int usec );
  75. //disable local loop
  76. int SetLocalLoop();
  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. };
  87. }
  88. #endif