server

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2018 License: BSD-3-Clause Imports: 27 Imported by: 0

Documentation

Overview

Package server provides a high level API for implementing the XRootD server following protocol from http://xrootd.org.

This package contains an implementation of the general requests such as handshake, protocol, and login inside the default Handler which can be obtained via Default.

Example
addr := "0.0.0.0:1094"
listener, err := net.Listen("tcp", addr)
if err != nil {
	log.Fatalf("could not listen on %q: %v", addr, err)
}

srv := New(Default(), func(err error) {
	log.Printf("an error occured: %v", err)
})

log.Printf("listening on %v...", listener.Addr())

if err = srv.Serve(listener); err != nil {
	log.Fatalf("could not serve: %v", err)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrServerClosed = errors.New("xrootd: server closed")

ErrServerClosed is returned by the Server's Serve method after a call to Shutdown.

Functions

This section is empty.

Types

type ErrorHandler

type ErrorHandler func(error)

ErrorHandler is the function which handles occurred error (e.g. logs it).

type Handler

type Handler interface {
	// Handshake handles the XRootD handshake: http://xrootd.org/doc/dev45/XRdv310.htm#_Toc464248784.
	Handshake() (xrdproto.Marshaler, xrdproto.ResponseStatus)

	// Login handles the XRootD login request: http://xrootd.org/doc/dev45/XRdv310.htm#_Toc464248819.
	Login(sessionID [16]byte, request *login.Request) (xrdproto.Marshaler, xrdproto.ResponseStatus)

	// Protocol handles the XRootD protocol request: http://xrootd.org/doc/dev45/XRdv310.htm#_Toc464248827.
	Protocol(sessionID [16]byte, request *protocol.Request) (xrdproto.Marshaler, xrdproto.ResponseStatus)

	// Dirlist handles the XRootD dirlist request: http://xrootd.org/doc/dev45/XRdv310.htm#_Toc464248815.
	Dirlist(sessionID [16]byte, request *dirlist.Request) (xrdproto.Marshaler, xrdproto.ResponseStatus)

	// CloseSession handles the aborting of user session. This can be used to free some user-related data.
	CloseSession(sessionID [16]byte) error

	// Open handles the XRootD open request: http://xrootd.org/doc/dev45/XRdv310.htm#_Toc464248823.
	Open(sessionID [16]byte, request *open.Request) (xrdproto.Marshaler, xrdproto.ResponseStatus)

	// Close handles the XRootD close request: http://xrootd.org/doc/dev45/XRdv310.htm#_Toc464248813.
	Close(sessionID [16]byte, request *xrdclose.Request) (xrdproto.Marshaler, xrdproto.ResponseStatus)

	// Read handles the XRootD read request: http://xrootd.org/doc/dev45/XRdv310.htm#_Toc464248841.
	Read(sessionID [16]byte, request *read.Request) (xrdproto.Marshaler, xrdproto.ResponseStatus)

	// Write handles the XRootD write request: http://xrootd.org/doc/dev45/XRdv310.htm#_Toc464248855.
	Write(sessionID [16]byte, request *write.Request) (xrdproto.Marshaler, xrdproto.ResponseStatus)

	// Stat handles the XRootD stat request: http://xrootd.org/doc/dev45/XRdv310.htm#_Toc464248850.
	Stat(sessionID [16]byte, request *stat.Request) (xrdproto.Marshaler, xrdproto.ResponseStatus)

	// Sync handles the XRootD sync request: http://xrootd.org/doc/dev45/XRdv310.htm#_Toc464248852.
	Sync(sessionID [16]byte, request *sync.Request) (xrdproto.Marshaler, xrdproto.ResponseStatus)

	// Truncate handles the XRootD truncate request: http://xrootd.org/doc/dev45/XRdv310.htm#_Toc464248853.
	Truncate(sessionID [16]byte, request *truncate.Request) (xrdproto.Marshaler, xrdproto.ResponseStatus)

	// Rename handles the XRootD mv request: http://xrootd.org/doc/dev45/XRdv310.htm#_Toc464248822.
	Rename(sessionID [16]byte, request *mv.Request) (xrdproto.Marshaler, xrdproto.ResponseStatus)
}

Handler provides a high-level API for the XRootD server. The Handler receives a parsed request and returns a response together with the status that will be send via Server to the client.

func Default

func Default() Handler

Default returns the defaultHandler implementing Handler with some general functionality added. Any unimplemented request returns InvalidRequest error.

func NewFSHandler

func NewFSHandler(basePath string) Handler

NewFSHandler creates a Handler that passes requests to the backing filesystem at basePath.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server implements the XRootD server following protocol from http://xrootd.org. The Server uses a Handler to handle incoming requests. To listen for incoming connections, Serve method must be called. It is possible to configure to listen on several ports simultaneously by calling Serve with different net.Listeners.

func New

func New(handler Handler, errorHandler ErrorHandler) *Server

New creates a XRootD server which uses specified handler to handle requests and errorHandler to handle errors. If the errorHandler is nil, then a default error handler is used that does nothing.

func (*Server) Serve

func (s *Server) Serve(l net.Listener) error

Serve accepts incoming connections on the Listener l, creating a new service goroutine for each. The service goroutines read requests and then call s.handler to handle them.

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Shutdown stops Server and closes all listeners and active connections. Shutdown returns the first non nil error while closing listeners and connections.

Jump to

Keyboard shortcuts

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