networking and threads

This page summarizes the projects mentioned and recommended in the original post on /r/lisp

Our great sponsors
  • WorkOS - The modern identity platform for B2B SaaS
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • SaaSHub - Software Alternatives and Reviews
  • CIEL

    CIEL Is an Extended Lisp. Scripting with batteries included.

  • I've been doing the protohackers challenges in common lisp to learn, and I ran into a problem that is possibly a bug in the socket library, or much more likely in my misunderstanding it. At any rate the best workaround a found seems pretty ugly, so can anyone advice what would be the cleanest way to solve it, and how we're supposed to deal with sockets? The problem is basically make a tcp server, that forwards all connections to an upstream server, and does a regex find and replace on all the traffic that passes through. Here's my working solution. I haven't learned much how asdf and packages work yet, I am just using CIEL which is SBCL (2.2.9.debian) with a bunch of libraries already loaded, I think if you load usocket, usocket-server, cl-ppcre, and bordeaux-threads it should run. The program is simple, I just forward all traffic from the client to the upstream doing regex replacement on each line, and spawn a thread that handles forwarding all traffic from the upstream to the client with the regex replacement. The issue is that when the client disconnects, my program doesn't disconnect from the upstream, even when I call (close upstream) and (socket-close socket). Before closing the socket or stream, the connection shows as established in ss -tp and as belonging to the sbcl process. After calling close on the socket and stream, the connection still shows as established, just it no longer shows as belonging to the sbcl process, and tcpdump shows that the 4-way termination handshake is not sent. After killing the background thread that is also reading the same socket, the 4-way termination is sent, and the connection is closed. It seems like calling close on the stream or socket should close it? Are sockets or streams not safe to share between threads? Is there a cleaner way to handle closing the upstream connection when the client disconnects rather than calling destroy thread?

  • WorkOS

    The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.

    WorkOS logo
NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts