Commit 45a1e761 authored by Sven Gestegård Robertz's avatar Sven Gestegård Robertz
Browse files

added program name to printouts

parent 54c6decf
......@@ -40,7 +40,7 @@ static int bind_server_socket(int fd, int port){
return -1;
}
// see man page ip(7)
/* see man page ip(7) */
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
......@@ -48,7 +48,7 @@ static int bind_server_socket(int fd, int port){
if(bind(fd, (struct sockaddr*) &addr, sizeof(addr))) return -1;
#ifdef INFO
printf("bound fd %d to port %d (%x)\n",fd,port,addr.sin_port);
printf("simple_server: bound fd %d to port %d\n",fd,port);
#endif
return fd;
......@@ -59,18 +59,16 @@ static int bind_server_socket(int fd, int port){
*/
static int do_serve(int fd)
{
struct sockaddr_in client;
socklen_t addrlen = sizeof(client);
int clientfd;
const char* msg = "Hello, socket!\n"
"I am a text\n"
"BYE.\n";
size_t len = strlen(msg);
printf("attempting accept on fd %d\n",fd);
if((clientfd = accept(fd,(struct sockaddr*) &client, &addrlen)) < 0) return -1;
printf("simple_server: attempting accept on fd %d\n",fd);
if((clientfd = accept(fd, NULL, NULL)) < 0) return -1;
#ifdef INFO
printf("writing msg (len=%lu) to clientfd %d (port %d)\n",len,clientfd,client.sin_port);
printf("simple_server: writing msg (len=%lu) to clientfd (%d)\n",len,clientfd);
#endif
#ifdef WRITE_LOOP
......@@ -82,20 +80,22 @@ static int do_serve(int fd)
goto error;
}
#ifdef INFO
printf("write returned %d\n",res);
printf("simple_server: write returned %d\n",res);
#endif
written += res;
} while (written < len);
#else
int res = write(clientfd, msg, len);
if (res < 0) {
perror("write to clientfd");
goto error;
{
int res = write(clientfd, msg, len);
if (res < 0) {
perror("write to clientfd");
goto error;
}
}
#endif
error:
printf("closing clientfd\n");
printf("simple_server: closing clientfd (%d)\n",clientfd);
return close(clientfd);
}
......@@ -110,7 +110,7 @@ int main()
do_serve(fd);
printf("closing socket: %d\n", fd);
printf("simple_server: closing socket: %d\n", fd);
close(fd);
return 0;
......
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