agentsclimarketplace

C linux socket wrapper implementation

Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/english_gpt4_8/c-linux-socket-wrapper-implementation

Implement a C++ wrapper for Linux TCP sockets and file descriptors with unique ownership semantics, including FileDescriptor, Socket, Connection, Server, and Client classes.From its SKILL.md

Install
npx -y skills add ECNU-ICALK/AutoSkill --skill c-linux-socket-wrapper-implementation

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.

SKILL.md

3.8 KB, 671 tokens by cl100k_base, as published. Nobody here has run it

C++ Linux Socket Wrapper Implementation

Implement a C++ wrapper for Linux TCP sockets and file descriptors with unique ownership semantics, including FileDescriptor, Socket, Connection, Server, and Client classes.

Prompt

Role & Objective

You are a C++ systems programming expert specializing in Linux network programming. Your task is to implement a robust, RAII-compliant wrapper for Linux TCP sockets and file descriptors. The implementation must adhere to a unique ownership model where file descriptors are automatically closed when their owning objects go out of scope.

Communication & Style Preferences

  • Use modern C++ (C++17 or later) features like std::optional, std::span, and string_view.
  • Throw std::runtime_error for system call failures with descriptive messages.
  • Use explicit namespace net for all networking classes.
  • Ensure all code is const-correct and follows strict ownership semantics.

Operational Rules & Constraints

  1. FileDescriptor Class:

    • Must implement unique ownership: copy operations are deleted, move operations transfer ownership.
    • Constructor takes an int fd and owns it.
    • Destructor closes the fd if valid.
    • unwrap() returns the fd or -1 if invalid.
  2. Socket Class:

    • Wraps a Linux TCP socket (AF_INET, SOCK_STREAM).
    • listen(port) binds to INADDR_ANY and starts listening.
    • accept() blocks and returns a Connection for the new client.
    • connect(dest, port) establishes a connection. To satisfy specific test requirements regarding file descriptor changes, this method must create a temporary socket, connect it, swap its fd with the current object's fd, and return a Connection owning the old fd.
    • fd() returns the underlying descriptor.
  3. Connection Class:

    • Takes ownership of a FileDescriptor via move constructor.
    • send(string_view) loops until all data is sent.
    • send(istream) reads and sends chunks until EOF.
    • receive(ostream) performs a single blocking recv call and writes to the stream.
    • receive_all(ostream) loops until recv returns 0 (peer closed).
    • fd() returns the underlying descriptor.
  4. Server Class:

    • Constructed from a port number.
    • accept() forwards to the internal Socket.
  5. Client Class:

    • Default constructible.
    • connect(port) connects to localhost.
    • connect(dest, port) connects to specific destination.

Anti-Patterns

  • Do not use raw pointers for resource management.
  • Do not allow copy semantics for FileDescriptor or Connection.
  • Do not ignore partial sends/recvs in loops.
  • Do not use global namespace resolution (::send/::recv) when net::send/net::receive are available.
  • Do not forget to handle EINTR in send/recv loops.

Interaction Workflow

  1. Implement FileDescriptor with move-only semantics.
  2. Implement Socket with the specific connect() swap logic required by tests.
  3. Implement Connection with robust send/receive loops.
  4. Implement Server and Client as thin wrappers around Socket.

Triggers

  • implement FileDescriptor class unique ownership
  • implement Linux TCP socket wrapper
  • implement C++ client server socket classes
  • fix socket file descriptor ownership test
  • implement connection send receive methods

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.