|
| 1 | +//go:build windows |
| 2 | + |
| 3 | +// Copyright 2025 Blink Labs Software |
| 4 | +// |
| 5 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +// you may not use this file except in compliance with the License. |
| 7 | +// You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, software |
| 12 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +// See the License for the specific language governing permissions and |
| 15 | +// limitations under the License. |
| 16 | + |
| 17 | +package connmanager |
| 18 | + |
| 19 | +import ( |
| 20 | + "errors" |
| 21 | + "net" |
| 22 | + "strings" |
| 23 | + "syscall" |
| 24 | + |
| 25 | + "github.com/Microsoft/go-winio" |
| 26 | +) |
| 27 | + |
| 28 | +// socketControl is a no-op on Windows |
| 29 | +func socketControl(_network, _address string, _c syscall.RawConn) error { |
| 30 | + return nil |
| 31 | +} |
| 32 | + |
| 33 | +type UnixConnAddr struct { |
| 34 | + addr string |
| 35 | +} |
| 36 | + |
| 37 | +func (a UnixConnAddr) Network() string { return "pipe" } |
| 38 | + |
| 39 | +func (a UnixConnAddr) String() string { return a.addr } |
| 40 | + |
| 41 | +type UnixConn struct { |
| 42 | + net.Conn |
| 43 | + remoteAddr UnixConnAddr |
| 44 | +} |
| 45 | + |
| 46 | +func NewUnixConn(conn net.Conn) (*UnixConn, error) { |
| 47 | + if conn == nil { |
| 48 | + return nil, errors.New("connection is nil") |
| 49 | + } |
| 50 | + if conn.RemoteAddr() == nil { |
| 51 | + return nil, errors.New("connection has no remote address") |
| 52 | + } |
| 53 | + return &UnixConn{ |
| 54 | + Conn: conn, |
| 55 | + remoteAddr: UnixConnAddr{addr: conn.RemoteAddr().String()}, |
| 56 | + }, nil |
| 57 | +} |
| 58 | + |
| 59 | +func (u *UnixConn) RemoteAddr() net.Addr { |
| 60 | + return u.remoteAddr |
| 61 | +} |
| 62 | + |
| 63 | +// createPipeListener creates a named pipe listener on Windows |
| 64 | +func createPipeListener(_, address string) (net.Listener, error) { |
| 65 | + // Adjust address to named pipe format if not already |
| 66 | + if !strings.HasPrefix(address, `\\.\pipe\`) { |
| 67 | + address = `\\.\pipe\` + address |
| 68 | + } |
| 69 | + return winio.ListenPipe(address, nil) |
| 70 | +} |
0 commit comments