Files
go3270/transactions.go
Claude 8539da3147 Licence: AGPL-3.0-only, or a commercial licence from the D-Modem Authors
The suite's licence, as D-Modem, bbs, menu and brand: the AGPL-3.0-only
by default, and a commercial licence from the D-Modem Authors for uses
that can't meet its terms (COMMERCIAL-LICENSE.md).  The contributor
agreement grants the licence for both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B82eRSQaj3bYPQDZU4qf9U
2026-11-07 11:01:37 +00:00

59 lines
2.1 KiB
Go

// SPDX-License-Identifier: MIT
// This file is part of https://github.com/racingmars/go3270/
// Copyright 2025 by Matthew R. Wilson, licensed under the MIT license.
// See LICENSE-MIT in the project root for license information.
package go3270
import "net"
// Tx is a function that serves as one transaction in a go3270 application.
// The Tx function is called with the network connection to the client, the
// DevInfo for use with alternate screen writes, and a "data" value provided
// by the previous transaction. Tx functions return the next transaction to
// run (or nil to indicate the RunTransactions() function should terminate),
// the data to pass into the next transaction, and any error. If the error is
// non-nil, the RunTransactions() function will terminate and return the err.
// A non-nil error is _not_ passed between transactions, it terminates
// transaction processing.
type Tx func(conn net.Conn, dev DevInfo, data any) (
next Tx, newdata any, err error)
// RunTransactions begins running transaction functions, starting with the
// initial transaction, until a transaction eventually returns nil for the
// next transaction, or until a transaction function returns a non-nil error
// value. data (which may be nil, if the initial transaction does not require
// data) is passed in as the data to the initial transaction.
//
// dev is the DevInfo of the connected client, as obtained from
// NegotiateTelnet(). It is safe to pass a nil DevInfo, in which case all
// transactions will only be able to operate with the default 24x80 screen
// size.
func RunTransactions(conn net.Conn, dev DevInfo, initial Tx,
data any) error {
var next Tx
var err error
next = initial
if dev == nil {
dev = &deviceInfo{rows: 24, cols: 80, termtype: "DEFAULT"}
}
// We run transactions until there isn't a next transaction to run, or
// an error.
for {
next, data, err = next(conn, dev, data)
if err != nil {
// Error means we bail out and return the error to the caller.
return err
}
if next == nil {
// nil next transaction means we're done.
return nil
}
}
}