ipc

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

The chmsg provides a data structure that helps to manage interprocess communications between Goroutines via channels.

The ipc pagage provides several objects which make managing inter processes communications easier. The ipc package is built on top of Go's channels. Within the package is a generic message which provides request and response support and a tickler object which allows an application to schedule periodic messages to be delivered on one or more channels.

Index

Constants

View Source
const (
	FOREVER int = 0
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Chmsg

type Chmsg struct {
	Msg_type       int         // action requested
	Response_ch    chan *Chmsg // channel to write this request back onto when done
	Response_data  interface{} // what might be useful in addition to the state
	Req_data       interface{} // necessary information to processes the request
	Requestor_data interface{} // private data meaningful only to the requestor and
	// necessary to process an asynch response to the message.
	State error // response state, nil == no error
}

--------------------------------------------------------------------------------------

Defines a message. Request and response data pointers are used so that in the case
where the requesting thread is not blocking on the response the request data will
be available for response processing if needed. A third data field, requestor_data
is another hook to assist with asynch response processing. This is assumed to point
to a data object that is of no significance to the receiver of the message when
the message is a request.  It should be nil if the response channel is also nil.

The struct allows the application to define how it is used, and does not really imply
any meaning on the fields.

func Mk_chmsg

func Mk_chmsg() (r *Chmsg)

constructor

func (*Chmsg) Send_nbreq

func (r *Chmsg) Send_nbreq(dest_ch chan *Chmsg, resp_ch chan *Chmsg, mtype int, data interface{}, pdata interface{})

Sends the message as a request to the indicated channel. The no-block flag is set which causes the message to be SILENTLY droped if the reciving channel is blocking.

func (*Chmsg) Send_req

func (r *Chmsg) Send_req(dest_ch chan *Chmsg, resp_ch chan *Chmsg, mtype int, data interface{}, pdata interface{})

Send the message as a request oriented packet. Data is mapped to request data, while response data and state are set to nil. Pdata is the private requestor data.

func (*Chmsg) Send_resp

func (r *Chmsg) Send_resp(data interface{}, state error)

Send the request as a response oriented packet. The response channel is used to send the block. Data is mapped to response data and state is set. All other fields are left unchanged.

type Tickler

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

Manages the user's list of tickle spots.

func Mk_tickler

func Mk_tickler(max int) (t *Tickler)

Create a tickle manager that can handle up to max concurrent tickles. We'll cap tickles at 1024 and default to 100 if 0 passed in as max.

func (*Tickler) Add_spot

func (t *Tickler) Add_spot(delay int64, ch chan *Chmsg, ttype int, data interface{}, count int) (id int, err error)

Adds something to the tickle list. Delay is the number of seconds between tickles and will be set to 1 if it is less than that. Data is any object (best if it's a pointer to something) that will be sent on each tickle request. The return is the 'id' of the tickle that can be used to drop it, and an error if we could not add the tickle spot.

Add is synchronous so concurrent goroutines which share a common tickler can safely add their tickle spots without worry of corruption.

Tickle spots should be added in increasing delay order, or the tickler should be stopped until all tickle spots have been added. This prevents a long tickle spot from becoming active and blocking shorter tickles until the first long tickle 'pops'.

func (*Tickler) Allow_to_block

func (t *Tickler) Allow_to_block(v bool)

Allow the user to control blocking mode of all tickle spots.

func (*Tickler) Drop_spot

func (t *Tickler) Drop_spot(id int)

Drop the tickle_spot from the active list.

func (*Tickler) Start

func (t *Tickler) Start()

Restarts the tickler.

func (*Tickler) Stop

func (t *Tickler) Stop()

Stops the tickler.

Directories

Path Synopsis
Provides a message routing interface.
Provides a message routing interface.

Jump to

Keyboard shortcuts

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