示例#1
0
文件: check_hrc.c 项目: foliern/lpel
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;
}
示例#2
0
/**
 * Non-blocking write to a stream
 *
 * @param sd    stream descriptor
 * @param item  data item (a pointer) to write
 * @pre         current task is single writer
 * @pre         item != NULL
 * @return 0 if the item could be written, -1 if the stream was full
 */
int LpelStreamTryWrite( lpel_stream_desc_t *sd, void *item)
{
  if (!LpelBufferIsSpace(&sd->stream->buffer)) {
    return -1;
  }
  LpelStreamWrite( sd, item );
  return 0;
}
示例#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;
}
示例#4
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;
}
示例#5
0
文件: check_hrc.c 项目: foliern/lpel
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;
}
示例#6
0
void SNetStreamWrite(snet_stream_desc_t * sd, void *item)
{
  LpelStreamWrite((lpel_stream_desc_t *) sd, item);
}