gpt-4-0125-preview· OpenAI
WildChat-4.8M (AI2)
Give me an example of getsockopt so_rcvbuf on Linux in C. Answer shortly
- User
Give me an example of getsockopt so_rcvbuf on Linux in C. Answer shortly
- Assistant
Certainly! Here's a short example of using
getsockoptto retrieve the size of theSO_RCVBUFoption, which is the receive buffer size, for a socket in Linux using C:#include <stdio.h> #include <string.h> #include <sys/socket.h> #include <unistd.h> int main() { int sock = socket(AF_INET, SOCK_STREAM, 0); if (sock == -1) { perror("socket"); return 1; } int recvBufSize; socklen_t optSize = sizeof(recvBufSize); // Get socket option if (getsockopt(sock, SOL_SOCKET, SO_RCVBUF, &recvBufSize, &optSize) == -1) { perror("getsockopt"); close(sock); return 1; } printf("Socket receive buffer size: %d\n", recvBufSize); close(sock); return 0; }This code snippet creates a TCP socket, retrieves its receive buffer size using
getsockoptwith theSO_RCVBUFoption, and then prints the size. Be sure to compile it with a C compiler likegccand link with the standard libraries.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.