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.

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