github.com/pawelgaczynski/gain@v0.4.0-alpha.0.20230821120126-41f1e60a18da/pkg/socket/socket.go (about) 1 // Copyright (c) 2020 Andy Pan 2 // Copyright (c) 2017 Max Riveiro 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 16 // Package socket provides functions that return fd and net.Addr based on 17 // given the protocol and address with a SO_REUSEPORT option set to the socket. 18 package socket 19 20 import ( 21 "net" 22 ) 23 24 // Option is used for setting an option on socket. 25 type Option struct { 26 SetSockOpt func(int, int) error 27 Opt int 28 } 29 30 // TCPSocket calls the internal tcpSocket. 31 func TCPSocket(proto, addr string, passive bool, sockOpts ...Option) (int, net.Addr, error) { 32 return tcpSocket(proto, addr, passive, sockOpts...) 33 } 34 35 // UDPSocket calls the internal udpSocket. 36 func UDPSocket(proto, addr string, connect bool, sockOpts ...Option) (int, net.Addr, error) { 37 return udpSocket(proto, addr, connect, sockOpts...) 38 }