Jack2: JackNetUnixSocket.h Source File

Jack2 1.9.12

JackNetUnixSocket.h
1 /*
2 Copyright (C) 2008-2011 Romain Moret at Grame
3
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.
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 General Public License for more details.
13
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.
17
18 */
19
20 #ifndef __JackNetUnixSocket__
21 #define __JackNetUnixSocket__
22
23 #include "JackNetSocket.h"
24 #include <sys/types.h>
25 #include <sys/socket.h>
26 #include <netdb.h>
27 #include <netinet/in.h>
28 #include <arpa/inet.h>
29
30 namespace Jack
31 {
32 #define NET_ERROR_CODE errno
33 #define SOCKET_ERROR -1
34 #define StrError strerror
35
36 typedef struct sockaddr socket_address_t;
37 typedef struct in_addr address_t;
38
39 //JackNetUnixSocket********************************************
40 class SERVER_EXPORT JackNetUnixSocket
41 {
42 private:
43
44 int fSockfd;
45 int fPort;
46 int fTimeOut;
47
48 struct sockaddr_in fSendAddr;
49 struct sockaddr_in fRecvAddr;
50 #if defined(__sun__) || defined(sun)
51 int WaitRead();
52 int WaitWrite();
53 #endif
54
55 public:
56
57 JackNetUnixSocket();
58 JackNetUnixSocket(const char* ip, int port);
59 JackNetUnixSocket(const JackNetUnixSocket&);
60 ~JackNetUnixSocket();
61
62 JackNetUnixSocket& operator=(const JackNetUnixSocket& socket);
63
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();
74
75 //IP/PORT management
76 void SetPort(int port);
77 int GetPort();
78
79 //address management
80 int SetAddress(const char* ip, int port);
81 char* GetSendIP();
82 char* GetRecvIP();
83
84 //utility
85 int GetName(char* name);
86 int JoinMCastGroup(const char* mcast_ip);
87
88 //options management
89 int SetOption(int level, int optname, const void* optval, socklen_t optlen);
90 int GetOption(int level, int optname, void* optval, socklen_t* optlen);
91
92 //timeout
93 int SetTimeOut(int us);
94
95 //disable local loop
96 int SetLocalLoop();
97
98 bool IsLocal(char* ip);
99
100 //network operations
101 int SendTo(const void* buffer, size_t nbytes, int flags);
102 int SendTo(const void* buffer, size_t nbytes, int flags, const char* ip);
103 int Send(const void* buffer, size_t nbytes, int flags);
104 int RecvFrom(void* buffer, size_t nbytes, int flags);
105 int Recv(void* buffer, size_t nbytes, int flags);
106 int CatchHost(void* buffer, size_t nbytes, int flags);
107
108 //error management
109 net_error_t GetError();
110 void PrintError();
111 };
112 }
113
114 #endif
Jack
Definition: JackAC3Encoder.cpp:30
Jack::JackNetUnixSocket
Definition: JackNetUnixSocket.h:40