//go:build linux /* * ============================================================================ * Projekt.....: rs2322tcp * Datei.......: internal/client/virtual_port_open_linux.go * Copyright (C) 2026 Dieter Lang * * SPDX-License-Identifier: GPL-3.0-or-later * * Beschreibung: * Linux-spezifische Erzeugung eines verwalteten virtuellen rs2322tcp-Ports. * * Die virtuelle serielle Schnittstelle wird über ein PTY-Paar erzeugt. * Der öffentliche /dev/ttyUSBxxx-Eintrag wird über den bereits vorhandenen * internen Link auf den PTY-Slave abgebildet. * ============================================================================ */ package client import "fmt" /////////////////////////////////////////////////////////////////////////////// // Open virtual port /////////////////////////////////////////////////////////////////////////////// // openVirtualPort creates and initializes a Linux virtual serial port. // // The port number must already have been reserved by the // VirtualPortManager. // // On failure, the caller remains responsible for releasing the reservation. func openVirtualPort( manager *VirtualPortManager, number int, ) (*ManagedVirtualPort, error) { if manager == nil { return nil, fmt.Errorf("virtual port manager is nil") } portPath := manager.PortPath(number) serial, err := newVirtualSerial() if err != nil { return nil, fmt.Errorf( "create virtual serial for %s: %w", portPath, err, ) } if err := setVirtualPortLink( portPath, serial.Path(), ); err != nil { _ = serial.Close() return nil, fmt.Errorf( "bind %s to %s: %w", portPath, serial.Path(), err, ) } port := NewVirtualPort( portPath, serial, ) return &ManagedVirtualPort{ port: port, manager: manager, number: number, }, nil }