tls

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 15, 2024 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 1 more Imports: 7 Imported by: 2

README

English | 中文

extension: tls

This is an extension combining tnet and crypto/tls to improve memory usage and performance under millions of connections, without intrusive modification of the underlying library.

Features:

  • Based upon tnet, reduce memory usage and improve CPU utilization.
  • Without intrusive modification of crypto/tls package.
  • SetMetadata/GetMetadata to store/retrieve user's private data.
  • Easy to use.

Examples: examples/echo/README.md

Documentation

Overview

Package tls provides tls connection utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewService

func NewService(ln net.Listener, handler Handler, opts ...ServerOption) (tnet.Service, error)

NewService creates a new tls service.

Types

type ClientOption

type ClientOption func(*clientOptions)

ClientOption is the type for a single client option.

func WithClientFlushWrite

func WithClientFlushWrite(flushWrite bool) ClientOption

WithClientFlushWrite sets the flush write flag for client connection.

func WithClientIdleTimeout

func WithClientIdleTimeout(idleTimeout time.Duration) ClientOption

WithClientIdleTimeout sets the idle timeout to close the connection.

func WithClientTLSConfig

func WithClientTLSConfig(cfg *tls.Config) ClientOption

WithClientTLSConfig provides the option to set TLS configuration.

func WithTimeout

func WithTimeout(timeout time.Duration) ClientOption

WithTimeout provides the option to set dial timeout.

type Conn

type Conn interface {
	net.Conn
	// SetMetaData sets meta data. Through this method, users can bind some custom data to a connection.
	SetMetaData(any)
	// GetMetaData gets meta data.
	GetMetaData() any
	// SetIdleTimeout sets connection level idle timeout.
	SetIdleTimeout(d time.Duration) error
	// SetFlushWrite sets flush write flag for the connection.
	SetFlushWrite(flushWrite bool)
	// SetOnRequest can set or replace the tls.Handler method for a connection.
	SetOnRequest(handle Handler) error
	// SetOnClosed sets the additional close process for a connection.
	SetOnClosed(handle Handler) error
	// IsActive checks whether the connection is active or not.
	IsActive() bool
}

Conn defines tls connection interface.

func Dial

func Dial(network, addr string, opts ...ClientOption) (Conn, error)

Dial creates a client connection.

type Handler

type Handler = func(c Conn) error

Handler is the tls connection handler.

type OnClosed

type OnClosed func(conn Conn) error

OnClosed fires when the connection is closed. In this method, please do not perform read-write operations, because the connection has been closed. But you can still manipulate the MetaData in the connection.

type OnOpened

type OnOpened func(conn Conn) error

OnOpened fires when the tcp connection is established.

type ServerOption

type ServerOption func(*serverOptions)

ServerOption is the type for a single server option.

func WithOnClosed

func WithOnClosed(onClosed OnClosed) ServerOption

WithOnClosed registers the OnClosed method that is fired when connection is closed.

func WithOnOpened

func WithOnOpened(onOpened OnOpened) ServerOption

WithOnOpened registers the OnOpened method that is fired when connection is established.

func WithServerFlushWrite

func WithServerFlushWrite(flushWrite bool) ServerOption

WithServerFlushWrite sets the flush write flag for server connection.

func WithServerIdleTimeout

func WithServerIdleTimeout(idleTimeout time.Duration) ServerOption

WithServerIdleTimeout sets the idle timeout to close the connection.

func WithServerTLSConfig

func WithServerTLSConfig(cfg *tls.Config) ServerOption

WithServerTLSConfig provides the option to set TLS configuration.

func WithTCPKeepAlive

func WithTCPKeepAlive(keepAlive time.Duration) ServerOption

WithTCPKeepAlive sets the tcp keep alive interval.

Directories

Path Synopsis
examples
echo/client
Package main is the main package.
Package main is the main package.
echo/server
Package main is the main package.
Package main is the main package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL