Files
Alex ShtinandGitHub 8e8f1b0f7c Remove license header from every file (#7689)
## What changed?
<!-- Describe what has changed in this PR -->
Remove license header from every file. Because it is really hard to
follow in this PR here is the summary:
1. License header is removed from all `.go` and `.proto` files
:fireworks::fireworks:🎆.
2. `LICENSE` file in the root directory has only Temporal and Uber
copyrights.
3. 5 other `LICENSE` files added to the packages which have copyrights
different from Temporal and Uber: Datadog, Xargin, "Mat Ryer, Tyler
Bunnell and contributors".
4. `license_file` flag is removed from all code generation tools.
5. `copyright_file` flag is removed from `go:generate mockgen`
directive.
6. All copyright related targets are removed from `Makefile`.
7. Updated Temporal copyright year to 2025 everywhere.

## Why?
<!-- Tell your future self why have you made these changes -->
I double checked with legal department that it is not needed to have
license header in every file. One file per repo is enough. I put all
copyrights to the root `LICENSE` file and removed header from all other
files. Also updated tools and `Makefile`.
2025-05-01 18:50:21 -07:00

59 lines
1.4 KiB
Go

package nettest
import (
"errors"
"net"
)
type (
// Pipe is an in-memory socket. It provides similar functionality to net.Listen and net.Dial via the Pipe.Accept
// and Pipe.Connect methods, respectively. It is useful for faster and more deterministic testing of netcode.
Pipe struct {
clients chan connCb
}
// connResult captures a value which is either a connection or an error.
connResult struct {
conn net.Conn
err error
}
// connCb is a callback that a connection result will be sent to.
connCb chan connResult
)
// ErrCanceled indicates that an operation was canceled by the client (e.g. via ctx.Done()).
var ErrCanceled = errors.New("pipe operation canceled by client")
// NewPipe returns a Pipe.
func NewPipe() *Pipe {
return &Pipe{
clients: make(chan connCb),
}
}
// Accept returns a connection to the server for a client.
func (p *Pipe) Accept(cancel <-chan struct{}) (net.Conn, error) {
select {
case <-cancel:
return nil, ErrCanceled
case client := <-p.clients:
clientConn, serverConn := net.Pipe()
client <- connResult{conn: clientConn}
return serverConn, nil
}
}
// Connect returns a connection to a client for the server.
func (p *Pipe) Connect(cancel <-chan struct{}) (net.Conn, error) {
clientConnCb := make(connCb)
select {
case p.clients <- clientConnCb:
r := <-clientConnCb
return r.conn, r.err
case <-cancel:
return nil, ErrCanceled
}
}