Jack2: JackNetWinSocket.h Source File

Jack2 1.9.12

JackNetWinSocket.h
1 /*
2 Copyright (C) 2004-2008 Grame
3
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.
8
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.
13
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.
17
18 */
19
20 #ifndef __JackNetWinSocket__
21 #define __JackNetWinSocket__
22
23 #include "JackNetSocket.h"
24 #ifdef __MINGW32__
25 #include <winsock2.h>
26 #include <ws2tcpip.h>
27 #include <stdint.h>
28 #endif
29
30 namespace Jack
31 {
32
33 #define E(code, s) { code, s }
34 #define NET_ERROR_CODE WSAGetLastError()
35 #define StrError PrintError
36
37 typedef uint32_t uint;
38 typedef int SOCKLEN;
39 typedef struct _win_net_error win_net_error_t;
40
41 struct _win_net_error
42 {
43 int code;
44 const char* msg;
45 };
46
47 SERVER_EXPORT const char* PrintError(int error);
48
49 //JeckNetWinSocket***************************************************************************
50 class SERVER_EXPORT JackNetWinSocket
51 {
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();
62
63 JackNetWinSocket& operator=(const JackNetWinSocket&);
64
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();
75
76 //IP/PORT management
77 void SetPort(int port);
78 int GetPort();
79
80 //address management
81 int SetAddress(const char* ip, int port);
82 char* GetSendIP();
83 char* GetRecvIP();
84
85 //utility
86 int GetName(char* name);
87 int JoinMCastGroup(const char* mcast_ip);
88
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);
92
93 //timeout
94 int SetTimeOut(int usec);
95
96 //disable local loop
97 int SetLocalLoop();
98
99 bool IsLocal(char* ip);
100
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);
108
109 //error management
110 net_error_t GetError();
111 };
112 }
113
114 #endif
115
Jack::_win_net_error
Definition: JackNetWinSocket.h:41
Jack::JackNetWinSocket
Definition: JackNetWinSocket.h:50