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

+ 2
- 0
io.h View File

@@ -31,6 +31,8 @@ ssize_t fdwrite(int fd, char *buf, size_t buf_size);
31 31
 int fdputs(int fd, char *msg);
32 32
 int fdputsf(int fd, char *fmt, ...);
33 33
 
34
+void set_log_io_errors(int report_io_errors);
35
+
34 36
 void set_sock_nonblock(int sockfd);
35 37
 void set_sock_block(int sockfd);
36 38
 

Loading…
Cancel
Save