diff --git a/nsock/include/nsock.h b/nsock/include/nsock.h index 90b778ee3..56652b644 100644 --- a/nsock/include/nsock.h +++ b/nsock/include/nsock.h @@ -322,8 +322,9 @@ enum nse_status { nspool is being deleted -- you should free up any resources you have allocated and exit. Don't you dare make any more async nsock calls! */ - NSE_STATUS_EOF /* We got EOF and NO DATA -- if we got data first, + NSE_STATUS_EOF, /* We got EOF and NO DATA -- if we got data first, SUCCESS is reported (see nse_eof()). */ + NSE_STATUS_PROXYERROR }; enum nse_status nse_status(nsock_event nse); diff --git a/nsock/src/nsock_event.c b/nsock/src/nsock_event.c index 138cacc56..fc1fb858c 100644 --- a/nsock/src/nsock_event.c +++ b/nsock/src/nsock_event.c @@ -500,6 +500,7 @@ const char *nse_status2str(enum nse_status status) { case NSE_STATUS_CANCELLED: return "CANCELLED"; case NSE_STATUS_KILL: return "KILL"; case NSE_STATUS_EOF: return "EOF"; + case NSE_STATUS_PROXYERROR: return "PROXY ERROR"; default: return "UNKNOWN!"; } diff --git a/nsock/src/nsock_proxy.c b/nsock/src/nsock_proxy.c index 661d81c44..fd2837eb3 100644 --- a/nsock/src/nsock_proxy.c +++ b/nsock/src/nsock_proxy.c @@ -428,32 +428,36 @@ void forward_event(nsock_pool nspool, nsock_event nsevent, void *udata) { msevent *nse = (msevent *)nsevent; enum nse_type cached_type; enum nse_status cached_status; - + cached_type = nse->type; cached_status = nse->status; - + nse->type = NSE_TYPE_CONNECT; - nse->status = NSE_STATUS_SUCCESS; - + + if (nse->status != NSE_STATUS_SUCCESS) + nse->status = NSE_STATUS_PROXYERROR; + if (nsp->tracelevel > 0) - nsock_trace(nsp, "Forwarding event upstream: SUCCESS TCP connect (IOD #%li) EID %li", - nse->iod->id, nse->id); - + nsock_trace(nsp, "Forwarding event upstream: TCP connect %s (IOD #%li) EID %li", + nse_status2str(nse->status), nse->iod->id, nse->id); + nse->iod->px_ctx->target_handler(nsp, nse, udata); - + nse->type = cached_type; nse->status = cached_status; } void nsock_proxy_ev_dispatch(nsock_pool nspool, nsock_event nsevent, void *udata) { msevent *nse = (msevent *)nsevent; - struct proxy_node *current; - if (nse->status != NSE_STATUS_SUCCESS) - fatal("Error, but this is debug only!"); + if (nse->status == NSE_STATUS_SUCCESS) { + struct proxy_node *current; - current = proxy_ctx_node_current(nse->iod->px_ctx); - assert(current); - current->ops->handler(nspool, nsevent, udata); + current = proxy_ctx_node_current(nse->iod->px_ctx); + assert(current); + current->ops->handler(nspool, nsevent, udata); + } else { + forward_event(nspool, nsevent, udata); + } }