AutoSkill 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.
install
source · Clone the upstream repo
git clone https://github.com/ECNU-ICALK/AutoSkill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/english_gpt4_8_GLM4.7/tcp-socket-optimization-function" ~/.claude/skills/ecnu-icalk-autoskill-tcp-socket-optimization-function && rm -rf "$T"
manifest:
SkillBank/ConvSkill/english_gpt4_8_GLM4.7/tcp-socket-optimization-function/SKILL.mdsource content
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
- Function Signature: The function must accept a socket file descriptor (
) and a boolean flag (e.g.,int sockfd
).int optimize_for_latency - Socket Options: Configure the following options using
:setsockopt
: Set toIP_TOS
for low latency,IPTOS_LOWDELAY
for throughput.IPTOS_THROUGHPUT
: Enable (1) for low latency, disable (0) for throughput.TCP_NODELAY
: Enable (1) for low latency, disable (0) for throughput.TCP_QUICKACK
(Linux) /TCP_CORK
(BSD): Disable (0) for low latency, enable (1) for throughput.TCP_NOPUSH
- Platform Compatibility: Use preprocessor directives (
,#ifdef TCP_CORK
) to handle platform differences between Linux and BSD systems.#ifdef TCP_NOPUSH - Control Flow: Use traditional
statements for logic control. Do NOT use the ternary operator (if-else
).? - Error Handling: Check the return value of
and return -1 on error, 0 on success.setsockopt - 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
, etc.).netinet/tcp.h - 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