aboutsummaryrefslogtreecommitdiff
path: root/lib/websocket/server.go
AgeCommit message (Collapse)Author
2025-01-22lib/bytes: replace Copy and Concat with standard libraryShulhan
Since Go 1.20, the standard bytes package have the Copy function. Since Go 1.22, the standard slices package have the Concat function.
2024-03-02all: move the repository to "git.sr.ht/~shulhan/pakakeh.go"Shulhan
There are several reasons that why we move from github.com. First, related to the name of package. We accidentally name the package with "share" a common word in English that does not reflect the content of repository. By moving to other repository, we can rename it to better and unique name, in this "pakakeh.go". Pakakeh is Minang word for tools, and ".go" suffix indicate that the repository related to Go programming language. Second, supporting open source. The new repository is hosted under sourcehut.org, the founder is known to support open source, and all their services are licensed under AGPL, unlike GitHub that are closed sources. Third, regarding GitHub CoPilot. The GitHub Terms of Service [1], allow any public content that are hosted there granted them to parse the content. On one side, GitHub helps and flourish the open source, but on another side have an issues regarding scraping the copyleft license [2]. [1]: https://docs.github.com/en/site-policy/github-terms/github-terms-of-service#4-license-grant-to-us [2]: https://githubcopilotinvestigation.com
2023-12-13all: fix linter warnings reported by reviveShulhan
There are some reports that I disagree with revive, in example, code should not declare the type after variables. In my opinion, on some cases, declaring the type make the code more readable and explicit. Since I did not want to add new configuration file, we changes it and follow revive for now.
2023-09-11lib/websocket: suppress unused parameter using "_"Shulhan
This fix some linter warnings on dummy methods and handlers.
2023-07-03lib/websocket: stop goroutines when no queue received after N durationShulhan
When the goroutine for upgrade, reader, or pinger does not receive any input from its queue after N duration, stop it. Currently, N equal to ServerOptions ReadWriteTimeout. This allow unused goroutines released back to system, minimizing resources usage.
2023-07-01lib/websocket: reformat comments and documentationShulhan
2023-07-01lib/websocket: handle concurrent ping using goroutinesShulhan
The maximum goroutines is quarter of max queue. The new goroutine for pinger will be dispatched when no goroutine can consume the current processed connection.
2023-07-01lib/websocket: prefix the error with function or method namesShulhan
Adding prefix provide better way to locate and debug the error in the future.
2023-07-01lib/websocket: handle concurrent Server read using goroutinesShulhan
The Server now dispatch a goroutine to consume event from poll reader for each client connection that is ready to read. The maximum number of goroutine is defined in ServerOptions maxGoroutineReader, which currently set to 1024.
2023-07-01lib/websocket: handle concurrent upgrade using goroutineShulhan
The maxGoroutineUpgrader define maximum goroutines running at the same time to handle client upgrade. The new goroutine only dispatched when others are full, so it will run incrementally not all at once. Default to defServerMaxGoroutineUpgrader (128) if its not set.
2023-06-29lib/websocket: add option to set read/write timeout on ServerShulhan
The ReadWriteTimeout define the maximum duration the server wait when receiving/sending packet from/to client before considering the connection as broken. Default read-write timeout is 30 seconds if not set. This changes affect the exported function Send and Recv by adding additional parameter timeout to both of them.
2023-06-04lib/websocket: increase the max buffer and queue for better throughputShulhan
The maxBuffer increased from 1024 to 4096 bytes. The reason that we use 1024 previously is related to MTU size and maximum payload in TCP (although its higher, 1460 bytes). The maxQueue increase from 128 to 4096.
2023-05-20all: remove any usage of debug.Value in all packagesShulhan
Using global debug value for all packages turns out is not a good idea.
2022-07-29lib/websocket: reformat and paraphrase some commentsShulhan
2022-06-09lib/websocket: refactoring codeShulhan
Replace assignment from using ":=" to use variable declaration with type. Rationale: clarity and minimize duplicate temporary variables with the same type.
2022-06-09lib/websocket: realign all struct to minimize allocationsShulhan
Changes, * Client: from 176 to 144 (-32 bytes) * ClientManager: from 64 to 40 (-24 bytes) * Request: from 88 to 72 (-16 bytes) * Response: from 40 to 24 (-16 bytes) * route: from 48 to 32 (-16 bytes) * Server: from 72 to 64 (-8 bytes) * ServerOptions: from 104 to 96 (s-8 bytes) Plus other structs in the tests.
2022-05-09all: reformat all codes using gofmt 1.19 (the Go tip)Shulhan
2022-01-20lib/websocket: return error if parameter is empty on RegisterTextHandlerShulhan
Previously, the RegisterTextHandler method return nil if method, target, or handler parameter is not set. This may cause confusion and hard to debug handler when no connection receive but the RegisterTextHandler does not have any error.
2021-12-20lib/websocket: fix race conditition on handleTextShulhan
Instead of accessing the ctx field directly, call the Context() method to prevent data race.
2021-06-26websocket: export the Options field on the ServerShulhan
Previously, the Options field is not exported to prevent user from changing it once it set throught NewServer() function. This changes export the Options field to allow user of Server access its values. We can create a method on server to return read-only options, but that will over complicated the Server API.
2020-11-26websocket: create buffered channel for running queueShulhan
This is to fix Stop() method waiting for running channel to be consumed.
2020-08-16websocket: remove unused const _pathHealthShulhan
2020-08-11websocket: reformat some filesShulhan
2020-08-11websocket: move the server handler to ServerOptionsShulhan
2020-08-11websocket: add server options to change the connect and status pathsShulhan
Previously, there is only one option for server, the port where it will listen. This changes add option to change the connect path (default to "/" previously) and new path and handler for retrieving server status.
2020-08-10websocket: add HTTP endpoint to check server health statusShulhan
Requesting "GET /health" on WebSocket server will return HTTP status code 204, which can be used for service health checking.
2020-06-09websocket: fix race on pingTicker when stopping serverShulhan
2020-03-26all: fix and suppress linter warningsShulhan
2020-01-22websocket: change the RouteHandler signature to return ResponseShulhan
Previously, the Response in RouteHandler is passed in parameter, which seems weird for handler. This commit, move the Response from parameter to return values.
2019-11-14websocket: add field Conn to represent connection in RequestShulhan
2019-11-14websocket: remove unused error on NewServerShulhan
2019-11-07websocket: fix zero response ID when error on handleTextShulhan
2019-11-05websocket: wrap the response with frame on sendResponseShulhan
2019-11-05websocket: set the response ID after calling handler on handleTextShulhan
This is to prevent the handler change the ID of response.
2019-11-01websocket: replace epoll implementation with libnet.PollShulhan
By using libnet.Poll, websocket package now support both Linux and Darwin/BSD.
2019-03-31websocket/server: remove unnecessary frames nil check on readerShulhan
The check for frames is already done in the above statement, where it will remove the connection and continue the loop.
2019-03-17websocket: update log related formatShulhan
Use "fmt" package when printing debugging information, and "log" package when printing error.
2019-03-17websocket: unexport Frame Pack()Shulhan
The Frame Pack method is only used internally, implementor should use NewFrameXxx functions.
2019-03-17websocket: move isValidFrame as method of FrameShulhan
This is to minimize duplicate code on client and server.
2019-03-17websocket: remove parameter randomMask from Frame.PackShulhan
The decision to randomize mask is now based on whether the maskKey length is equal to 4 or not. If its 4 the maskKey will not be randomized.
2019-03-17websocket: simplify handling chopped frameShulhan
Previously, we use two function to unpack frame: frameUnpack and continueUnpack, both of this functions actually use the same logic. This commit merge both functions into Frame's unpack() and which also make handleChopped() to be unused on both server and client.
2019-03-17websocket: do not cut the close code bytes from frame's payloadShulhan
For control CLOSE frame, the frame's length, close code, and payload are all related. For example, the length of 2 indicate that there is a close code in payload. This change only affect test when unpacking close frame, and does not affect the result of autobahn test.
2019-03-12websocket: fix debug statement with index out of rangeShulhan
2019-03-12websocket: move the process to handle frame into methodShulhan
This is to minimize duplicate code on server's reader and when handling chopped frame.
2019-03-12websocket: move the process to validate client's frame into methodShulhan
This is to minimize duplicate code on server's reader and handling chopped frame.
2019-03-12websocket: export the opcode typeShulhan
The opcode type is required to create new frame and to get the opcode in continous frames.
2019-03-12websocket: unexport internal methods and remove unused methodsShulhan
Some of the methods in ClientManager and Frames should be only accessed by internal server, not by implementor.
2019-03-12websocket: run data frame handler using routinesShulhan
By running the handler on separated routines, we can prevent the server select to be blocked by reading or writing larger packet.
2019-03-11websocket: fix response code for fragmentation with invalid opcodeShulhan
Connection without fragmentation with the first frame is CONT frame, should be closed with bad-request (1002). Connection with fragmentation but the next frame opcode is not CONT, should be closed with bad-request (1002).
2019-03-11websocket: handle chopped frame with interjected control frameShulhan
Another possibility is fragmented frames with one of the frame is chopped and in the middle of it is a control FRAME. For example, C> Frame{fin:false opcode:TEXT len:1024 payload:512} C> payload:512 FRAME{fin:TRUE opcode:PING len:0} C> Frame{fin:true opcode:0 len:1024 payload:1024}