Merge branch 'master' into server_no_deadlock
[jack2.git] / windows / JackNetWinSocket.h
blob21ad275d08c24dccb9917294ff5e2b7d78a9d382
1 /*
2 Copyright (C) 2008 Romain Moret at Grame
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #ifndef __JackNetWinSocket__
21 #define __JackNetWinSocket__
23 #include "JackNetSocket.h"
24 #ifdef __MINGW32__
25 #include <winsock2.h>
26 #include <ws2tcpip.h>
27 #endif
30 namespace Jack
32 #define E(code, s) { code, s }
33 #define NET_ERROR_CODE WSAGetLastError()
34 #define StrError PrintError
36 typedef uint32_t uint;
37 typedef int SOCKLEN;
38 typedef struct _win_net_error win_net_error_t;
40 struct _win_net_error
42 int code;
43 const char* msg;
46 SERVER_EXPORT const char* PrintError ( int error );
48 //JeckNetWinSocket***************************************************************************
49 class SERVER_EXPORT JackNetWinSocket
51 private:
52 int fSockfd;
53 int fPort;
54 SOCKADDR_IN fSendAddr;
55 SOCKADDR_IN fRecvAddr;
56 public:
57 JackNetWinSocket();
58 JackNetWinSocket ( const char* ip, int port );
59 JackNetWinSocket ( const JackNetWinSocket& );
60 ~JackNetWinSocket();
62 JackNetWinSocket& operator= ( const JackNetWinSocket& );
64 //socket management
65 int NewSocket();
66 int Bind();
67 int BindWith ( const char* ip );
68 int BindWith ( int port );
69 int Connect();
70 int ConnectTo ( const char* ip );
71 void Close();
72 void Reset();
73 bool IsSocket();
75 //IP/PORT management
76 void SetPort ( int port );
77 int GetPort();
79 //address management
80 int SetAddress ( const char* ip, int port );
81 char* GetSendIP();
82 char* GetRecvIP();
84 //utility
85 int GetName ( char* name );
86 int JoinMCastGroup ( const char* mcast_ip );
88 //options management
89 int SetOption ( int level, int optname, const void* optval, SOCKLEN optlen );
90 int GetOption ( int level, int optname, void* optval, SOCKLEN* optlen );
92 //timeout
93 int SetTimeOut ( int usec );
95 //disable local loop
96 int SetLocalLoop();
98 //network operations
99 int SendTo ( const void* buffer, size_t nbytes, int flags );
100 int SendTo ( const void* buffer, size_t nbytes, int flags, const char* ip );
101 int Send ( const void* buffer, size_t nbytes, int flags );
102 int RecvFrom ( void* buffer, size_t nbytes, int flags );
103 int Recv ( void* buffer, size_t nbytes, int flags );
104 int CatchHost ( void* buffer, size_t nbytes, int flags );
106 //error management
107 net_error_t GetError();
111 #endif