trpc.group/trpc-go/trpc-go@v1.0.3/transport/tnet/server_transport_option.go (about) 1 // 2 // 3 // Tencent is pleased to support the open source community by making tRPC available. 4 // 5 // Copyright (C) 2023 THL A29 Limited, a Tencent company. 6 // All rights reserved. 7 // 8 // If you have downloaded a copy of the tRPC source code from Tencent, 9 // please note that tRPC source code is licensed under the Apache 2.0 License, 10 // A copy of the Apache 2.0 License is included in this file. 11 // 12 // 13 14 //go:build linux || freebsd || dragonfly || darwin 15 // +build linux freebsd dragonfly darwin 16 17 package tnet 18 19 import ( 20 "runtime" 21 "time" 22 23 "trpc.group/trpc-go/tnet" 24 ) 25 26 // SetNumPollers sets the number of tnet pollers. Generally it is not actively used. 27 func SetNumPollers(n int) error { 28 return tnet.SetNumPollers(n) 29 } 30 31 // ServerTransportOption is server transport option. 32 type ServerTransportOption func(o *ServerTransportOptions) 33 34 // ServerTransportOptions is server transport options struct. 35 type ServerTransportOptions struct { 36 KeepAlivePeriod time.Duration 37 ReusePort bool 38 } 39 40 // WithKeepAlivePeriod sets the TCP keep alive interval. 41 func WithKeepAlivePeriod(d time.Duration) ServerTransportOption { 42 return func(opts *ServerTransportOptions) { 43 opts.KeepAlivePeriod = d 44 } 45 } 46 47 // WithReusePort returns a ServerTransportOption which enables reuse port or not. 48 func WithReusePort(reuse bool) ServerTransportOption { 49 return func(opts *ServerTransportOptions) { 50 opts.ReusePort = reuse 51 if runtime.GOOS == "windows" { 52 opts.ReusePort = false 53 } 54 } 55 }