예제 #1
0
int SVUnixOpMonitor::telnetOpen()
{
	int nResult;

	nResult=telnetinit();
	if(SVFAILED(nResult)) return nResult;
	for(int nLoop=0;nLoop<2;nLoop++  )
	{
		nResult=telnet_connect();

		if(!SVFAILED(nResult)) break;
	}
	if(SVFAILED(nResult)) return nResult;
	/*
	nResult=telnet_command();
	if(SVFAILED(nResult)) return nResult;*/
	return TELNETSUCCESS;

}
예제 #2
0
/* devread */ /*{{{*/
static int devread(struct Device *r)
{
  char c;

  if (r->socket) /* socket */ /*{{{*/
  {
    struct sockaddr remote;
    size_t remotelen=sizeof(remote);

    while (!r->connected) if ((r->fd2=accept(r->fd,&remote,&remotelen))!=-1) 
    {
      if (!(r->connected=telnetinit(r->fd2))) return 26;
    }
    if (read(r->fd2,&c,1)==1) return c;
    else { r->connected=0; close(r->fd2); return 26; }
  }
  /*}}}*/
  else /* file */ /*{{{*/
  {
    if (read(r->fd,&c,1)==0) return 26;
    else return c;
  }
  /*}}}*/
}
예제 #3
0
/* devwrite */ /*{{{*/
static void devwrite(struct Device *r, char c)
{
  if (r->socket) /* socket */ /*{{{*/
  {
    struct sockaddr remote;
    size_t remotelen=sizeof(remote);
    fd_set s;
    struct timeval t;

    if (!r->connected)
    {
      FD_ZERO(&s);
      FD_SET(r->fd,&s);
      t.tv_sec=0;
      t.tv_usec=(benice>=BENICE ? NICESLEEP : 0);
      if (select(r->fd+1,&s,(fd_set*)0,(fd_set*)0,&t)==1)
      {
        if ((r->fd2=accept(r->fd,&remote,&remotelen))==-1)
        {
          if (benice<BENICE) ++benice;
          return;
        }
        if (!(r->connected=telnetinit(r->fd2))) return;
      }
      else { if (benice<BENICE) ++benice; return; }
    }
    if (r->connected) write(r->fd2,&c,1);
  }
  /*}}}*/
  else /* file */ /*{{{*/
  {
    write(r->fd,&c,1);
  }
  /*}}}*/
  benice=0;
}
예제 #4
0
/* devready */ /*{{{*/
static int devready(struct Device *r)
{
  fd_set s;
  struct timeval t;

  if (r->fd==-1) return 0;
  if (r->socket) /* socket */ /*{{{*/
  {
    struct sockaddr remote;
    size_t remotelen=sizeof(remote);

    if (!r->connected)
    {
      FD_ZERO(&s);
      FD_SET(r->fd,&s);
      t.tv_sec=0;
      t.tv_usec=(benice>=BENICE ? NICESLEEP : 0);
      if (select(r->fd+1,&s,(fd_set*)0,(fd_set*)0,&t)==1)
      {
        if ((r->fd2=accept(r->fd,&remote,&remotelen))==-1)
        {
          if (benice<BENICE) ++benice;
          return 0;
        }
        if (!(r->connected=telnetinit(r->fd2))) return 0;
      }
      else { if (benice<BENICE) ++benice; return 0; }
    }
    FD_ZERO(&s);
    FD_SET(r->fd2,&s);
    t.tv_sec=0;
    t.tv_usec=(benice>=BENICE ? NICESLEEP : 0);
    if (select(r->fd2+1,&s,(fd_set*)0,(fd_set*)0,&t)==1)
    {
      benice=0;
      return 0xff;
    }
    else
    {
      if (benice<BENICE) ++benice;
      return 0;
    }
  }
  /*}}}*/
  else /* file */ /*{{{*/
  {
    FD_ZERO(&s);
    FD_SET(r->fd,&s);
    t.tv_sec=0;
    t.tv_usec=(benice>=BENICE ? NICESLEEP : 0);
    if (select(r->fd+1,&s,(fd_set*)0,(fd_set*)0,&t)==1)
    {
      benice=0;
      return 0xff;
    }
    else
    {
      if (benice<BENICE) ++benice;
      return 0;
    }
  }
  /*}}}*/
}