Commit 0f5fce41 authored by Gero Hülsbusch's avatar Gero Hülsbusch
Browse files

Update echo_server_IPv6.c

parent 2551123e
......@@ -4,14 +4,17 @@
#include "Socket.h"
//called for each connection
void *handle_connection(void *arg) {
ssize_t read_len, send_len;
char buf[BUFFER_SIZE];
int client_fd = *(int*)arg;
free(arg);
do {
//read from client
read_len = recv_wrapper(client_fd, (void *) buf, sizeof(buf), 0);
send_len = 0;
//send back to client
while (send_len < read_len) {
send_len += send_wrapper(client_fd, (void *) (buf+send_len), read_len - send_len, 0);
}
......@@ -27,6 +30,7 @@ int main (int argc, char **argv) {
pthread_t client_thread;
struct sockaddr_in server_addr;
//create an IPv6 socket
server_fd = socket_wrapper(AF_INET6, SOCK_STREAM, IPPROTO_TCP);
memset(&server_addr, 0, sizeof(server_addr));
server_addr.sin_family = AF_INET6;
......@@ -52,6 +56,7 @@ int main (int argc, char **argv) {
*thread_fd = accept_wrapper(server_fd, NULL, NULL);
//create a thread for each client
pthread_create(&client_thread, NULL, &handle_connection, (void *) thread_fd);
pthread_detach(client_thread);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment