Browse Source

io: Add set_log_io_errors().

This function allows disabling of error messages from fdwrite,
fdread and fdgetline functions.
Georgi Chorbadzhiyski 12 years ago
parent
commit
82141bd7b7
2 changed files with 14 additions and 3 deletions
  1. 12
    3
      io.c
  2. 2
    0
      io.h

+ 12
- 3
io.c View File

12
 #include <stdio.h>
12
 #include <stdio.h>
13
 #include <stdlib.h>
13
 #include <stdlib.h>
14
 #include <stdarg.h>
14
 #include <stdarg.h>
15
+#include <stdbool.h>
15
 #include <unistd.h>
16
 #include <unistd.h>
16
 #include <string.h>
17
 #include <string.h>
17
 #include <netdb.h>
18
 #include <netdb.h>
31
 #include "libfuncs.h"
32
 #include "libfuncs.h"
32
 #include "log.h"
33
 #include "log.h"
33
 
34
 
35
+static int io_report_errors = 1;
36
+
37
+void set_log_io_errors(int report_io_errors) {
38
+	io_report_errors = report_io_errors;
39
+}
40
+
34
 char * chomp(char *x) {
41
 char * chomp(char *x) {
35
 	int i=strlen(x)-1;
42
 	int i=strlen(x)-1;
36
 	while ((i>=0)&&((x[i]=='\n')||(x[i]=='\r')||(x[i]==' ')||(x[i]=='\t'))){
43
 	while ((i>=0)&&((x[i]=='\n')||(x[i]=='\r')||(x[i]==' ')||(x[i]=='\t'))){
88
 			if (num_timeouts++ <= FDGETLINE_RETRIES) {
95
 			if (num_timeouts++ <= FDGETLINE_RETRIES) {
89
 				continue;
96
 				continue;
90
 			} else {
97
 			} else {
91
-				log_perror("fdgetline() timeout", errno);
98
+				if (io_report_errors)
99
+					log_perror("fdgetline() timeout", errno);
92
 			}
100
 			}
93
 		}
101
 		}
94
 		if (fdready == 0 || fdready == -1) { /* Timeout || error */
102
 		if (fdready == 0 || fdready == -1) { /* Timeout || error */
129
 			if (num_timeouts++ <= retries) {
137
 			if (num_timeouts++ <= retries) {
130
 				continue;
138
 				continue;
131
 			} else {
139
 			} else {
132
-				if (timeout) {
140
+				if (timeout && io_report_errors) {
133
 					log_perror("fdread() timeout", errno);
141
 					log_perror("fdread() timeout", errno);
134
 				}
142
 				}
135
 				return rbytes > 0 ? rbytes : -1;
143
 				return rbytes > 0 ? rbytes : -1;
183
 			if (num_timeouts++ <= FDWRITE_RETRIES) {
191
 			if (num_timeouts++ <= FDWRITE_RETRIES) {
184
 				continue;
192
 				continue;
185
 			} else {
193
 			} else {
186
-				log_perror("fdwrite() timeout", errno);
194
+				if (io_report_errors)
195
+					log_perror("fdwrite() timeout", errno);
187
 				return wbytes > 0 ? wbytes : -1;
196
 				return wbytes > 0 ? wbytes : -1;
188
 			}
197
 			}
189
 		}
198
 		}

+ 2
- 0
io.h View File

31
 int fdputs(int fd, char *msg);
31
 int fdputs(int fd, char *msg);
32
 int fdputsf(int fd, char *fmt, ...);
32
 int fdputsf(int fd, char *fmt, ...);
33
 
33
 
34
+void set_log_io_errors(int report_io_errors);
35
+
34
 void set_sock_nonblock(int sockfd);
36
 void set_sock_nonblock(int sockfd);
35
 void set_sock_block(int sockfd);
37
 void set_sock_block(int sockfd);
36
 
38
 

Loading…
Cancel
Save