test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Macros | Functions
cmsShowSendReport.cc File Reference
#include <stdio.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include "zlib.h"
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <string.h>
#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

#define BUFLEN   60000

Definition at line 12 of file cmsShowSendReport.cc.

Function Documentation

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

Definition at line 20 of file cmsShowSendReport.cc.

References ecal_dqm_sourceclient-live_cfg::cerr, cmsRelvalreport::exit, NULL, and query::result.

Referenced by main().

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

Definition at line 63 of file cmsShowSendReport.cc.

References ecal_dqm_sourceclient-live_cfg::cerr, cmsRelvalreport::exit, getCompressedBuffer(), h, and sd.

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