Save (and print) errno on socket error

This commit is contained in:
Tony Garnock-Jones 2011-01-02 15:06:17 -05:00
parent 2b8f39b52f
commit 9dd094daeb
3 changed files with 7 additions and 1 deletions

View File

@ -4,6 +4,7 @@
#include <string.h>
#include <stdio.h>
#include <stddef.h>
#include <errno.h>
#include <sys/time.h>
@ -166,12 +167,14 @@ static void output_isr(struct bufferevent *bufev, IOHandle *h) {
static void error_isr(struct bufferevent *bufev, short what, IOHandle *h) {
unsigned short kind = what & ~(EVBUFFER_READ | EVBUFFER_WRITE);
int saved_errno = errno;
info("error_isr 0x%04X fd %d\n", what, h->fd);
h->error_direction = what & (EVBUFFER_READ | EVBUFFER_WRITE);
if (kind == EVBUFFER_EOF) {
h->eof = 1;
} else {
h->error_kind = kind;
h->error_errno = saved_errno;
}
awaken_waiters(h, EV_READ | EV_WRITE);
}
@ -205,6 +208,7 @@ void delete_iohandle(IOHandle *h) {
void iohandle_clear_error(IOHandle *h) {
h->error_direction = 0;
h->error_kind = 0;
h->error_errno = 0;
}
static void block_on_io(IOHandle *h, short event) {

View File

@ -24,6 +24,7 @@ typedef struct IOHandle {
int eof;
unsigned short error_direction;
unsigned short error_kind;
int error_errno;
} IOHandle;
extern IOHandle *stdin_h;

View File

@ -182,7 +182,8 @@ static void relay_main(node_t *n) {
break;
default:
warn("Relay handle error on fd %d: 0x%04X\n", r->fd, inh->error_kind);
warn("Relay handle error 0x%04X on fd %d: %d, %s\n",
inh->error_kind, r->fd, inh->error_errno, strerror(inh->error_errno));
break;
}
}