80 lines
1.8 KiB
Go
80 lines
1.8 KiB
Go
//go:build linux
|
|
|
|
/*
|
|
* ============================================================================
|
|
* Projekt.....: rs2322tcp
|
|
* Datei.......: internal/client/virtual_port_manager_linux.go
|
|
* Copyright (C) 2026 Dieter Lang
|
|
*
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
*
|
|
* Beschreibung:
|
|
* Linux-spezifische Erzeugung eines virtuellen rs2322tcp-Ports.
|
|
*
|
|
* Die gemeinsame Verwaltung von ManagedVirtualPort und VirtualPortManager
|
|
* befindet sich in virtual_port_manager_open.go.
|
|
*
|
|
* Unter Linux wird der PTY über newVirtualSerial() erzeugt und der interne
|
|
* Link unter ~/.rs2322tcp/virtual/ auf diesen PTY gesetzt.
|
|
* ============================================================================
|
|
*/
|
|
|
|
package client
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
// openReserved creates the actual Linux virtual serial port for an already
|
|
// reserved port number.
|
|
//
|
|
// The caller must reserve the port before calling this method.
|
|
//
|
|
// The public /dev/ttyUSBxxx link is not modified here. The installation-owned
|
|
// link remains untouched. Only the user-owned internal link below
|
|
// ~/.rs2322tcp/virtual/ is created or updated to point to the newly created
|
|
// PTY.
|
|
func openReserved(
|
|
m *VirtualPortManager,
|
|
number int,
|
|
) (*ManagedVirtualPort, error) {
|
|
if m == nil {
|
|
return nil, fmt.Errorf("virtual port manager is nil")
|
|
}
|
|
|
|
portPath := m.PortPath(number)
|
|
|
|
serial, err := newVirtualSerial()
|
|
if err != nil {
|
|
m.Release(number)
|
|
|
|
return nil, fmt.Errorf(
|
|
"create virtual serial for %s: %w",
|
|
portPath,
|
|
err,
|
|
)
|
|
}
|
|
|
|
if err := setVirtualPortLink(
|
|
portPath,
|
|
serial.Path(),
|
|
); err != nil {
|
|
_ = serial.Close()
|
|
m.Release(number)
|
|
|
|
return nil, fmt.Errorf(
|
|
"bind %s to %s: %w",
|
|
portPath,
|
|
serial.Path(),
|
|
err,
|
|
)
|
|
}
|
|
|
|
port := NewVirtualPort(portPath, serial)
|
|
|
|
return &ManagedVirtualPort{
|
|
port: port,
|
|
manager: m,
|
|
number: number,
|
|
}, nil
|
|
}
|