Jack2 1.9.6
|
00001 /* 00002 Copyright (C) 2004-2008 Grame 00003 00004 This program is free software; you can redistribute it and/or modify 00005 it under the terms of the GNU Lesser General Public License as published by 00006 the Free Software Foundation; either version 2.1 of the License, or 00007 (at your option) any later version. 00008 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 GNU Lesser General Public License for more details. 00013 00014 You should have received a copy of the GNU Lesser General Public License 00015 along with this program; if not, write to the Free Software 00016 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 00018 */ 00019 00020 #ifndef __JackNetWinSocket__ 00021 #define __JackNetWinSocket__ 00022 00023 #include "JackNetSocket.h" 00024 #ifdef __MINGW32__ 00025 #include <winsock2.h> 00026 #include <ws2tcpip.h> 00027 #endif 00028 00029 00030 namespace Jack 00031 { 00032 #define E(code, s) { code, s } 00033 #define NET_ERROR_CODE WSAGetLastError() 00034 #define StrError PrintError 00035 00036 typedef uint32_t uint; 00037 typedef int SOCKLEN; 00038 typedef struct _win_net_error win_net_error_t; 00039 00040 struct _win_net_error 00041 { 00042 int code; 00043 const char* msg; 00044 }; 00045 00046 SERVER_EXPORT const char* PrintError ( int error ); 00047 00048 //JeckNetWinSocket*************************************************************************** 00049 class SERVER_EXPORT JackNetWinSocket 00050 { 00051 private: 00052 int fSockfd; 00053 int fPort; 00054 SOCKADDR_IN fSendAddr; 00055 SOCKADDR_IN fRecvAddr; 00056 public: 00057 JackNetWinSocket(); 00058 JackNetWinSocket ( const char* ip, int port ); 00059 JackNetWinSocket ( const JackNetWinSocket& ); 00060 ~JackNetWinSocket(); 00061 00062 JackNetWinSocket& operator= ( const JackNetWinSocket& ); 00063 00064 //socket management 00065 int NewSocket(); 00066 int Bind(); 00067 int BindWith ( const char* ip ); 00068 int BindWith ( int port ); 00069 int Connect(); 00070 int ConnectTo ( const char* ip ); 00071 void Close(); 00072 void Reset(); 00073 bool IsSocket(); 00074 00075 //IP/PORT management 00076 void SetPort ( int port ); 00077 int GetPort(); 00078 00079 //address management 00080 int SetAddress ( const char* ip, int port ); 00081 char* GetSendIP(); 00082 char* GetRecvIP(); 00083 00084 //utility 00085 int GetName ( char* name ); 00086 int JoinMCastGroup ( const char* mcast_ip ); 00087 00088 //options management 00089 int SetOption ( int level, int optname, const void* optval, SOCKLEN optlen ); 00090 int GetOption ( int level, int optname, void* optval, SOCKLEN* optlen ); 00091 00092 //timeout 00093 int SetTimeOut ( int usec ); 00094 00095 //disable local loop 00096 int SetLocalLoop(); 00097 00098 //network operations 00099 int SendTo ( const void* buffer, size_t nbytes, int flags ); 00100 int SendTo ( const void* buffer, size_t nbytes, int flags, const char* ip ); 00101 int Send ( const void* buffer, size_t nbytes, int flags ); 00102 int RecvFrom ( void* buffer, size_t nbytes, int flags ); 00103 int Recv ( void* buffer, size_t nbytes, int flags ); 00104 int CatchHost ( void* buffer, size_t nbytes, int flags ); 00105 00106 //error management 00107 net_error_t GetError(); 00108 }; 00109 } 00110 00111 #endif