[Simh] Questions regarding future simulator development

Mark Pizzolato - Info Comm Mark at infocomm.com
Fri Apr 12 16:10:01 EDT 2013


On Friday, April 12, 2013 at 8:55 AM, Michael Mondy wrote:
> On Thu, Apr 11, 2013 at 03:35:10PM -0700, Mark Pizzolato - Info Comm wrote:
> > On Thursday, April 11, 2013 at 2:13 PM, Michael Mondy wrote:
> > > > > Extend the "set <var> = <value>" command to allow <value> to be
> > > > > a
> > > quoted string with whitespace.  I have code for this.  I use it to
> > > allow an ini file to provide initial input for my console routines
> > > so that the boot process can be partially automated.  There are
> > > other approaches to automated/interactive interaction, but this was
> simple.
> > > >
> > > > I'm not familiar with any syntax like this.  The above SET
> > > > ENVIRONMENT command is new since v3.9
> > >
> > > For example, I have a DEVICE named "OPCON" with an MTAB entry
> named
> > > "autoinput".  I use the following setting in my ini files:
> > >    sim> set OPCON autoinput="cold a20 ipc 3381 0a"
> > >
> > > Please see the patch at end of this message for specifics.
> >
> > OK, so you're parsing (or capturing) arguments in a SET modifier.  You could
> have chosen a different delimiter (a comma perhaps), and gathered them in
> the modifier validation routine.  We have other cases which do this.  Once
> gathered, you can store that information internally however you want.
> >
> > I'll look to see what else might be affected by this.  This one is a maybe.
> 
> My use case is collecting what would normally be typed human input.  If
> quoting doesn't make sense, I guess I could support octal escapes for blanks.
> Of course, my OS console's auto-input mechanism is pretty primitive.  If
> anyone wanted to do serious boot or other automation, they'd want
> something like the "expect" model.  That type of scripting can be provided by
> an external command that interacts with the console though.

It sounds reasonable to have a quoted string option.  

Supporting it without potentially affecting any of the many cases this code is already used is harder than just automatically ignoring quotes in parsed strings.

We can add a MTAB flag to select this option (MTAB_QUOTE) and an api to implement it: get_glyph_quoted which will return a quote bounded string or the original string if no quotes were supplied then delimited by the designated delimiter.  get_glyph_quoted implies no case conversion as well.  One Issue you'll have to deal with differently is that the string returned by get_glyph_quoted will return a string which still contains the quotes.  This due to the issues around what it would mean to strip quotes from some ambiguous cases:  For example calling get_glyph_quoted (input, output, ',')
	 He"lp M"e, other stuff
	"Help Me", other stuff
	HelpMe , other stuff
The way get_glyph_quoted is implemented means that spaces and the delimiter character within quoted strings don't count as delimiters.
Get_glyph_quoted allows either a " or a ' to start a quoted string.  If a particular quote character starts the quoted string, then that same character must end it.  This allows quoted strings to contain the opposite quote character: "It's fun doing this" will return the whole string as a single glyph.

> > > > > Open sockets with the SO_REUSEADDR or "no wait" option. I have
> > > > > code for this minor change.
> > > >
> > > > When would this be valuable and to whom (of the 4 classes of users
> > > > you
> > > define below)?
> > >
> > > This is useful when you re-launch a simulator only a few seconds
> > > after the prior run.  As you probably know, the TCP specs require
> > > that an OS list a socket in a TIME_WAIT state for a while after a
> > > listening socket is closed.  This is to allow the OS to more easily
> > > reject any packets that were part of a prior session but that did
> > > not arrive until after the socket was closed.  Especially not of
> > > interest on localhost connections.  Many network based apps have an
> option for whether or not to set this flag. See:
> > > http://www.unixguide.net/network/socketfaq/4.5.shtml
> >
> > Well, I can see your desire to get back to working your test environment
> quickly.
> >
> > The default behavior is there to hopefully prevent someone from
> accidentally running multiple instances of the same application.  On at least
> some platforms, if you set SO_REUSEADDR multiple instances of an
> application can be started each listening on the same socket.  Each one gets
> 'some' of the connections which arrive.
> >
> > We can add a switch which will add the SO_REUSEADDR socket option if
> someone explicitly wants that behavior.  The -R switch already has meaning
> for many attach commands, so maybe -A, -S or -U....
> 
> No OS allows multiple TCP/IP listeners.  It wouldn't work; the OS would never
> know which process should receive an incoming packet.

It is not a question of where packets go.  All kernel's will deliver packets destined to already established tcp sessions to the appropriate endpoint.  Meanwhile, the concerns about SO_REUSEADDR are effectively about whether multiple listeners can coexist listening on the same port which, as I previously mentioned, can happen on some platforms.  When it does happen, it is indeterminate which listener will get any particular newly arriving connection...

Think through the coding sequence.  1) the socket is created, 2) the options are set, 3) the socket is bound to addresses by calling bind(), 4) the socket becomes eligible to receive connections when listen is called.  The sanity validation performed or disregarded happen in bind, not listen.  Listen isn't defined to have any errors which relate to conflicting addresses.

I've added a -U switch option which will cause SO_REUSEADDR to be set on sockets prior to calling bind.

If you don't want to have to type -U on your attach commands, you can create an alias: SET ENV ATT=ATTACH -U.  The -U switch will also work for the telnet redirected console: SET -U CONSOLE TELNET=port

The above mentioned quoted string parsing and the SO_REUSEADDR option are checked-in on the github repository.  Download a zip from: https://github.com/simh/simh/archive/master.zip


- Mark




More information about the Simh mailing list