Example #1
0
int main(void) {
  dyad_Stream *s;
  dyad_init();

  s = dyad_newStream();
  dyad_addListener(s, DYAD_EVENT_ERROR,  onError,  NULL);
  dyad_addListener(s, DYAD_EVENT_ACCEPT, onAccept, NULL);
  dyad_listen(s, 8000);

  while (dyad_getStreamCount() > 0) {
    dyad_update();
  }

  return 0;
}
Example #2
0
static void* tcpThread(void* data) {
    UNUSED(data);

    dyad_init();
    dyad_setTickInterval(0.2f);
    dyad_setUpdateTimeout(0.5f);

    while (workerRunning) {
        dyad_update();
    }

    dyad_shutdown();
    printf("tcpThread end!!\n");
    return NULL;
}
Example #3
0
int main(void) {
  dyad_Stream *s;
  dyad_init();

  s = dyad_newStream();
  dyad_addListener(s, DYAD_EVENT_CONNECT, onConnect, NULL);
  dyad_addListener(s, DYAD_EVENT_ERROR,   onError,   NULL);
  dyad_addListener(s, DYAD_EVENT_DATA,    onData,    NULL);
  dyad_connect(s, "time-nw.nist.gov", 13);

  while (dyad_getStreamCount() > 0) {
    dyad_update();
  }
  
  dyad_shutdown();
  return 0;
}
Example #4
0
/// \brief  Main executable
/// \return 0
int main()
{
    srand((int)time(0));
    initscr();
    clear();
    curs_set(0);
    noecho();
    raw();
    if(has_colors())start_color();
    settings();
    dyad_init();
    pthread_attr_init (&AThread);
    pthread_attr_setdetachstate (&AThread, PTHREAD_CREATE_JOINABLE);
    bool cho=true;
    while(cho){
        pthread_mutex_init (&MBoard, NULL);
        pthread_cond_init (&CBoard, NULL);
        pthread_mutex_init (&MInfo, NULL);
        pthread_cond_init (&CInfo, NULL);
        pthread_mutex_init (&MScr, NULL);
        pthread_mutex_init (&MNet, NULL);
        pthread_mutex_init (&MNetC, NULL);
        pthread_cond_init (&CNet, NULL);
        Clrboard(curs);
        welcome();
        if(isnetworking){
            dyad_setUpdateTimeout(0.05);
            pthread_create (&TNetworkPlay, &AThread, t_NetworkPlay, NULL);
            while (dyad_getStreamCount() > 0 && isconnected) {
                pthread_mutex_lock(&MNet);
                dyad_update();
                pthread_mutex_unlock(&MNet);
                usleep(10000);
            }
            if(result){
                if(score[0]>score[1])
					c_info("You Win!");
				else if(score[0]<score[1])
					c_info("You Lost!");
				else
					c_info("Neck and neck!");
                pthread_cancel(TNetworkPlay);
                pthread_join(TNetworkPlay, NULL);
                pthread_cancel(TNetworkSend);
                pthread_cancel(TNetworkShow);
                pthread_cond_signal (&CBoard);
                pthread_cond_signal (&CNet);
                pthread_join(TNetworkSend, NULL);
                pthread_join(TNetworkShow, NULL);
                pthread_cancel(TInfo);
                pthread_cond_signal (&CInfo);
                pthread_join(TInfo, NULL);
                getch();
            }
            cho=0;
        }else{
            cho=play();
        }
        if(result){
            pthread_mutex_destroy (&MScr);
            pthread_mutex_destroy (&MInfo);
            pthread_cond_destroy (&CInfo);
            pthread_mutex_destroy (&MBoard);
            pthread_cond_destroy (&CBoard);
            pthread_mutex_destroy (&MNet);
            pthread_mutex_destroy (&MNetC);
            pthread_cond_destroy (&CNet);
        }
    }
    if(result){c_forceQuit();}
    return 0;
}
Example #5
0
		static void init() {
			dyad_init();
		}