public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] Redboot: net_io_getc_nonblock not setting return value?
@ 2001-02-09  9:32 Grant Edwards
  2001-02-09  9:52 ` Jonathan Larmour
  0 siblings, 1 reply; 4+ messages in thread
From: Grant Edwards @ 2001-02-09  9:32 UTC (permalink / raw)
  To: ecos-discuss

I'm getting a compiler warning about net_io_getc_nonblock not
returning a value.  The routine looks like this:

   160	static cyg_bool
   161	net_io_getc_nonblock(void* __ch_data, cyg_uint8* ch)
   162	{
   163	    if (_net_io_getc_nonblock(__ch_data, ch)) {
   164	        if (*ch == TELNET_IAC) {
   165	            cyg_uint8 esc;
   166	            // Telnet escape - need to read/handle more
   167	            while (!_net_io_getc_nonblock(__ch_data, &esc)) ;
   168	            if (esc == TELNET_IP) {
   169	                // Special case for ^C == Interrupt Process
   170	                *ch = 0x03;  
   171	                // Just in case the other end needs synchronizing
   172	                net_io_putc(__ch_data, TELNET_IAC);
   173	                net_io_putc(__ch_data, TELNET_WONT);
   174	                net_io_putc(__ch_data, TELNET_TM);
   175	                net_io_flush();
   176	                return true;
   177	            }
   178	            if (esc == TELNET_DO) {
   179	                // Telnet DO option
   180	                while (!_net_io_getc_nonblock(__ch_data, &esc)) ;                
   181	                // Respond with WONT option
   182	                net_io_putc(__ch_data, TELNET_IAC);
   183	                net_io_putc(__ch_data, TELNET_WONT);
   184	                net_io_putc(__ch_data, esc);
   185	                return false;  // Ignore this whole thing!
   186	            }
   187	        }
   188	    } else {
   189	        return false;
   190	    }
   191	}

Should there be a "return true;" either between lines 187/188
or just before the final brace at line 191?

-- 
Grant Edwards
grante@visi.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [ECOS] Redboot: net_io_getc_nonblock not setting return value?
  2001-02-09  9:32 [ECOS] Redboot: net_io_getc_nonblock not setting return value? Grant Edwards
@ 2001-02-09  9:52 ` Jonathan Larmour
  2001-02-09 10:09   ` Grant Edwards
  0 siblings, 1 reply; 4+ messages in thread
From: Jonathan Larmour @ 2001-02-09  9:52 UTC (permalink / raw)
  To: Grant Edwards; +Cc: ecos-discuss

Grant Edwards wrote:
> 
> I'm getting a compiler warning about net_io_getc_nonblock not
> returning a value.  The routine looks like this:
> 
>    160  static cyg_bool
>    161  net_io_getc_nonblock(void* __ch_data, cyg_uint8* ch)
>    162  {
>    163      if (_net_io_getc_nonblock(__ch_data, ch)) {
>    164          if (*ch == TELNET_IAC) {
>    165              cyg_uint8 esc;
>    166              // Telnet escape - need to read/handle more
>    167              while (!_net_io_getc_nonblock(__ch_data, &esc)) ;
>    168              if (esc == TELNET_IP) {
>    169                  // Special case for ^C == Interrupt Process
>    170                  *ch = 0x03;
>    171                  // Just in case the other end needs synchronizing
>    172                  net_io_putc(__ch_data, TELNET_IAC);
>    173                  net_io_putc(__ch_data, TELNET_WONT);
>    174                  net_io_putc(__ch_data, TELNET_TM);
>    175                  net_io_flush();
>    176                  return true;
>    177              }
>    178              if (esc == TELNET_DO) {
>    179                  // Telnet DO option
>    180                  while (!_net_io_getc_nonblock(__ch_data, &esc)) ;
>    181                  // Respond with WONT option
>    182                  net_io_putc(__ch_data, TELNET_IAC);
>    183                  net_io_putc(__ch_data, TELNET_WONT);
>    184                  net_io_putc(__ch_data, esc);
>    185                  return false;  // Ignore this whole thing!
>    186              }
>    187          }
>    188      } else {
>    189          return false;
>    190      }
>    191  }
> 
> Should there be a "return true;" either between lines 187/188
> or just before the final brace at line 191?

It should probably just have a default return false at the end. i.e. just

>    187          }
>    188      }
>    189      return false;
>    191  }

I'll change it.

Jifl
-- 
Red Hat, Rustat House, Clifton Road, Cambridge, UK. Tel: +44 (1223) 271062
Maybe this world is another planet's Hell -Aldous Huxley || Opinions==mine

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [ECOS] Redboot: net_io_getc_nonblock not setting return value?
  2001-02-09  9:52 ` Jonathan Larmour
