1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
|
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
|
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
+
-
-
-
-
+
-
-
+
+
+
|
while (1) {
/* Failure loop prevention */
if (failure_count > max_failure_count) {
break;
}
/* Allocate a new log buffer */
log = filed_log_new(1);
if (log == NULL) {
filed_log_msg("ALLOCATE_LOG_MSG_FAILED");
break;
}
log->type = FILED_LOG_TYPE_TRANSFER;
/* Accept a new client */
addrlen = sizeof(addr);
fd = accept(master_fd, (struct sockaddr *) &addr, &addrlen);
/*
* If we fail, make a note of it so we don't go into a loop of
* accept() failing
*/
if (fd < 0) {
/* Log the new connection */
filed_log_msg("ACCEPT_FAILED");
failure_count++;
continue;
}
/* Log the new connection */
log = filed_log_new(1);
if (log == NULL) {
close(fd);
/* Fill in log structure */
continue;
}
log->type = FILED_LOG_TYPE_TRANSFER;
if (filed_log_ip((struct sockaddr *) &addr, log->ip, sizeof(log->ip)) == NULL) {
log->ip[0] = '\0';
log->port = 0;
}
log->port = addr.sin6_port;
} else {
log->port = addr.sin6_port;
}
/* Reset failure count*/
failure_count = 0;
/* Handle socket */
filed_handle_client(fd, &request, log, options);
}
|