Skip to content
Back to skills

C Linux Socket Wrapper Implementation

ASecurity

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

  • 17 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added May 30, 2026
businessgoc++

Works with

  • cli

Security analysis

A100/100

Scanned May 30, 2026

npx -y skills add gabrielmoreira/agent-skills-mirror --skill c-linux-socket-wrapper-implementation --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of C Linux Socket Wrapper Implementation?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for C Linux Socket Wrapper Implementation
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/gabrielmoreira-c-linux-socket-wrapper-implementation/badge)](https://www.skillsdirectory.com/skills/gabrielmoreira-c-linux-socket-wrapper-implementation)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
id: "e06874b8-588c-4532-87eb-dd0429975456"
name: "C++ Linux Socket Wrapper Implementation"
description: "Implement a C++ wrapper for Linux TCP sockets and file descriptors with unique ownership semantics, including FileDescriptor, Socket, Connection, Server, and Client classes."
version: "0.1.0"
tags:
  - "cpp"
  - "linux"
  - "sockets"
  - "networking"
  - "raii"
  - "systems-programming"
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"
---

# 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

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.