@ 2001-02-09 10:09   ` Grant Edwards
  2001-02-09 10:26     ` Jonathan Larmour
  0 siblings, 1 reply; 4+ messages in thread
From: Grant Edwards @ 2001-02-09 10:09 UTC (permalink / raw)
  To: Jonathan Larmour; +Cc: ecos-discuss

On Fri, Feb 09, 2001 at 05:52:23PM +0000, Jonathan Larmour wrote:

> >    160  static cyg_bool
> >    161  net_io_getc_nonblock(void* __ch_data, cyg_uint8* ch)
> >    162  {
> >    163      if (_net_io_getc_nonblock(__ch_data, ch)) {
> >    164          if (*ch == TELNET_IAC) {
> >    165              cyg_uint8 esc;
> >    166              // Telnet escape - need to read/handle more
> >    167              while (!_net_io_getc_nonblock(__ch_data, &esc)) ;
> >    168              if (esc == TELNET_IP) {
> >    169                  // Special case for ^C == Interrupt Process
> >    170                  *ch = 0x03;
> >    171                  // Just in case the other end needs synchronizing
> >    172                  net_io_putc(__ch_data, TELNET_IAC);
> >    173                  net_io_putc(__ch_data, TELNET_WONT);
> >    174                  net_io_putc(__ch_data, TELNET_TM);
> >    175                  net_io_flush();
> >    176                  return true;
> >    177              }
> >    178              if (esc == TELNET_DO) {
> >    179                  // Telnet DO option
> >    180                  while (!_net_io_getc_nonblock(__ch_data, &esc)) ;
> >    181                  // Respond with WONT option
> >    182                  net_io_putc(__ch_data, TELNET_IAC);
> >    183                  net_io_putc(__ch_data, TELNET_WONT);
> >    184                  net_io_putc(__ch_data, esc);
> >    185                  return false;  // Ignore this whole thing!
> >    186              }
> >    187          }
> >    188      } else {
> >    189          return false;
> >    190      }
> >    191  }
> > 
> > Should there be a "return true;" either between lines 187/188
> > or just before the final brace at line 191?
> 
> It should probably just have a default return false at the end. i.e. just
> 
> >    187          }
> >    188      }
> >    189      return false;
> >    191  }
> 
> I'll change it.

I'm confused.  Why is it false and not true?  How would reading
a normal character ever return a true status?

My brain can't handle things nested too deeply -- especially w/
K&R brace placement ;).  I ended up fixing my copy like this:

static cyg_bool
net_io_getc_nonblock(void* __ch_data, cyg_uint8* ch)
{
	cyg_uint8 esc;
	
	if (!_net_io_getc_nonblock(__ch_data, ch))
		return false;

	if (*ch != TELNET_IAC)
		return true;
	  
	// Telnet escape - need to read/handle more

	while (!_net_io_getc_nonblock(__ch_data, &esc)) ;
	
	if (esc == TELNET_IP) {
		// Special case for ^C == Interrupt Process
		*ch = 0x03;  
		// Just in case the other end needs synchronizing
		net_io_putc(__ch_data, TELNET_IAC);
		net_io_putc(__ch_data, TELNET_WONT);
		net_io_putc(__ch_data, TELNET_TM);
		net_io_flush();
		return true;
	}
	else if (esc == TELNET_DO) {
		// Telnet DO option
		while (!_net_io_getc_nonblock(__ch_data, &esc)) ;                
		// Respond with WONT option
		net_io_putc(__ch_data, TELNET_IAC);
		net_io_putc(__ch_data, TELNET_WONT);
		net_io_putc(__ch_data, esc);
		return false;  // Ignore this whole thing!
	}

	return false;
}


