Skip to content

Commit

Permalink
io: Add set_log_io_errors().
Browse files Browse the repository at this point in the history
This function allows disabling of error messages from fdwrite,
fdread and fdgetline functions.
  • Loading branch information
Georgi Chorbadzhiyski committed Sep 29, 2011
1 parent c1aecc8 commit 82141bd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 12 additions & 3 deletions io.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdbool.h>
#include <unistd.h>
#include <string.h>
#include <netdb.h>
Expand All @@ -31,6 +32,12 @@
#include "libfuncs.h"
#include "log.h"

static int io_report_errors = 1;

void set_log_io_errors(int report_io_errors) {
io_report_errors = report_io_errors;
}

char * chomp(char *x) {
int i=strlen(x)-1;
while ((i>=0)&&((x[i]=='\n')||(x[i]=='\r')||(x[i]==' ')||(x[i]=='\t'))){
Expand Down Expand Up @@ -88,7 +95,8 @@ ssize_t fdgetline(int fd, char *buf, size_t buf_size) {
if (num_timeouts++ <= FDGETLINE_RETRIES) {
continue;
} else {
log_perror("fdgetline() timeout", errno);
if (io_report_errors)
log_perror("fdgetline() timeout", errno);
}
}
if (fdready == 0 || fdready == -1) { /* Timeout || error */
Expand Down Expand Up @@ -129,7 +137,7 @@ ssize_t fdread_ex(int fd, char *buf, size_t buf_size, int timeout, int retries,
if (num_timeouts++ <= retries) {
continue;
} else {
if (timeout) {
if (timeout && io_report_errors) {
log_perror("fdread() timeout", errno);
}
return rbytes > 0 ? rbytes : -1;
Expand Down Expand Up @@ -183,7 +191,8 @@ ssize_t fdwrite(int fd, char *buf, size_t buf_size) {
if (num_timeouts++ <= FDWRITE_RETRIES) {
continue;
} else {
log_perror("fdwrite() timeout", errno);
if (io_report_errors)
log_perror("fdwrite() timeout", errno);
return wbytes > 0 ? wbytes : -1;
}
}
Expand Down
2 changes: 2 additions & 0 deletions io.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ ssize_t fdwrite(int fd, char *buf, size_t buf_size);
int fdputs(int fd, char *msg);
int fdputsf(int fd, char *fmt, ...);

void set_log_io_errors(int report_io_errors);

void set_sock_nonblock(int sockfd);
void set_sock_block(int sockfd);

Expand Down

0 comments on commit 82141bd

Please sign in to comment.