ser6.c - ser6.c(Topic 11 HX An improved version of\"ser5.c This version handles the message boundaries which are not preserved by the TCP Each message

ser6.c - ser6.c(Topic 11 HX An improved version of"ser5.c...

This preview shows page 1 - 2 out of 3 pages.

/* * ser6.c - (Topic 11, HX 22/5/1995) * An improved version of "ser5.c". This version handles the message boundaries * which are not preserved by the TCP. Each message transmitted between the * client and the server is preceeded by a two byte value which is the length * of the message. The handling of the message length is done in routines readn * and writen. * revised: 22/05/1996 * revised: 18/10/2006 */ #include <stdlib.h> /* strlen(), strcmp() etc */ #include <stdio.h> /* printf() */ #include <string.h> /* strlen(), strcmp() etc */ #include <errno.h> /* extern int errno, EINTR, perror() */ #include <signal.h> /* SIGCHLD, sigaction() */ #include <syslog.h> #include <sys/types.h> /* pid_t, u_long, u_short */ #include <sys/socket.h> /* struct sockaddr, socket(), etc */ #include <sys/wait.h> /* waitpid(), WNOHAND */ #include <netinet/in.h> /* struct sockaddr_in, htons(), htonl(), */ /* and INADDR_ANY */ #include "stream.h" /* MAX_BLOCK_SIZE, readn(), writen() */ #define SERV_TCP_PORT 40005 /* default server listening port */ void claim_children() { pid_t pid=1; while (pid>0) { /* claim as many zombies as we can */ pid = waitpid(0, (int *)0, WNOHANG); } } void daemon_init(void) { pid_t pid; struct sigaction act;
Image of page 1
Image of page 2

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture