nanomsg.org/go/mangos/v2@v2.0.9-0.20200203084354-8a092611e461/transport/handshaker.go (about) 1 // Copyright 2019 The Mangos Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use file except in compliance with the License. 5 // You may obtain a copy of the license at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package transport 16 17 // Handshaker is used to support dealing with asynchronous 18 // handshaking used for some transports. This allows the 19 // initial handshaking to be done in the background, without 20 // stalling the server's accept queue. This is important to 21 // ensure that a slow remote peer cannot bog down the server 22 // or effect a denial-of-service for new connections. 23 type Handshaker interface { 24 // Start injects a pipe into the handshaker. The 25 // handshaking is done asynchronously on a Go routine. 26 Start(Pipe) 27 28 // Waits for until a pipe has completely finished the 29 // handshaking and returns it. 30 Wait() (Pipe, error) 31 32 // Close is used to close the handshaker. Any existing 33 // negotiations will be canceled, and the underlying 34 // transport sockets will be closed. Any new attempts 35 // to start will return mangos.ErrClosed. 36 Close() 37 }