projects
/
gapil.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Aggiunte note per le funzioni classiche dei socket per ricordarne il loro
[gapil.git]
/
sources
/
TCP_echod.c
diff --git
a/sources/TCP_echod.c
b/sources/TCP_echod.c
index fe14ea31f2f9657c74765335c136057927cd7e22..dd0a9f855b3f2cb5d8295c431732c5ac36e86c5e 100644
(file)
--- a/
sources/TCP_echod.c
+++ b/
sources/TCP_echod.c
@@
-26,7
+26,7
@@
*
* Usage: echod -h give all info
*
*
* Usage: echod -h give all info
*
- * $Id: TCP_echod.c,v 1.1
1 2003/08/02 19:54:11
piccardi Exp $
+ * $Id: TCP_echod.c,v 1.1
3 2003/12/25 17:31:09
piccardi Exp $
*
****************************************************************/
/*
*
****************************************************************/
/*
@@
-42,6
+42,8
@@
#include <signal.h> /* signal functions */
#include <errno.h> /* error code */
#include <string.h> /* error strings */
#include <signal.h> /* signal functions */
#include <errno.h> /* error code */
#include <string.h> /* error strings */
+#include <stdlib.h>
+
#include "Gapil.h"
#define BACKLOG 10
#include "Gapil.h"
#define BACKLOG 10
@@
-153,9
+155,10
@@
int main(int argc, char *argv[])
/* handle echo to client */
while (1) {
/* accept connection */
/* handle echo to client */
while (1) {
/* accept connection */
+ len = sizeof(cli_add);
while (((conn_fd = accept(list_fd, (struct sockaddr *)&cli_add, &len))
< 0) && (errno == EINTR));
while (((conn_fd = accept(list_fd, (struct sockaddr *)&cli_add, &len))
< 0) && (errno == EINTR));
- if (
conn_fd < 0) {
+ if (conn_fd < 0) {
PrintErr("accept error");
exit(1);
}
PrintErr("accept error");
exit(1);
}
@@
-176,6
+179,14
@@
int main(int argc, char *argv[])
if (pid == 0) { /* child */
close(list_fd); /* close listening socket */
ServEcho(conn_fd); /* handle echo */
if (pid == 0) { /* child */
close(list_fd); /* close listening socket */
ServEcho(conn_fd); /* handle echo */
+ if (debugging) {
+ snprintf(debug, MAXLINE, "Closed connection %s\n", ipaddr);
+ if (demonize) {
+ syslog(LOG_DEBUG, debug);
+ } else {
+ printf("%s", debug);
+ }
+ }
exit(0);
} else { /* parent */
close(conn_fd); /* close connected socket */
exit(0);
} else { /* parent */
close(conn_fd); /* close connected socket */
@@
-208,23
+219,13
@@
void ServEcho(int sockfd) {
/* main loop, reading 0 char means client close connection */
while ( (nread = read(sockfd, buffer, MAXLINE)) != 0) {
if (nread < 0) {
/* main loop, reading 0 char means client close connection */
while ( (nread = read(sockfd, buffer, MAXLINE)) != 0) {
if (nread < 0) {
- snprintf(debug, MAXLINE+20, "Errore in lettura: %s \n",
- strerror(errno));
- if (demonize) { /* daemon mode */
- syslog(LOG_DEBUG, debug);
- } else {
- printf("%s", debug);
- }
+ PrintErr("Errore in lettura");
+ return;
}
nwrite = FullWrite(sockfd, buffer, nread);
if (nwrite) {
}
nwrite = FullWrite(sockfd, buffer, nread);
if (nwrite) {
- snprintf(debug, MAXLINE+20, "Errore in scrittura: %s \n",
- strerror(errno));
- if (demonize) { /* daemon mode */
- syslog(LOG_DEBUG, debug);
- } else {
- printf("%s", debug);
- }
+ PrintErr("Errore in scrittura");
+ return;
}
if (debugging) {
buffer[nread] = 0;
}
if (debugging) {
buffer[nread] = 0;