forked from sPHENIX-Collaboration/srs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
srs_test.cc
88 lines (63 loc) · 1.5 KB
/
srs_test.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <arpa/inet.h>
#include <netinet/in.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <fcntl.h>
#define BUFLEN 4096
#define NPACK 100
#define PORT 6006
using namespace std;
void diep(char *s)
{
perror(s);
exit(1);
}
main(int argc, char *argv[])
{
if ( argc < 2)
{
cout << "Usage: " << argv[0] << " outfile" << endl;
exit(1);
}
struct sockaddr_in si_me, si_other;
int s, i;
socklen_t slen=sizeof(si_other);
int count=0;
if ((s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))==-1)
diep("socket");
memset((char *) &si_me, 0, sizeof(si_me));
si_me.sin_family = AF_INET;
si_me.sin_port = htons(PORT);
si_me.sin_addr.s_addr = htonl(INADDR_ANY);
if (bind(s, (sockaddr *)&si_me, sizeof(si_me))==-1)
diep("bind");
int d[5000];
int r;
count = 100;
int sleeptime = 0;
int ifd = open(argv[1], O_WRONLY | O_CREAT | O_EXCL | O_LARGEFILE ,
S_IRWXU | S_IROTH | S_IRGRP );
if (ifd < 0)
{
cerr << "file exists, I will not overwrite " << argv[1] << endl;
exit(1);
}
const unsigned int eop_marker = 0xf000f000;
for (i = 0; i< count; i++)
{
if ( ( r = recvfrom(s, d, 4*5000, 0, (sockaddr *) &si_other, &slen) ) ==-1)
diep("recvfrom()");
cout << "length received: " << r << endl;
write( ifd, d, r);
write( ifd, &eop_marker, 4);
}
close(s);
close (ifd);
return 0;
}