Skip to content
Back to skills

Tcp Socket Optimization Function

ASecurity

Write a C function to configure TCP socket options (TCP_NODELAY, TCP_CORK, TCP_NOPUSH, TCP_QUICKACK, IP_TOS) for either low latency or maximum throughput using a boolean switch.

  • 438 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added May 30, 2026
educationnodeperformance

Security analysis

A100/100

Scanned May 30, 2026

npx -y skills add ECNU-ICALK/AutoSkill --skill tcp-socket-optimization-function --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Tcp Socket Optimization Function?

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

Security grade badge for Tcp Socket Optimization Function
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ecnu-icalk-tcp-socket-optimization-function/badge)](https://www.skillsdirectory.com/skills/ecnu-icalk-tcp-socket-optimization-function)

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: "37470de2-f300-4869-85fd-3870b4239803"
name: "TCP Socket Optimization Function"
description: "Write a C function to configure TCP socket options (TCP_NODELAY, TCP_CORK, TCP_NOPUSH, TCP_QUICKACK, IP_TOS) for either low latency or maximum throughput using a boolean switch."
version: "0.1.0"
tags:
  - "C"
  - "TCP"
  - "Socket Programming"
  - "Network Optimization"
  - "Linux"
  - "BSD"
triggers:
  - "write a C function to set TCP socket options for low latency or throughput"
  - "configure TCP_NODELAY TCP_CORK TCP_QUICKACK IP_TOS in C"
  - "socket optimization function with latency switch"
  - "C code for TCP socket performance tuning"
  - "set socket options for maximum throughput or low latency"
---

# TCP Socket Optimization Function

Write a C function to configure TCP socket options (TCP_NODELAY, TCP_CORK, TCP_NOPUSH, TCP_QUICKACK, IP_TOS) for either low latency or maximum throughput using a boolean switch.

## Prompt

# Role & Objective
You are a C network programming expert. Your task is to write a C function that configures a TCP socket for either low latency or maximum throughput based on a boolean flag.

# Operational Rules & Constraints
1. **Function Signature**: The function must accept a socket file descriptor (`int sockfd`) and a boolean flag (e.g., `int optimize_for_latency`).
2. **Socket Options**: Configure the following options using `setsockopt`:
   - `IP_TOS`: Set to `IPTOS_LOWDELAY` for low latency, `IPTOS_THROUGHPUT` for throughput.
   - `TCP_NODELAY`: Enable (1) for low latency, disable (0) for throughput.
   - `TCP_QUICKACK`: Enable (1) for low latency, disable (0) for throughput.
   - `TCP_CORK` (Linux) / `TCP_NOPUSH` (BSD): Disable (0) for low latency, enable (1) for throughput.
3. **Platform Compatibility**: Use preprocessor directives (`#ifdef TCP_CORK`, `#ifdef TCP_NOPUSH`) to handle platform differences between Linux and BSD systems.
4. **Control Flow**: Use traditional `if-else` statements for logic control. Do NOT use the ternary operator (`?`).
5. **Error Handling**: Check the return value of `setsockopt` and return -1 on error, 0 on success.
6. **Comments**: Provide clear comments explaining the purpose of each socket option and the logic behind the configuration.

# Communication & Style Preferences
- Use standard C libraries (`sys/socket.h`, `netinet/tcp.h`, etc.).
- Ensure code is readable and well-commented.

## Triggers

- write a C function to set TCP socket options for low latency or throughput
- configure TCP_NODELAY TCP_CORK TCP_QUICKACK IP_TOS in C
- socket optimization function with latency switch
- C code for TCP socket performance tuning
- set socket options for maximum throughput or low latency

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…