OpenCOVER
rel_mcast-old.h
Go to the documentation of this file.
1/* This file is part of COVISE.
2
3 You can use it under the terms of the GNU Lesser General Public License
4 version 2.1 or later, see lgpl-2.1.txt.
5
6 * License: LGPL 2+ */
7
8//****************************************************************************
9// Filename: rel_mcast.h
10// Project Affiliation: none
11// Funcionality: Header file for rel_mcast.cpp
12// Author: Michael Poehnl
13// Institution: University of Stuttgart, HPC Center
14// Operating Systems: Linux
15// Creation Date: 03-09-23
16//****************************************************************************
17
18#ifndef REL_MCAST_H
19#define REL_MCAST_H
20
21#ifdef WIN32
22#include <Winsock2.h>
23#endif
24
25#include <util/coTypes.h>
26
27#include <iostream>
28#include <string.h>
29#ifdef WIN32
30#include <MSWSock.h>
31#include <windows.h>
32#include <ws2tcpip.h>
33//#include <windows.h>
34/*
35struct iovec
36{
37 void *iov_base; // BSD uses caddr_t (1003.1g requires void *)
38 DWORD iov_len; // Must be size_t (1003.1g)
39};
40
41struct msghdr {
42 void * msg_name; // Socket name
43 int msg_namelen; // Length of name
44 struct iovec * msg_iov; // Data blocks
45__kernel_size_t msg_iovlen; // Number of blocks
46void * msg_control; // Per protocol magic (eg BSD file descriptor passing)
47__kernel_size_t msg_controllen; // Length of cmsg list
48unsigned msg_flags;
49};*/
50#define msghdr _WSAMSG
51#define msg_name name
52#define msg_namelen namelen
53#define msg_iov lpBuffers
54#define msg_iovlen dwBufferCount
55#define msg_control Control
56#define msg_flags dwFlags
57#define recvmsg WSARecvMsg
58#define sendmsg WSASend
59#define iovec _WSABUF
60#define iov_base buf
61#define iov_len len
62
63#else
64#include <sys/socket.h>
65#include <sys/ioctl.h>
66#include <errno.h>
67#include <netinet/in.h>
68#include <arpa/inet.h>
69#include <net/if.h>
70#include <unistd.h>
71#include <sys/uio.h>
72#endif
73namespace opencover
74{
75typedef unsigned char uchar;
76typedef unsigned short ushort;
77typedef unsigned int uint;
78typedef unsigned long ulong;
79
80#define RM_TRACE(DBG_LVL, ACT_LVL, STRING) \
81 { \
82 if (ACT_LVL >= DBG_LVL) \
83 std::cerr << STRING << std::endl; \
84 }
85
86#define RM_ERRNO(DBG_LVL, ACT_LVL, STRING) \
87 { \
88 if (ACT_LVL >= DBG_LVL) \
89 printErrorMessage(STRING); \
90 }
91
92//----------------------------------------------------------------------------
197class COVEREXPORT Rel_Mcast
198{
199
200public:
202 {
209 RM_SYNC_ERROR
210 };
211
212 Rel_Mcast(int portnumber, int number_clients,
213 const char *addr = "224.223.222.221", const char *interfaceName = 0);
214 Rel_Mcast(int portnumber, const char *addr = "224.223.222.221",
215 const char *interfaceName = 0);
218 RM_Error_Type write_mcast(const void *, int, bool);
219 RM_Error_Type read_mcast(void *, int, bool);
221 void set_sock_buffsize(int sbs);
222 void set_debuglevel(int);
224 void set_mtu(int);
226 void set_msg_buffer(int);
228
229private:
230 RM_Error_Type init_server();
231 RM_Error_Type init_client();
232 int synchronize(uint &);
233 void printErrorMessage(const char *prefix);
234 int readable_timeo();
235 int data_waiting();
236 int write_msg(const struct msghdr *, int);
237 int read_msg(struct msghdr *, int);
238
239 struct sockaddr_in host_addr;
240#ifdef __linux__
241 socklen_t host_addrlen;
242#else
243 int host_addrlen;
244#endif
245 int sockfd;
246 int port;
247 int num_clients;
248 const char *mcast_addr;
249 const char *if_name;
250 int read_timeout;
251 int debug_level;
252 char *buffer;
253 int msg_buff_size;
254 int sock_buffsize;
255 uchar loopback;
256 bool is_server;
257 int max_seg_size;
258 uint seq_num;
259 uint sync_seq_num;
260 int num_retry;
261 uint tail;
262};
263}
264#endif
Definition: ARToolKit.h:33
unsigned int uint
abbreviation for unsigned int
Definition: rel_mcast-old.h:77
unsigned long ulong
abbreviation for unsigned long
Definition: rel_mcast-old.h:78
unsigned char uchar
abbreviation for unsigned char
Definition: rel_mcast-old.h:75
unsigned short ushort
abbreviation for unsigned short
Definition: rel_mcast-old.h:76
Definition: rel_mcast-old.h:198
void set_retry_counter(int)
Rel_Mcast(int portnumber, const char *addr="224.223.222.221", const char *interfaceName=0)
void set_sock_buffsize(int sbs)
void set_debuglevel(int)
RM_Error_Type write_mcast(const void *, int, bool)
RM_Error_Type init()
RM_Error_Type read_mcast(void *, int, bool)
void set_readtimeout(int)
RM_Error_Type
Error Codes.
Definition: rel_mcast-old.h:202
@ RM_SOCK_ERROR
Definition: rel_mcast-old.h:205
@ RM_READ_ERROR
Definition: rel_mcast-old.h:207
@ RM_ALLOC_ERROR
Definition: rel_mcast-old.h:208
@ RM_OK
no error
Definition: rel_mcast-old.h:203
@ RM_TIMEOUT_ERROR
Definition: rel_mcast-old.h:204
@ RM_WRITE_ERROR
Definition: rel_mcast-old.h:206
void set_loopback(uchar)
void set_msg_buffer(int)
Rel_Mcast(int portnumber, int number_clients, const char *addr="224.223.222.221", const char *interfaceName=0)