-- 
Grant Edwards
grante@visi.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [ECOS] Redboot: net_io_getc_nonblock not setting return value?
  2001-02-09 10:09   ` Grant Edwards
@ 2001-02-09 10:26     ` Jonathan Larmour
  0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Larmour @ 2001-02-09 10:26 UTC (permalink / raw)
  To: Grant Edwards; +Cc: ecos-discuss

Grant Edwards wrote:
> 
> On Fri, Feb 09, 2001 at 05:52:23PM +0000, Jonathan Larmour wrote:
> 
> > >    160  static cyg_bool
> > >    161  net_io_getc_nonblock(void* __ch_data, cyg_uint8* ch)
> > >    162  {
> > >    163      if (_net_io_getc_nonblock(__ch_data, ch)) {
> > >    164          if (*ch == TELNET_IAC) {
> > >    165              cyg_uint8 esc;
> > >    166              // Telnet escape - need to read/handle more
> > >    167              while (!_net_io_getc_nonblock(__ch_data, &esc)) ;
> > >    168              if (esc == TELNET_IP) {
> > >    169                  // Special case for ^C == Interrupt Process
> > >    170                  *ch = 0x03;
> > >    171                  // Just in case the other end needs synchronizing
> > >    172                  net_io_putc(__ch_data, TELNET_IAC);
> > >    173                  net_io_putc(__ch_data, TELNET_WONT);
> > >    174                  net_io_putc(__ch_data, TELNET_TM);
> > >    175                  net_io_flush();
> > >    176                  return true;
> > >    177              }
> > >    178              if (esc == TELNET_DO) {
> > >    179                  // Telnet DO option
> > >    180                  while (!_net_io_getc_nonblock(__ch_data, &esc)) ;
> > >    181                  // Respond with WONT option
> > >    182                  net_io_putc(__ch_data, TELNET_IAC);
> > >    183                  net_io_putc(__ch_data, TELNET_WONT);
> > >    184                  net_io_putc(__ch_data, esc);
> > >    185                  return false;  // Ignore this whole thing!
> > >    186              }
> > >    187          }
> > >    188      } else {
> > >    189          return false;
> > >    190      }
> > >    191  }
> > >
> > > Should there be a "return true;" either between lines 187/188
> > > or just before the final brace at line 191?
> >
> > It should probably just have a default return false at the end. i.e. just
> >
> > >    187          }
> > >    188      }
> > >    189      return false;
> > >    191  }
> >
> > I'll change it.
> 
> I'm confused.  Why is it false and not true?  How would reading
> a normal character ever return a true status?
> 
> My brain can't handle things nested too deeply -- especially w/
> K&R brace placement ;).  I ended up fixing my copy like this:

Sorry you're right (I tried to answer too quickly :-/ ). I'll change it to
the way you did it.

Jifl
-- 
Red Hat, Rustat House, Clifton Road, Cambridge, UK. Tel: +44 (1223) 271062
Maybe this world is another planet's Hell -Aldous Huxley || Opinions==mine

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2001-02-09 10:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-02-09  9:32 [ECOS] Redboot: net_io_getc_nonblock not setting return value? Grant Edwards
2001-02-09  9:52 ` Jonathan Larmour
2001-02-09 10:09   ` Grant Edwards
2001-02-09 10:26     ` Jonathan Larmour

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).