#include <pthread.h>
#include "common.h"

void* echo( void* ps ) {
    int sc = *(int*)ps;
    sched_yield();
    retrans( sc );
    close( sc );
    if( debug ) cout << "*" << flush;                      
    return NULL;
}
    
// ретранслятор c pthread_create по запросу
int main( int argc, char *argv[] ) {
   int ls = getsocket( THREAD_PORT ), rs;
   setv( argc, argv );
   while( true ) {
      pthread_t tid;
      if( ( rs = accept( ls, NULL, NULL ) ) < 0 ) errx( "accept error" ); 
      if( pthread_create( &tid, NULL, &echo, &rs ) != EOK ) errx( "thread create error" );
      sched_yield();       
   };
   exit( EXIT_SUCCESS );
};

