コード例 #1
0
static void adapter_step() {

   fd_set set[1];
   int fd_max;
   int val;

   // process buffered lines

   while (io_line_ready(XBoard->io)) xboard_step(); // process available xboard lines
   while (io_line_ready(Engine->io)) engine_step(); // process available engine lines

   // init

   FD_ZERO(set);
   fd_max = -1; // HACK

   // add xboard input

   ASSERT(XBoard->io->in_fd>=0);

   FD_SET(XBoard->io->in_fd,set);
   if (XBoard->io->in_fd > fd_max) fd_max = XBoard->io->in_fd;

   // add engine input

   ASSERT(Engine->io->in_fd>=0);

   FD_SET(Engine->io->in_fd,set);
   if (Engine->io->in_fd > fd_max) fd_max = Engine->io->in_fd;

   // wait for something to read (no timeout)

   ASSERT(fd_max>=0);

   val = select(fd_max+1,set,NULL,NULL,NULL);
   if (val == -1 && errno != EINTR) my_fatal("adapter_step(): select(): %s\n",strerror(errno));

   if (val > 0) {
      if (FD_ISSET(XBoard->io->in_fd,set)) io_get_update(XBoard->io); // read some xboard input
      if (FD_ISSET(Engine->io->in_fd,set)) io_get_update(Engine->io); // read some engine input
   }
}
コード例 #2
0
void engine_get(engine_t * engine, char string[], int size) {

   ASSERT(engine_is_ok(engine));
   ASSERT(string!=NULL);
   ASSERT(size>=256);

   while (!io_line_ready(engine->io)) {
      io_get_update(engine->io);
   }

   if (!io_get_line(engine->io,string,size)) { // EOF
      exit(EXIT_SUCCESS);
   }
}
コード例 #3
0
ファイル: pipex_posix.c プロジェクト: niklasf/polyglot
bool pipex_readln(pipex_t *pipex, char *string){
    while (!io_line_ready(pipex->io)) {
	io_get_update(pipex->io);
   }
   if (!io_get_line(pipex->io,string,StringSize)) { // EOF
       string[0]='\0';
       pipex->state|=PIPEX_EOF;
       return FALSE;
   }
   if(strncmp(PIPEX_MAGIC,string,strlen(PIPEX_MAGIC))==0){
     my_fatal("%s\n",string+strlen(PIPEX_MAGIC)+1);
   }

   return TRUE;
}
コード例 #4
0
ファイル: pipex_posix.c プロジェクト: niklasf/polyglot
bool pipex_readln_nb(pipex_t *pipex, char *string){

    while(!pipex->io->in_eof && !io_line_ready(pipex->io) && io_peek(pipex->io)){
      io_get_update(pipex->io);
  }
  
  if(io_line_ready(pipex->io)){
    return pipex_readln(pipex,string);
  }else if(pipex->io->in_eof){
    string[0]='\0';
    pipex->state|=PIPEX_EOF;
    return FALSE;
  }else {  
    string[0]='\0';
    return FALSE;
  }
}
コード例 #5
0
ファイル: io.c プロジェクト: paly2/NetPipes
void io_get(io_t * io, char string[]) {
    int src, dst;
    char c;

    src = 0;
    dst = 0;

    io_get_update(io); // first, call io_get_update

    while (1) {
        // test for end of buffer
        if (src >= io->in_size) {
            string[0] = '\0';
            return;
        }

        // test for end of string
        if (dst >= STRING_SIZE) {
            printf("io_get_line(): buffer overflow\n");
            exit(EXIT_FAILURE);
        }

        // copy the next character
        c = io->in_buffer[src++];

        if (c == '\n') { // '\n' => line complete
            string[dst] = '\0';
            break;
        }
        else if (c != '\r') { // skip '\r's
            string[dst++] = c;
        }
    }

    // shift the buffer
    io->in_size -= src;
    memmove(&io->in_buffer[0], &io->in_buffer[src], io->in_size);
}
コード例 #6
0
ファイル: pipex_posix.c プロジェクト: niklasf/polyglot
void pipex_wait_event(pipex_t *pipex[]){

    fd_set set[1];
    pipex_t *p;
    int fd_max;
    int val;
    pipex_t **q;

    q=pipex;

        // init

   FD_ZERO(set);
   fd_max = -1; // HACK
   while((p=*(q++))!=NULL){
       ASSERT(p->io->in_fd>=0);
       FD_SET(p->io->in_fd,set);
       if (p->io->in_fd > fd_max){
           fd_max = p->io->in_fd;
       }
   }
   
   // wait for something to read (no timeout)

   ASSERT(fd_max>=0);
   val = select(fd_max+1,set,NULL,NULL,NULL);
   if (val == -1 && errno != EINTR) my_fatal("pipex_wait_event(): select(): %s\n",strerror(errno));

   q=pipex;
   if (val > 0) {
       while((p=*(q++))!=NULL){
           if (FD_ISSET(p->io->in_fd,set) /*&& !io_line_ready(p->io)*/){
	       io_get_update(p->io); 
	   }
       }
   }    
}