Documentation ¶
Overview ¶
Package tcpserver is discontinued. Please visit: github.com/orkunkaraduman/go-accepter Package tcpserver provides TCP server implementation.
Index ¶
- Variables
- func ReadBytesLimit(b *bufio.Reader, delim byte, lim int) (line []byte, err error)
- type Handler
- type HandlerFunc
- type TCPServer
- func (srv *TCPServer) Close() (err error)
- func (srv *TCPServer) ListenAndServe() error
- func (srv *TCPServer) ListenAndServeTLS(certFile, keyFile string) error
- func (srv *TCPServer) Serve(l net.Listener) (err error)
- func (srv *TCPServer) ServeTLS(l net.Listener, certFile, keyFile string) (err error)
- func (srv *TCPServer) Shutdown(ctx context.Context) (err error)
- type TextProtocol
- type TextProtocolContext
Constants ¶
This section is empty.
Variables ¶
var DefMaxLineSize = 1 * 1024
DefMaxLineSize specifies maximum line size with delimiter if TextProtocol.MaxLineSize is 0.
var ( // ErrBufferLimitExceeded is returned when specified buffer limit // was exceeded. ErrBufferLimitExceeded = errors.New("buffer limit exceeded") )
Functions ¶
Types ¶
type HandlerFunc ¶
The HandlerFunc type is an adapter to allow the use of ordinary functions as handlers. If f is a function with the appropriate signature, HandlerFunc(f) is a Handler that calls f.
func (HandlerFunc) Serve ¶
func (f HandlerFunc) Serve(conn net.Conn, closeCh <-chan struct{})
Serve calls f(conn, closeCh)
type TCPServer ¶
type TCPServer struct { // TCP address to listen on. Addr string // Handler to invoke. Handler Handler // TLSConfig optionally provides a TLS configuration. TLSConfig *tls.Config // ErrorLog specifies an optional logger for errors in Handler. ErrorLog *log.Logger // contains filtered or unexported fields }
A TCPServer defines parameters for running an TCP server.
func (*TCPServer) Close ¶
Close immediately closes all active net.Listeners and any connections. For a graceful shutdown, use Shutdown.
Close returns any error returned from closing the Server's underlying Listener(s).
func (*TCPServer) ListenAndServe ¶
ListenAndServe listens on the TCP network address srv.Addr and then calls Serve to handle requests on incoming connections. ListenAndServe returns a nil error after Close or Shutdown method called.
func (*TCPServer) ListenAndServeTLS ¶
ListenAndServeTLS listens on the TCP network address srv.Addr and then calls Serve to handle requests on incoming TLS connections.
Filenames containing a certificate and matching private key for the server must be provided if neither the Server's TLSConfig.Certificates nor TLSConfig.GetCertificate are populated. If the certificate is signed by a certificate authority, the certFile should be the concatenation of the server's certificate, any intermediates, and the CA's certificate.
func (*TCPServer) Serve ¶
Serve accepts incoming connections on the Listener l, creating a new service goroutine for each. The service goroutines read requests and then call srv.Handler to reply to them. Serve returns a nil error after Close or Shutdown method called.
func (*TCPServer) ServeTLS ¶
ServeTLS accepts incoming connections on the Listener l, creating a new service goroutine for each. The service goroutines read requests and then call srv.Handler to reply to them. ServeTLS returns a nil error after Close or Shutdown method called.
Additionally, files containing a certificate and matching private key for the server must be provided if neither the Server's TLSConfig.Certificates nor TLSConfig.GetCertificate are populated.. If the certificate is signed by a certificate authority, the certFile should be the concatenation of the server's certificate, any intermediates, and the CA's certificate.
func (*TCPServer) Shutdown ¶
Shutdown gracefully shuts down the server without interrupting any connections. Shutdown works by first closing all open listeners, then fills closeCh on Serve method of Handler, and then waiting indefinitely for connections to exit Serve method of Handler and then close. If the provided context expires before the shutdown is complete, Shutdown returns the context's error, otherwise it returns any error returned from closing the Server's underlying Listener(s).
When Shutdown is called, Serve, ListenAndServe, and ListenAndServeTLS immediately return nil. Make sure the program doesn't exit and waits instead for Shutdown to return.
type TextProtocol ¶
type TextProtocol struct { // Accept callback. It will be called before reading line. OnAccept func(ctx *TextProtocolContext) // Quit callback. It will be called before closing. OnQuit func(ctx *TextProtocolContext) // ReadLine callback. If it returns greater then 0, context reads data from // connection n bytes. And after will be call OnReadData. OnReadLine func(ctx *TextProtocolContext, line string) (n int) // ReadData callback. OnReadData func(ctx *TextProtocolContext, buf []byte) // MaxLineSize specifies maximum line size with delimiter. MaxLineSize int // User data to use free. UserData interface{} }
TextProtocol defines parameters for Handler of text based protocol.
func (*TextProtocol) Serve ¶
func (prt *TextProtocol) Serve(conn net.Conn, closeCh <-chan struct{})
Serve implements Handler.Serve.
type TextProtocolContext ¶
type TextProtocolContext struct { // Pointer of TextProtocol struct handled by this context. Prt *TextProtocol // Connection handled by this context. Conn net.Conn // User data to use free. UserData interface{} // contains filtered or unexported fields }
TextProtocolContext defines parameters for text protocol context.
func (*TextProtocolContext) WriteData ¶
func (ctx *TextProtocolContext) WriteData(buf []byte) error
WriteData writes data to connection.
func (*TextProtocolContext) WriteLine ¶
func (ctx *TextProtocolContext) WriteLine(line string) error
WriteLine writes a line to connection.