{"id":30660769,"url":"https://github.com/weavejester/teensyp","last_synced_at":"2025-10-25T00:44:57.344Z","repository":{"id":303821591,"uuid":"1016760086","full_name":"weavejester/teensyp","owner":"weavejester","description":null,"archived":false,"fork":false,"pushed_at":"2025-07-22T00:00:55.000Z","size":110,"stargazers_count":19,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-02T10:52:22.950Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Clojure","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/weavejester.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-07-09T13:35:54.000Z","updated_at":"2025-07-24T09:29:49.000Z","dependencies_parsed_at":"2025-07-09T16:27:39.065Z","dependency_job_id":"7e1b85b8-9869-4976-81d8-21a9f5217b2c","html_url":"https://github.com/weavejester/teensyp","commit_stats":null,"previous_names":["weavejester/teensyp"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/weavejester/teensyp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weavejester%2Fteensyp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weavejester%2Fteensyp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weavejester%2Fteensyp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weavejester%2Fteensyp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/weavejester","download_url":"https://codeload.github.com/weavejester/teensyp/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weavejester%2Fteensyp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280889069,"owners_count":26408478,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-24T02:00:06.418Z","response_time":73,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-08-31T14:13:26.844Z","updated_at":"2025-10-25T00:44:57.314Z","avatar_url":"https://github.com/weavejester.png","language":"Clojure","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TeensyP [![Build Status](https://github.com/weavejester/teensyp/actions/workflows/test.yml/badge.svg)](https://github.com/weavejester/teensyp/actions/workflows/test.yml)\n\nA small, zero-dependency Clojure TCP server that uses Java NIO.\n\n## Installation\n\nAdd the following dependency to your deps.edn file:\n\n    dev.weavejester/teensyp {:mvn/version \"0.3.0\"}\n\nOr to your Leiningen project file:\n\n    [dev.weavejester/teensyp \"0.3.0\"]\n\n## Usage\n\nAt minimum, TeensyP requires a port to listen on and a handler function:\n\n```clojure\n(require '[teensyp.server :as tcp])\n\n(tcp/start-server {:port 3000, :handler demo-handler})\n```\n\nThe handler function has three arities, and defines how the server\nbehaves.\n\n```clojure\n(import 'java.nio.ByteBuffer)\n\n(defn demo-handler\n  ([write]\n   ;; With 1 argument, we can write ByteBuffers via the write function.\n   ;; The return value is the channel's state.\n   {:read-bytes 0})\n  ([state ^ByteBuffer buffer write]\n   ;; With 3 arguments, we handle read data stored in a ByteBuffer. We\n   ;; can update the channel's state by returning a new value, and write\n   ;; to the output channel with the write function.\n   (update state :read-bytes + (.remaining buffer)))\n  ([state exception]\n   ;; With 2 arguments, we have the channel closing. If it closed due to an\n   ;; exception, that exception is passed as the second argument, otherwise it\n   ;; will be nil.\n   (println \"Total bytes:\" (:read-bytes state))\n  ))\n```\n\nThe handler maintains a `state`, which can be any Clojure data\nstructure, but is usually a map. This state is unique to the channel,\nand is updated each time the channel is read from by the 3-arity form of\nthe handler.\n\n### Writes\n\nThe `write` function accepts a single `ByteBuffer` argument, or one of\nthree special marker objects:\n\n- `teensyp.server/CLOSE`        - closes the channel\n- `teensyp.server/PAUSE-READS`  - pause reads until resumed\n- `teensyp.server/RESUME-READS` - resume reads\n\nYou may also specify a second argument to `write`. This is a zero\nargument callback function that will be called when the write completes.\n\n### Guarantees\n\nTeensyP makes several guarantees that apply per-channel:\n\n- The 1-arity accept is always called first.\n- The 2-arity close is always called last.\n- The current handler call for the channel must finish before the next\n  can begin.\n- The write queue queue must be empty before the handler is called.\n\n### Server Options\n\nThe `start-server` function takes a number of options:\n\n| Key                  | Description                                     | Mandatory | Default |\n|----------------------|-------------------------------------------------|-----------|---------|\n| `:executor`          | An `ExecutorService` to use for handler calls   |           |         |\n| `:handler`           | The handler function                            | Yes       |         |\n| `:port`              | The port number to listen on                    | Yes       |         |\n| `:read-buffer-size`  | The size in bytes of the channel read buffer    |           | 8K      |\n| `:write-buffer-size` | The size in bytes of the channel write buffer   |           | 32K     |\n| `:write-queue-size`  | The maximum number of writes that can be queued |           | 64      |\n\n## Documentation\n\n- [API Documentation](https://weavejester.github.io/teensyp)\n\n## License\n\nCopyright © 2025 James Reeves\n\nThis program and the accompanying materials are made available under the\nterms of the Eclipse Public License 2.0 which is available at\nhttp://www.eclipse.org/legal/epl-2.0.\n\nThis Source Code may also be made available under the following Secondary\nLicenses when the conditions for such availability set forth in the Eclipse\nPublic License, v. 2.0 are satisfied: GNU General Public License as published by\nthe Free Software Foundation, either version 2 of the License, or (at your\noption) any later version, with the GNU Classpath Exception which is available\nat https://www.gnu.org/software/classpath/license.html.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweavejester%2Fteensyp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fweavejester%2Fteensyp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweavejester%2Fteensyp/lists"}