MCPcopy
hub / github.com/etcd-io/etcd / NewServer

Function NewServer

pkg/proxy/server.go:194–270  ·  view source on GitHub ↗

NewServer returns a proxy implementation with no iptables/tc dependencies. The proxy layer overhead is <1ms.

(cfg ServerConfig)

Source from the content-addressed store, hash-verified

192// NewServer returns a proxy implementation with no iptables/tc dependencies.
193// The proxy layer overhead is <1ms.
194func NewServer(cfg ServerConfig) Server {
195 s := &server{
196 lg: cfg.Logger,
197
198 from: cfg.From,
199 to: cfg.To,
200
201 tlsInfo: cfg.TLSInfo,
202 dialTimeout: cfg.DialTimeout,
203
204 bufferSize: cfg.BufferSize,
205 retryInterval: cfg.RetryInterval,
206
207 readyc: make(chan struct{}),
208 donec: make(chan struct{}),
209 errc: make(chan error, 16),
210
211 pauseAcceptc: make(chan struct{}),
212 pauseTxc: make(chan struct{}),
213 pauseRxc: make(chan struct{}),
214 }
215
216 _, fromPort, err := net.SplitHostPort(cfg.From.Host)
217 if err == nil {
218 s.fromPort, _ = strconv.Atoi(fromPort)
219 }
220 var toPort string
221 _, toPort, err = net.SplitHostPort(cfg.To.Host)
222 if err == nil {
223 s.toPort, _ = strconv.Atoi(toPort)
224 }
225
226 if s.dialTimeout == 0 {
227 s.dialTimeout = defaultDialTimeout
228 }
229 if s.bufferSize == 0 {
230 s.bufferSize = defaultBufferSize
231 }
232 if s.retryInterval == 0 {
233 s.retryInterval = defaultRetryInterval
234 }
235
236 close(s.pauseAcceptc)
237 close(s.pauseTxc)
238 close(s.pauseRxc)
239
240 if strings.HasPrefix(s.from.Scheme, "http") {
241 s.from.Scheme = "tcp"
242 }
243 if strings.HasPrefix(s.to.Scheme, "http") {
244 s.to.Scheme = "tcp"
245 }
246
247 addr := fmt.Sprintf(":%d", s.fromPort)
248 if s.fromPort == 0 { // unix
249 addr = s.from.Host
250 }
251

Callers 9

testServerFunction · 0.70
testServerDelayAcceptFunction · 0.70
TestServer_PauseTxFunction · 0.70
TestServer_BlackholeTxFunction · 0.70
TestServer_ShutdownFunction · 0.70
testServerHTTPFunction · 0.70

Calls 8

CloseMethod · 0.95
listenAndServeMethod · 0.95
FromMethod · 0.95
ToMethod · 0.95
InfoMethod · 0.80
AddMethod · 0.65
StringMethod · 0.65
EmptyMethod · 0.45

Tested by 9

testServerFunction · 0.56
testServerDelayAcceptFunction · 0.56
TestServer_PauseTxFunction · 0.56
TestServer_BlackholeTxFunction · 0.56
TestServer_ShutdownFunction · 0.56
testServerHTTPFunction · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…