Beispiel #1
0
static void *receiverThread(void *arg) {
    int listenfd=0, handle, status, nevents, nwords, *ip;
    int i;
    uint32_t dictLen, buffer[2048];
    char *dict;
    struct sockaddr_in cliaddr;
    socklen_t len = sizeof(cliaddr);
    
printf("Receiver thread: listen on server socket\n");

    /* open a listening socket */
    listenfd = tcp_listen(serverPort, bufferSize);
    if (listenfd < 0) {
        printf("Error starting listening socket\n");
        exit(1);
    }

    /* wait for connection to client */
printf("Receiver thread: accepting\n");
    recvFd = Accept(listenfd, (SA *) &cliaddr, &len);
    if (recvFd < 0) {
        printf("Error receiving client TCP connection\n");
        exit(1);
    }
    
printf("Receiver thread: got client ... \n");
    status = evOpenSocket(recvFd, "r", &handle);
printf ("Receiver thread: Opened socket, status = %#x\n", status);

     status = evGetDictionary(handle, &dict, &dictLen);
printf ("Receiver thread: get dictionary, status = %#x\n\n", status);

     if (dictionary != NULL) {
         printf("DICTIONARY =\n%s\n", dict);
         free(dict);
     }

     nevents = 0;
    
     while (1) {

//printf("Receiver thread: Waiting on evRead\n");
         if ((status = evRead(handle, buffer, 2048)) != S_SUCCESS) {
             printf("Receiver thread: Done reading\n");
             break;
         }
         
         nevents++;
        
         printf("Receiver thread: Read event #%d,  len = %d data words\n", nevents, buffer[0] - 1);

         ip = buffer;
         nwords = buffer[0] + 1;
        
         printf("      Header words\n");
         printf("        %#10.8x\n", *ip++);
         printf("        %#10.8x\n\n", *ip++);
         printf("      Data words\n");
   
         nwords -= 2;
        
         for (; nwords > 0; nwords-=4) {
             for (i = MIN(nwords,4); i > 0; i--) {
                 printf("        %#10.8x", *ip++);
             }
             printf("\n");
         }
         printf("\n");
     }
    
printf("\nReceiver thread: Last read, status = %x\n", status);
    if (status == EOF) {
        printf("Receiver thread: Last read, reached EOF!\n");
    }
    
    status = evClose(handle);
    printf ("Receiver thread: Closed socket, status = %#x\n\n", status);
}
Beispiel #2
0
int main (int argc, char **argv)
{
    int i, handle, nevents, status, bufLen, nWords, dLen, version;
    uint32_t *buf, *ip;
    char *dictionary = NULL;


    if (argc != 2) {
        printf("Incorrect number of arguments:\n");
        printf("  usage: %s filename\n", argv[0]);
        exit(-1);
    }

    if ( (status = evOpen(argv[1], "r", &handle)) < 0) {
        printf("Unable to open file %s status = %d\n",argv[1],status);
        exit(-1);
    } else {
        printf("Opened %s for reading, hit <enter> to see each individual event\n\n",argv[1]);
    }

    /* Get evio version # of file */
    status = evIoctl(handle, "v", &version);
    if (status == S_SUCCESS) {
        printf("Evio file version = %d\n", version);
    }

    /* Get a dictionary if there is one */
    status = evGetDictionary(handle, &dictionary, &dLen);
    if (status == S_SUCCESS && dictionary != NULL) {
        printf("Dictionary =\n%s\n\n", dictionary);
        free(dictionary);
    }

    nevents=0;
    while ((status = evReadAlloc(handle, &buf, &bufLen))==0) {
        nevents++;
        printf("    Event #%d,  len = %d words\n", nevents, buf[0]);
        nWords = buf[0] + 1;

        for (ip=buf; nWords > 0; nWords-=4) {
            for (i = MIN(nWords,4); i > 0; i--) {
                printf("      %#10.8x", *ip++);
            }
            printf("\n");
        }
       
        printf("\n");

        free(buf);
        printf("Hit enter for next event\n");
        getc(stdin);
    }

    if ( status == EOF ) {
        printf("Hit end-of-file\n");
    }
    else {
        printf("Error reading file, quit\n");
    }
    evClose(handle);
  
    exit(0);
}