head	1.4;
access;
symbols
	tonic_4:1.4
	tonic_3:1.4
	tonic_2:1.4
	demo:1.4.0.2
	design_report:1.4
	dec2:1.1.1.1
	oral_presentation_freeze:1.1.1.1.0.6
	DAVEG_CDP:1.1.1.1.0.4
	template_integ:1.1.1.1.0.2
	v1_1:1.1.1.1
	nov19:1.1.1.1
	course_staff:1.1.1;
locks; strict;
comment	@ * @;


1.4
date	95.12.09.05.12.00;	author daveg;	state Exp;
branches;
next	1.3;

1.3
date	95.12.07.09.24.05;	author hartmans;	state Exp;
branches;
next	1.2;

1.2
date	95.12.05.10.44.45;	author hartmans;	state Exp;
branches;
next	1.1;

1.1
date	95.11.19.05.50.04;	author hartmans;	state Exp;
branches
	1.1.1.1;
next	;

1.1.1.1
date	95.11.19.05.50.05;	author hartmans;	state Exp;
branches;
next	;


desc
@@


1.4
log
@added #include <stdio.h> for perror
@
text
@#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <fstream.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <stdio.h>
 
#include "ps5/server.h"

server::server(int port) {
    s = -1;
    s = socket(AF_INET, SOCK_STREAM, 0);
    if (s < 0) { perror("create socket"); exit(1); }

    struct sockaddr_in sa;
    sa.sin_family = AF_INET;
    sa.sin_addr.s_addr = INADDR_ANY;
    sa.sin_port = htons(port);
    if (0 > bind(s, (struct sockaddr*) &sa, sizeof(sa))) {
	perror ("bind socket");
	exit(1);
    }
    if (0 > listen(s, 4)) {
	perror ("listen socket");
	exit(1);
    }
}

int server::accept() {
    int new_s;
    for (;;) {
	new_s = ::accept(s, 0, 0);
	if (new_s >= 0) break;
	if (errno != EINTR) {
	    perror("accept");
	    exit(1);
	}
    }
    return new_s;
}

void server::close() {
    ::close(s);
}

int server::file_descriptor() {
    return s;
}
@


1.3
log
@random changes I made and forgot about
@
text
@d9 1
@


1.2
log
@Fix potential bug
@
text
@d31 1
a31 1
sockstream server::accept() {
d41 1
a41 1
    return sockstream(new_s);
@


1.1
log
@Initial revision
@
text
@d10 1
a10 1
#include "ps4/server.h"
@


1.1.1.1
log
@Bring web_server code into our tree
@
text
@@
