Merge pull request #23 from jackaudio/device_reservation_fixes
[jack2.git] / windows / JackNetWinSocket.h
blob153f65bb6802716a7b14a3d495a66759ee42fc5c
1 /*
2 Copyright (C) 2004-2008 Grame
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as published by
6 the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #ifndef __JackNetWinSocket__
21 #define __JackNetWinSocket__
23 #include "JackNetSocket.h"
24 #ifdef __MINGW32__
25 #include <winsock2.h>
26 #include <ws2tcpip.h>
27 #include <stdint.h>
28 #endif
30 namespace Jack
33 #define E(code, s) { code, s }
34 #define NET_ERROR_CODE WSAGetLastError()
35 #define StrError PrintError
37 typedef uint32_t uint;
38 typedef int SOCKLEN;
39 typedef struct _win_net_error win_net_error_t;
41 struct _win_net_error
43 int code;
44 const char* msg;
47 SERVER_EXPORT const char* PrintError(int error);
49 //JeckNetWinSocket***************************************************************************
50 class SERVER_EXPORT JackNetWinSocket
52 private:
53 int fSockfd;
54 int fPort;
55 SOCKADDR_IN fSendAddr;
56 SOCKADDR_IN fRecvAddr;
57 public:
58 JackNetWinSocket();
59 JackNetWinSocket(const char* ip, int port);
60 JackNetWinSocket(const JackNetWinSocket&);
61 ~JackNetWinSocket();
63 JackNetWinSocket& operator=(const JackNetWinSocket&);
65 //socket management
66 int NewSocket();
67 int Bind();
68 int BindWith(const char* ip);
69 int BindWith(int port);
70 int Connect();
71 int ConnectTo(const char* ip);
72 void Close();
73 void Reset();
74 bool IsSocket();
76 //IP/PORT management
77 void SetPort(int port);
78 int GetPort();
80 //address management
81 int SetAddress(const char* ip, int port);
82 char* GetSendIP();
83 char* GetRecvIP();
85 //utility
86 int GetName(char* name);
87 int JoinMCastGroup(const char* mcast_ip);
89 //options management
90 int SetOption(int level, int optname, const void* optval, SOCKLEN optlen);
91 int GetOption(int level, int optname, void* optval, SOCKLEN* optlen);
93 //timeout
94 int SetTimeOut(int usec);
96 //disable local loop
97 int SetLocalLoop();
99 bool IsLocal(char* ip);
101 //network operations
102 int SendTo(const void* buffer, size_t nbytes, int flags);
103 int SendTo(const void* buffer, size_t nbytes, int flags, const char* ip);
104 int Send(const void* buffer, size_t nbytes, int flags);
105 int RecvFrom(void* buffer, size_t nbytes, int flags);
106 int Recv(void* buffer, size_t nbytes, int flags);
107 int CatchHost(void* buffer, size_t nbytes, int flags);
109 //error management
110 net_error_t GetError();
114 #endif