Exemple #1
0
void *Relay(void *inarg)
{
  channels_t *ch = (channels_t *)inarg;
  int term = 0;
  int id = ch->id;
  char *item;
  lpel_stream_desc_t *in, *out;

  in = LpelStreamOpen(ch->in, 'r');
  out = LpelStreamOpen(ch->out, 'w');

  printf("Relay %d START\n", id);

  while (!term) {
    item = LpelStreamRead( in);
    assert( item != NULL );
    //printf("Relay %d: %s", id, item );
    if ( 0 == strcmp( item, "T\n")) {
      term = 1;
    }
    LpelStreamWrite( out, item);
  } // end while
  LpelStreamClose( in, 1);
  LpelStreamClose( out, 0);
  //free(ch);
  SCCFreePtr(ch);
  printf("Relay %d TERM\n", id);
  return NULL;
}
Exemple #2
0
static void *Outputter(void *arg)
{
  lpel_stream_desc_t *in = LpelStreamOpen((lpel_stream_t*)arg, 'r'); 
  char *item;
  int term = 0;

  printf("Outputter START\n");

  while (!term) {
    item = LpelStreamRead(in);
    assert( item != NULL );
    printf("\n\n*************************************\nOut: %s\n*************************************\n", item );

    if ( 0 == strcmp( item, "T\n")) {
      term = 1;
    }
    //free( item);
	SCCFreePtr(item);
  } // end while

  LpelStreamClose( in, 1);
  printf("Outputter TERM\n");

  LpelStop();
  return NULL;
}
Exemple #3
0
void *Relay(void *inarg)
{
  void *item;
  char *msg;
  int i, dest;
  lpel_stream_desc_t *out[NUM_COLL];
  lpel_stream_desc_t *in;
  int term = 0;

  printf("start Relay\n" );

  /* open streams */
  for (i=0; i<NUM_COLL; i++) {
    out[i] = LpelStreamOpen(scoll[i], 'w');
  }
  in = LpelStreamOpen(sinp, 'r');

  /* main task: relay to consumer via defined stream */
  while( !term) {
    item = LpelStreamRead(in);
    assert( item != NULL );
    msg = (char *)item;
    if  ( 0 == strcmp( msg, "T\n" ) ) {
      term = 1;
      dest = 0;
    } else {
      dest = atoi(msg);
    }
    if ( 0<dest && dest<NUM_COLL) {
      LpelStreamWrite( out[dest], item);
      printf("Relay dest: %d\n", dest);
    }
  }
  /* terminate msg goes to 0 */
  assert( dest==0 );
  printf("Relay dest: %d\n", dest);

  /* relay to all, close streams */
  for (i=0; i<NUM_COLL; i++) {
    LpelStreamWrite( out[i], item);
    LpelStreamClose( out[i], 0);
  }
  LpelStreamClose(in, 1);
  printf("exit Relay\n" );
  return NULL;
}
Exemple #4
0
void SNetStreamClose(snet_stream_desc_t * sd, int destroy_stream)
{
  if (destroy_stream) {
    /* also need to destroy the usrdata */
    DestroyUsrdata(LpelStreamGet((lpel_stream_desc_t *) sd));
  }
  LpelStreamClose((lpel_stream_desc_t *) sd, destroy_stream);
}
Exemple #5
0
void *Consumer(void *inarg)
{
  char *msg;
  int i, term;
  lpel_streamset_t lst = NULL;
  lpel_stream_iter_t *iter;

  printf("start Consumer\n" );
  /* open streams */
  for (i=0; i<NUM_COLL; i++) {
    LpelStreamsetPut( &lst, LpelStreamOpen(scoll[i], 'r'));
  }

  iter = LpelStreamIterCreate(&lst);

  term = 0;
  do {
    /* here we do wait */
    printf("Consumer poll\n");
    LpelStreamPoll( &lst);
    printf("Consumer resumes\n");

    printf("Consumer iterates:\n");
    LpelStreamIterReset(iter, &lst);
    while( LpelStreamIterHasNext(iter)) {
      lpel_stream_desc_t *snext = LpelStreamIterNext(iter);
      if ( NULL != LpelStreamPeek( snext )) {
        msg = (char *) LpelStreamRead( snext);
        if (0 == strcmp( msg, "T\n" )) {
          term=1;
        } else {
          printf("%s", msg );
          free(msg);
        }
      }
    }
    //sleep(5);
  } while (0 == term) ;

  /* print & free termination message */
  printf("%s", msg );
  free(msg);

  /* close streams */
  LpelStreamIterReset(iter, &lst);
  while( LpelStreamIterHasNext(iter)) {
    lpel_stream_desc_t *snext = LpelStreamIterNext(iter);
    LpelStreamClose( snext, 1);
  }
  LpelStreamIterDestroy( iter);
  printf("exit Consumer\n" );

  LpelStop();
  return NULL;
}
Exemple #6
0
static void *Inputter(void *arg)
{
  lpel_stream_desc_t *out = LpelStreamOpen((lpel_stream_t*)arg, 'w');
  char *buf;

  do {
    buf = fgets( malloc( 120 * sizeof(char) ), 119, stdin  );
    LpelStreamWrite( out, buf);
  } while ( buf[0] != 'T') ;

  LpelStreamClose( out, 0);
  printf("exit Inputter\n" );
  return NULL;
}
Exemple #7
0
static void *Inputter(void *arg)
{
  lpel_stream_desc_t *out = LpelStreamOpen((lpel_stream_t*)arg, 'w'); 
  char *buf;

  printf("\nInputter START\n\n");
  do {
    //buf = fgets( malloc( 120 * sizeof(char) ), 119, stdin  );
   
   buf = fgets( SCCMallocPtr( 120 * sizeof(char) ), 119, stdin  ); 
   printf("\nLPEL STREAM WRITE\n\n");
   LpelStreamWrite( out, buf);
  } while ( 0 != strcmp(buf, "T\n") );

  LpelStreamClose( out, 0);
  printf("\nInputter TERM\n\n");
  return NULL;
}