Timeout in protocol loop

To (hopefully) prevent dead connections from hanging around.

Signed-off-by: Thomas Berezansky <tsbere@mvlc.org>
Signed-off-by: Bill Erickson <berick@esilibrary.com>
LP#1042850: Add TCP-level keepalive

Some client TCP stacks fail to actually close down their sockets
all the way, leading to a pile up of stale backends that can never
go away.

So, we will use Linux's TCP_KEEPALIVE tuning capabilities to probe
the connection on a regular basis.  This should detect the half-
closed situation and let the backend shut itself down.

Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Bill Erickson <berick@esilibrary.com>
LP#1338731: support clients that send 99 then 93 when starting a raw connection

This patch adds the option, for raw transports, to allow clients
to send the SC Status (99) message first, then the Login (93)
message. It's arguable whether such behavior is standard or not,
but at least one SIP2 client (Relais), inflexibly requires such
behavior.

This option is enabled using the service-level attribute
"allow_sc_status_then_login".

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
LP#1338761: add support for Relais extensions to message 24

The Relais SIP2 client expects that the Patron Status Response
(msg 24) will contain certain non-standard fields that are more
properly included in the patron information response:

- patron home address
- patron email
- patron home phone

In addition, and contrary to the specification, Relais expects that
the variable fields in the response will be given in the order that
they appear in the spec.

This patch ensures that the Patron Status repsonse emits the
institution ID, patron ID, and personal name in that order.  It also
adds a new institution option, relais_extensions_to_msg24, to make
the response includes the additional fields.  For example:

  <relais_extensions_to_msg24 enabled="true" />

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
LP#1339190 Unroll recursion-based processing chain

Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Bill Erickson <berick@esilibrary.com>
LP#1339190 Add support for the "Multiplex" personality

We use Net::Server::Multiplex to reduce resource consumption.  In
this mode, SIPServer will maintain connection state in the main
listening process and fork workers as needed to handle individual
requests.

Initial implementation by Mike Rylander, with a conversion from
File::Queue to Memcache, and LOTS of debugging, by Bill Erickson.

Some highlights:

* A fork fence for max concurrent in-flight requests

* Allow the ILS to save state in IO::Multiplex mode

* Optimistic login using fork-and-check

When a SIP child process is spawned to handle a new connection login,
the pending login is tracked in the parent process (by PID) and the
child indicates to the parent that the login has succeeded by storing
login success/failure plus some state information in memcache.  Any time
the parent wakes up to process a message, it checks for completed logins
so they can be resolved as OK in the parent and the state information
is extracted and stored for future conversation with the resolved client.

* Let workers hang around for a bit for higher-rate clients

For some clients, such as AMH (sorters), the per-message connections
cause too much latency.  So, instead, we'll let their backends hang
around for a while.  This is controlled by a new attribute on the
server-params element, worker-keepalive, as a peer to the personality
value.  This value can also be set on the institution and login elements
to support finer-grained keepalive tuning.

This is measured in seconds and the default is 5. A value of 0 here
will disable this feature altogether.

Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Signed-off-by: Blake GH <blake@mobiusconsortium.org>