Files
zeekay c07340ba19 build: Automatic CGO-based implementation selection
- Pure Go when CGO_ENABLED=0 (default)
- CZMQ when CGO_ENABLED=1 (automatic)
- Replaced manual build tags with CGO detection
- Comprehensive documentation and tooling
- Added benchmarks and integration tests
- Cleaned up repository structure
2025-08-20 23:53:34 -05:00

53 lines
1016 B
Go

// Copyright 2025 The go-zeromq Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package zmq4
import (
"fmt"
)
// Proxy starts a proxy that forwards messages between frontend and backend.
// This is the ONLY way to create a proxy - no complex variations.
func Proxy(frontend, backend Socket) error {
if frontend == nil || backend == nil {
return fmt.Errorf("frontend and backend sockets are required")
}
errChan := make(chan error, 2)
// Frontend to backend
go func() {
for {
msg, err := frontend.Recv()
if err != nil {
errChan <- err
return
}
if err := backend.Send(msg); err != nil {
errChan <- err
return
}
}
}()
// Backend to frontend
go func() {
for {
msg, err := backend.Recv()
if err != nil {
errChan <- err
return
}
if err := frontend.Send(msg); err != nil {
errChan <- err
return
}
}
}()
// Wait for first error
return <-errChan
}