Skip to content

Commit ab2bc25

Browse files
author
Anton Yarkov
committed
Regrouped example to make common header/lib files.
1 parent 9d166a7 commit ab2bc25

File tree

10 files changed

+28
-282
lines changed

10 files changed

+28
-282
lines changed

networking/02 Astro-tcp-server - Simple blocked/server.c renamed to networking/02 Astro-tcp-server/0_simple_blocker_server.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,30 @@ ssize_t receive_all(int fd, char *buf, size_t len)
3333
return pos;
3434
}
3535

36+
/*
37+
// Just another example of the same receive algorithm.
38+
// Taken from book Effective TCP/IP.
39+
int receive_all(int fd, char *buf, size_t len)
40+
{
41+
int cnt, rc;
42+
cnt = len;
43+
while (cnt > 0)
44+
{
45+
rc = recv(fd, buf, cnt, 0);
46+
if (rc < 0)
47+
{
48+
if (errno == EINTR)
49+
continue;
50+
return -1;
51+
}
52+
if (rc == 0)
53+
return len - cnt;
54+
buf += rc;
55+
cnt -= rc;
56+
}
57+
}
58+
*/
59+
3660
void main()
3761
{
3862
printf("ASTRO Server PID -- %d.\n", getpid());

networking/02 Astro-tcp-server - Simple blocked/client.c renamed to networking/02 Astro-tcp-server/client.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ ssize_t receive_all(int fd, char *buf, size_t len)
3636
return pos;
3737
}
3838

39-
void main(int argc, char **argv)
39+
int main(int argc, char **argv)
4040
{
4141
struct hostent *hp;
4242
if ((hp = gethostbyname(argv[1])) == 0)
@@ -52,7 +52,7 @@ void main(int argc, char **argv)
5252
serv_addr.sin_port = htons(PORTNUM);
5353

5454
int sockfd = -1;
55-
if ((sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1)
55+
if ((sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1) // IPPROTO_TCP == 0
5656
{
5757
perror("Error of calling socket");
5858
exit(1);
@@ -74,7 +74,7 @@ void main(int argc, char **argv)
7474
// TEST1. Set some HOROSCOPE.
7575

7676
char setzodiak[] = "STARS SAY Aries ";
77-
int sent = send(sockfd, setzodiak, strlen(setzodiak) + 1, MSG_NOSIGNAL);
77+
int sent = send(sockfd, setzodiak, strlen(setzodiak) + 1, MSG_NOSIGNAL); // MSG_NOSIGNAL == 0
7878
printf("Sent to server: %s, %d bytes\n", setzodiak, sent);
7979

8080
char desc[] = "Some of my descriptions here. ";
@@ -136,5 +136,5 @@ void main(int argc, char **argv)
136136
}
137137

138138
close(sockfd);
139-
printf("Client off!\n\n"); \
139+
printf("Client off!\n\n");
140140
}

networking/03 Astro-tcp-server - Automata/client.c

Lines changed: 0 additions & 139 deletions
This file was deleted.

networking/04 Astro-tcp-server - Multiplex - select/client.c

Lines changed: 0 additions & 139 deletions
This file was deleted.

0 commit comments

Comments
 (0)