commit | 56c79d7770f76ca102977c814b8375dd9f8d23b2 | [log] [tgz] |
---|---|---|
author | jason <lvs.pjx@gmail.com> | Sun Nov 14 22:04:03 2021 +0800 |
committer | jason <lvs.pjx@gmail.com> | Sun Nov 14 22:04:03 2021 +0800 |
tree | 9586fd43ed57a79f8a3841a63a27b53925357836 | |
parent | 60b2b74cfe09e1be596ccf82df48da7f17261278 [diff] |
use lock on write method
a netty like asynchronous network I/O library
Getty is a asynchronous network I/O library in golang. Getty works on tcp/udp/websocket network protocol and supplies a uniform interface.
In getty there are two goroutines in one connection(session), one reads tcp stream/udp packet/websocket package, the other handles logic process and writes response into network write buffer. If your logic process may take a long time, you should start a new logic process goroutine by yourself in codec.go:(Codec)OnMessage.
You can also handle heartbeat logic in codec.go:(Codec):OnCron. If you use tcp/udp, you should send hearbeat package by yourself, and then invoke session.go:(Session)UpdateActive to update its active time. Please check whether the tcp session has been timeout or not in codec.go:(Codec)OnCron by session.go:(Session)GetActive.
Whatever if you use websocket, you do not need to care about hearbeat request/response because Getty do this task in session.go:(Session)handleLoop by sending/received websocket ping/pong frames. You just need to check whether the websocket session has been timeout or not in codec.go:(Codec)OnCron by session.go:(Session)GetActive.
Apache License 2.0