How allenxuxu/gev works
gev is a Go TCP reactor library for building custom-protocol and WebSocket servers. A client connects through the listener; the server assigns its connection to a worker event loop, which dispatches socket events. The connection buffers and unpacks frames, invokes the application handler, packs any response, and schedules writes on the loop. The README also documents multi-loop load balancing, async sends, idle cleanup, and scheduled tasks. Plugin internals are represented from documented capabilities and the sampled plugin files; unsampled connection and listener wiring is shown only where documented.
Main entry points: server.go Server · connection.go Connection · eventloop.go Event loop · protocol.go Protocol interface
Components 17
Server lifecycle
- Server
server.go - Listener
listener.go - Loop strategy
load_balance.go
Reactor I/O
- Event loop
eventloop/eventloop.go - OS poller
poller/poller.go - Connection
connection.go - Ring buffer
Protocol support
- Protocol interface
protocol.go - Protobuf plugin
plugins/protobuf/protocol.go - WebSocket protocol
plugins/websocket/protocol.go - WebSocket handler wrap
plugins/websocket/wrap.go - WebSocket framing
plugins/websocket/ws/ws.go
Timers and options
- Timing wheel
- Scheduled tasks
everyscheduler.go - Server options
options.go
Other components
- TCP client
- Application handler
Connections 24
- TCP client → Listener: connects
- Server → Listener: starts
- Listener → Server: accepted fd
- Server → Loop strategy: selects loop
- Server → Event loop: runs workers
- Server → Connection: creates
- Server → Application handler: connect callback
- Event loop → OS poller: polls events
- OS poller → Event loop: dispatches events
- Event loop → Connection: dispatches socket events
- Connection → Ring buffer: buffers bytes
- Connection → Protocol interface: unpacks frames
- Connection → Application handler: delivers messages
- Application handler → Connection: returns response
- Connection → Protocol interface: packs responses
- Connection → Event loop: queues async writes
- Server → Server options: configures
- Server → Timing wheel: starts timers
- Server → Scheduled tasks: schedules recurring tasks
- Scheduled tasks → Timing wheel: uses
- Protobuf plugin → Protocol interface: implements
- WebSocket protocol → Protocol interface: implements
- WebSocket protocol → WebSocket framing: parses and frames
- WebSocket handler wrap → Application handler: delegates messages