CMS 3D CMS Logo

Macros | Functions
cmsShowSendReport.cc File Reference
#include <cstdio>
#include <cstdlib>
#include <arpa/inet.h>
#include "zlib.h"
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <cstring>
#include <netdb.h>
#include <iostream>

Go to the source code of this file.

Macros

#define BUFLEN   60000
 

Functions

void getCompressedBuffer (const char *fname, Bytef **buffPtr, unsigned long &zippedSize)
 
int main (int argc, char **argv)
 

Macro Definition Documentation

◆ BUFLEN

#define BUFLEN   60000

Definition at line 12 of file cmsShowSendReport.cc.

Function Documentation

◆ getCompressedBuffer()

void getCompressedBuffer ( const char *  fname,
Bytef **  buffPtr,
unsigned long &  zippedSize 
)

Definition at line 19 of file cmsShowSendReport.cc.

References edmScanValgrind::buffer, DMR_cfg::cerr, beamvalidation::exit(), alignmentValidation::fname, free(), malloc(), and mps_fire::result.

Referenced by main().

19  {
20  FILE* pFile = fopen(fname, "r");
21  if (pFile == nullptr) {
22  std::cerr << "Can't open " << fname << std::endl;
23  exit(1);
24  }
25 
26  // obtain file size:
27  fseek(pFile, 0, SEEK_END);
28  unsigned int lSize = ftell(pFile);
29  rewind(pFile);
30 
31  // allocate memory to contain the whole file:
32  void* buffer = malloc(sizeof(Bytef) * (lSize));
33 
34  size_t result = fread(buffer, 1, lSize, pFile);
35  fclose(pFile);
36  if (!result) {
37  std::cerr << "Failed to read " << fname << std::endl;
38  exit(1);
39  }
40 
41  //
42  // write a new buffer. First four bytes is integer with
43  // value of size of uncompressed data. Remaining content
44  // is compressed original buffer.
45  //
46  unsigned int deflatedSize = compressBound(lSize) + 4; // estimation
47  Bytef* deflatedBuff = (Bytef*)malloc(sizeof(Bytef) * (deflatedSize));
48  *((unsigned int*)deflatedBuff) = htonl(lSize);
49 
50  //set buffer ptr
51  *buffPtr = deflatedBuff;
52 
53  // compress buffer
54  zippedSize = deflatedSize;
55  compress(deflatedBuff + 4, &zippedSize, (const Bytef*)buffer, lSize);
56  zippedSize += 4;
57 
58  free(buffer);
59  /*
60  printf("zipped size %d \n", (int)zippedSize);
61  FILE* pFileOut = fopen ( "myfile-compressed" , "wb" );
62  fwrite (deflatedBuff , 1 , zippedSize , pFileOut );
63  fclose(pFileOut);
64  */
65 }
void free(void *ptr) noexcept
void * malloc(size_t size) noexcept
string fname
main script
def exit(msg="")

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 67 of file cmsShowSendReport.cc.

References dir2webdir::argc, GCPpyPlots::argv, DMR_cfg::cerr, beamvalidation::exit(), free(), getCompressedBuffer(), and h.

67  {
68  if (argc != 2) {
69  std::cerr << "Uasage: sendCrashReport <fileName>" << std::endl;
70  exit(1);
71  }
72 
73  // socket creation
74  int sd = socket(AF_INET, SOCK_DGRAM, 0);
75  if (sd < 0) {
76  return 1;
77  }
78 
79  // printf("bind port\n");
80  struct sockaddr_in cliAddr;
81  cliAddr.sin_family = AF_INET;
82  cliAddr.sin_addr.s_addr = htonl(INADDR_ANY);
83  cliAddr.sin_port = htons(0);
84 
85  int rc = bind(sd, (struct sockaddr*)&cliAddr, sizeof(cliAddr));
86  if (rc < 0) {
87  std::cerr << "Can't bind port %d " << rc << std::endl;
88  exit(1);
89  }
90 
91  // send data
92  struct hostent* h = gethostbyname("xrootd.t2.ucsd.edu");
93  if (!h) {
94  std::cerr << "Can't get gost ip \n";
95  exit(1);
96  }
97 
98  struct sockaddr_in remoteServAddr;
99  remoteServAddr.sin_family = h->h_addrtype;
100  memcpy((char*)&remoteServAddr.sin_addr.s_addr, h->h_addr_list[0], h->h_length);
101  remoteServAddr.sin_port = htons(9699);
102 
103  Bytef* buff;
104  unsigned long buffSize;
105  getCompressedBuffer(argv[1], &buff, buffSize);
106 
107  sendto(sd, buff, buffSize, 0, (struct sockaddr*)&remoteServAddr, sizeof(remoteServAddr));
108 
109  free(buff);
110 }
void getCompressedBuffer(const char *fname, Bytef **buffPtr, unsigned long &zippedSize)
void free(void *ptr) noexcept
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
def exit(msg="")