# README
elio
elio
means event loop io library.
This library allows you to quickly write epoll-based servers.
Apps written using elio
library
π Running Echo
Echo
is a simple echo server.
π Running Herald
Herald
is a simple MQTT pub/sub test client.
- Docker Hub: cppis/herald
Under the Hood of Echo
app/echo
is simple echo server written by elio
.
This is the main function of app/echo
:
package main
import (
"github.com/cppis/elio"
)
func main() {
app := elio.Elio()
echo := NewEcho(app)
app.Register(echo)
app.Run()
app.Wait()
}
The echo
generated by NewEcho
is a implementation of elio
service interface:
elio
service interface has following method signatures:
package elio
import (
"context"
"time"
)
// Service service
type Service interface {
Name() string
OnInit(ctx context.Context, cancel context.CancelFunc) error
OnExit()
OnOpen(s *Session) error
OnClose(s *Session, err error)
OnError(s *Session, err error)
OnRead(s *Session, in []byte) int
OnWrite(s *Session, out []byte)
OnLoop(host *IoHost, t time.Time, d time.Duration)
}
If network I/O event happens, elio
calls proper event method of service.
This is a event implementations of echo
service:
func (e *Echo) OnOpen(s *elio.Session) error {
fmt.Printf("o")
return nil
}
func (e *Echo) OnClose(s *elio.Session, err error) {
fmt.Printf("c")
}
func (e *Echo) OnError(s *elio.Session, err error) {
fmt.Printf("e")
}
func (e *Echo) OnRead(s *elio.Session, in []byte) (processed int) {
fmt.Printf("+%d", len(in))
s.Write(in)
if 'q' == in[0] {
elio.Elio().End()
}
return processed
}
func (e *Echo) OnWrite(s *elio.Session, out []byte) {
fmt.Printf("-%d", len(out))
}
Service also has loop callback for running logics at regular intervals:
const (
// defaultFetchLimit default fetch limit
defaultFetchLimit int = 2000
)
func (e *Echo) OnLoop(host *elio.IoHost, t time.Time, d time.Duration) {
//host.RunDivision(t, r.callbackDivision)
_, _ = host.Dispatching(t, defaultFetchLimit)
e.prev = t
}
# Functions
AppDebug app log debug.
AppError app log error.
AppFatal app log fatal.
AppInfo app log info.
AppPanic app log panic.
AppTrace app log trace.
AppWarn app log warn.
DebugEnabled debug enabled.
DeleteSession delete session.
DumpDebug packet log debug.
DumpError packet log error.
DumpFatal packet log fatal.
DumpInfo packet log info.
DumpPanic packet log panic.
DumpTrace packet log trace.
DumpWarn packet log warn.
Elio get elio.
ErrorEnabled error enabled.
FatalEnabled fatal enabled.
GenIO gen io.
GetBaseAndConfig get base and config.
GetBasename get base name.
GetBasepath get base path.
GetCurrentIO get current io.
GetFdFromConn this function is linux only.
GetFdFromLisener this function is linux only.
GetMaxInCount get max in count.
Host host.
InfoEnabled info enabled.
InitLog init log.
IOsFromString IO models from string.
LogDebug app log debug.
LogError app log error.
LogFatal app log fatal.
LogInfo app log info.
LogPanic app log panic.
LogParams get log params.
LogTrace app log trace.
LogWarn app log warn.
NewApp new app.
NewClock new clock.
NewConfig new config.
NewContext create new context.
NewDivMap new division map.
NewEventQueue new event queue.
NewIo new server.
NewIoDefault new io default.
NewIoHost new host.
NewIoPoll new io poll.
NewMqttClient new mqtt client.
NewPoll create poll.
NewSafeSlice creates a new safe slice.
NewSession new session.
NewUnsafeMap creates a new unsafe map.
NewUnsafeSlice creates a new concurrent slice.
PacketDebug packet log debug.
PacketError packet log error.
PacketFatal packet log fatal.
PacketInfo packet log info.
PacketPanic packet log panic.
PacketTrace packet log trace.
PacketWarn packet log warn.
PanicEnabled panic enabled.
PanicParse panic parse.
ProvideConfigIo returns service config.
ProvideIo provide service.
SetLimit set limit.
StackParse stack parse.
StartUp start up.
StopDown stop down.
T2pOnParse control on parse.
T2PParse T2P parse.
T2pParseCommand parse command.
TraceEnabled debug enabled.
WarnEnabled debug enabled.
WithLevel with level.
# Constants
CaptureInterval capture interval.
Close disconnect connection.
CloseAll disconnect all connections.
todo range λ³ ν΄λΌ μ‘μ
μ μ νλκ²..? ex) 100λ²λλ μλ¬λ¦¬ν΄ ν νμ΄νλ‘ μ΄λ 200λ²λλ μλ¬λ§ μΆλ ₯ μ΄λ°μμΌλ‘..
DefaultCapacity default capacity.
DefaultDefIOInCount default def IO in count.
DefaultInterval default interval.
DefaultPollInCount default poll in count.
DevLogger development logger.
Duration5m duration 5 minute.
todo μΆν μμ μμ , μν μλ²μμ μ¬μ©νλ μ½λλ μλ¨μ μ½λλ‘ κ΅μ²΄ νμ (μ¬μ©νλ μ½λλ μλ¨μλ§ μ‘΄μ¬).
todo μΆν μμ μμ , μν μλ²μμ μ¬μ©νλ μ½λλ μλ¨μ μ½λλ‘ κ΅μ²΄ νμ (μ¬μ©νλ μ½λλ μλ¨μλ§ μ‘΄μ¬).
todo μΆν μμ μμ , μν μλ²μμ μ¬μ©νλ μ½λλ μλ¨μ μ½λλ‘ κ΅μ²΄ νμ (μ¬μ©νλ μ½λλ μλ¨μλ§ μ‘΄μ¬).
todo μΆν μμ μμ , μν μλ²μμ μ¬μ©νλ μ½λλ μλ¨μ μ½λλ‘ κ΅μ²΄ νμ (μ¬μ©νλ μ½λλ μλ¨μλ§ μ‘΄μ¬).
ExamLogger example logger.
FlagAllout disconnect all flag.
FlagNone default none flag.
FlagSafeTerminate safe terminate flag.
FlagStop stop listen flag.
FlagTerminate terminate flag.
FlagTerminateAfter5m exit after 5 minute flag.
InvalidDivIndex partition invalid index.
IoAuto IO auto.
IoDefault IO default(golang method).
IoPoll IO poll.
Listen listen.
LogCode code.
LogContext context.
LogDump dump.
LogErrorCode errorcode.
LogGitHash git last commit hash.
LogHost host.
LogIP ip.
LogMatchKey match key.
LogName name.
LogObject object.
LogPayload payload.
LogProject project.
LogRecover recover.
LogRoom room.
LogService service.
LogSession session.
LogStage stage.
LogState state.
LogSuid server unique id.
LogUuid user unique id.
LogWalltime walltime.
MetricAppIoInCountf app io in count metric.
MetricAppIoInSizef app io in size metric.
MetricAppIoOutCountf app io out count metric.
MetricAppIoOutSizef app io out size metric.
MetricAppSessionsf app session metric.
MetricPubAppStatesf publish app state metric.
MetricSubAppStatesf subscribe app state metric.
None indicates that no action should occur following an event.
No description provided by the author
ProdLogger production logger.
QueueCapacity queue default capacity.
μ΄λ―Έ λ°©μμ μλ μνμΈ κ²½μ°.
μ΄λ―Έ λ‘κ·ΈμΈ μνμΈ κ²½μ°.
μ€λ³΅λ‘κ·ΈμΈ.
Frontend & Relayer.
Frontend & Relayer.
Frontend & Relayer.
Frontend & Relayer.
Frontend & Relayer.
http ν΅μ μλ¬.
message marshal error.
λ°©μμ μλ μνκ° μλ κ²½μ°.
λ‘κ·ΈμΈ μνκ° μλ κ²½μ°.
λ°©μ΄ μ‘΄μ¬ & μ μ λ₯Ό κΈ°λ€λ¦¬λ μνκ° μλ κ²½μ°.
packet unpack error.
SafeTermiate close the listen and exit when no user.
Shut close the listen.
ShutRd shut rd.
ShutRdWr shut rdwr.
ShutWr shut wr.
SigInt sig int.
SigTerm sig term.
StatsDAddress statsd address.
StatsDInterval capture interval.
todo range λ³ ν΄λΌ μ‘μ
μ μ νλκ²..? ex) 100λ²λλ μλ¬λ¦¬ν΄ ν νμ΄νλ‘ μ΄λ 200λ²λλ μλ¬λ§ μΆλ ₯ μ΄λ°μμΌλ‘..
Termiate terminate the server.
TermiateAfter5m shutdown after 5 minute.
# Variables
GetByteBuffer returns an empty byte buffer from the pool, exported from gnet/bytebuffer.
PutByteBuffer returns byte buffer to the pool, exported from gnet/bytebuffer.
UIDInvalid uid invalid.
# Structs
App app.
AppMetrics app metrics.
Buffer is a helper type for managing input streams from inside the Data event.
Clock clock.
Config config.
ConfigIo config service.
Context implementation.
DivMap division map.
EnvApp env app ELIO_LOG_LEVEL ELIO_LOG_OUTS ELIO_LOG_JSON ELIO_LOG_NOCOLOR ELIO_IN_METRIC ELIO_IN_PPROF.
EventQueue event queue.
Io IO.
IoHost host.
Listener listener.
MqttClient mqtt client.
Poll event poll object.
PollEvent poll event.
SafeSlice safe slice.
SafeSliceItem contains the index/value pair of an item in a concurrent slice.
Session session.
UnsafeMap safe map.
UnsafeMapItem contains a key/value pair item of a concurrent map.
UnsafeSlice safe slice.
UnsafeSliceItem contains the index/value pair of an item in a concurrent slice.
WaitResult wait result.
WriteJob write job.
# Type aliases
Action is an action that occurs after the completion of an event.
ByteBuffer is the alias of bytebufferpool.ByteBuffer.
DivCallback metric callback.
Fnv32 fnv32 type definition.
Fnv64 fnv64 type definition.
IOs io models type definition.
OnFilter on filter.
Sockaddr sockaddr type definition.
UID uid μ¬μ©μ ID μ μ νμ
KBO(CPB)μ uid, MLBμ vid κ°.