Exemple #1
0
// arguments:
// 1. RowTerm
// 2. string data
static int lua_RoteTerm_inject(lua_State* L) {
    RoteTerm* rt = lua_RoteTerm_self(L, 1);
    size_t length;
    const char* data = luaL_checklstring(L, 2, &length);
    rote_vt_inject(rt, data, length);
    return 0;
}
Exemple #2
0
void rote_vt_update(RoteTerm *rt) {
   fd_set ifs;
   struct timeval tvzero;
   char buf[512];
   int bytesread;
   int n = ROTE_VT_UPDATE_ITERATIONS;
   if (rt->pd->pty < 0) return;  /* nothing to pump */

   while (n--) { /* iterate at most ROVE_VT_UPDATE_ITERATIONS times.
                  * As Phil Endecott pointed out, if we don't restrict this,
                  * a program that floods the terminal with output
                  * could cause this loop to iterate forever, never
                  * being able to catch up. So we'll rely on the client
                  * calling rote_vt_update often, as the documentation
                  * recommends :-) */

      /* check if pty has something to say */
      FD_ZERO(&ifs); FD_SET(rt->pd->pty, &ifs);
      tvzero.tv_sec = 0; tvzero.tv_usec = 0;
   
      if (select(rt->pd->pty + 1, &ifs, NULL, NULL, &tvzero) <= 0)
         return; /* nothing to read, or select() failed */

      /* read what we can. This is guaranteed not to block, since
       * select() told us there was something to read. */
      bytesread = read(rt->pd->pty, buf, 512);
      if (bytesread <= 0) return;   

      /* inject the data into the terminal */
      rote_vt_inject(rt, buf, bytesread);
   }
}
Exemple #3
0
void rote_vt_write(RoteTerm *rt, const char *data, int len) {
   if (rt->pd->pty < 0) {
      /* no pty, so just inject the data plain and simple */
      rote_vt_inject(rt, data, len);
      return;
   }

   /* write data to pty. Keep calling write() until we have written
    * everything. */
   while (len > 0) {
      int byteswritten = write(rt->pd->pty, data, len);
      if (byteswritten < 0) {
         /* very ugly way to inform the error. Improvements welcome! */
         static char errormsg[] = "\n(ROTE: pty write() error)\n";
         rote_vt_inject(rt, errormsg, strlen(errormsg));
         return;
      }

      data += byteswritten;
      len  -= byteswritten;
   }
}
Exemple #4
0
int update_terminal(void *data)
{
    while(1)
    {
      moomoo * d = (moomoo *)data;
      char buf[512];
      int br=-1;
//     printf("UNLOCKED SELECT\n");
      rote_vt_update_thready(buf, 512, &br, d->t);
//     printf("*end SELECT, locking %i*\n", d->lock);
        _mutexP(d->lock);
//        printf("LOCKED\n");

      if (br>0)
      {
        /* inject the data into the terminal */
//        printf("*locked injecting\n");
	rote_vt_inject(d->t, buf, br);
//        printf("*locked injected\n");
	SDL_Event e;
	e.type=SDL_USEREVENT;
	e.user.code=0;
	SDL_PushEvent(&e);
      }
      
      if(!d->t->childpid)
      {
        printf("Segmentation Fault\n");
	SDL_Event e;
	e.type=SDL_USEREVENT;
	e.user.code=1;
	e.user.data1=d->t;
	SDL_PushEvent(&e);
        _mutexV(d->lock);
	return 777;
      }
      _mutexV(d->lock);

     }
      return 666;
}
Exemple #5
0
int update_terminal(void *data)
{
	while(20)
	{
	    moomoo * d = (moomoo *)data;
	    char buf[123456];
	    int br=-1;
	    //logit("UNLOCKED SELECT\n");
	    rote_vt_update_thready(buf, 123456, &br, d->t);
	    //logit("*end SELECT, locking %i*\n", d->lock);
	    _mutexP(d->lock);
	    //logit("LOCKED\n");
	    if (br>0)
	    {
	        //logit("*locked injecting\n");
	        rote_vt_inject(d->t, buf, br);
	        //logit("*locked injected\n");
	        SDL_Event e;
	        e.type=SDL_USEREVENT;
	        e.user.code=CODE_DATA;
	        e.user.data1=d->t;
	        SDL_PushEvent(&e);
	        //wake up main thread.
	    }
	    if(!d->t->childpid)
	    {	//our child died
	        SDL_Event e;
	        e.type=SDL_USEREVENT;
	        e.user.code=CODE_QUIT;
	        e.user.data1=d->t;
	        SDL_PushEvent(&e);
	        _mutexV(d->lock);
	        return 666;
	    }
	    _mutexV(d->lock);
	}
	return 69;
}