diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2008-06-09 12:40:54 +0200 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2008-06-09 12:40:54 +0200 |
commit | 55e01da2ec3de1b5c6b15e4154235f0eedbb68da (patch) | |
tree | fe7b9b9b114c982d1453a363499bad9fa323fd1a /runtime/nsd_ptcp.c | |
parent | cf51333f7617e586ca1d4cf5202e3d42f14c96ea (diff) | |
download | rsyslog-55e01da2ec3de1b5c6b15e4154235f0eedbb68da.tar.gz rsyslog-55e01da2ec3de1b5c6b15e4154235f0eedbb68da.tar.xz rsyslog-55e01da2ec3de1b5c6b15e4154235f0eedbb68da.zip |
somewhat improved plain tcp syslog reliability
...by doing a connection check before sending. Credits to Martin
Schuette for providing the idea. Details are available at
http://blog.gerhards.net/2008/06/reliable-plain-tcp-syslog-once-again.html
Diffstat (limited to 'runtime/nsd_ptcp.c')
-rw-r--r-- | runtime/nsd_ptcp.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/runtime/nsd_ptcp.c b/runtime/nsd_ptcp.c index 14c564a3..ff85619a 100644 --- a/runtime/nsd_ptcp.c +++ b/runtime/nsd_ptcp.c @@ -638,6 +638,34 @@ finalize_it: } +/* This function checks if the connection is still alive - well, kind of... It + * is primarily being used for plain TCP syslog and it is quite a hack. However, + * as it seems to work, it is worth supporting it. The bottom line is that it + * should not be called by anything else but a plain tcp syslog sender. + * In order for it to work, it must be called *immediately* *before* the send() + * call. For details about what is done, see here: + * http://blog.gerhards.net/2008/06/getting-bit-more-reliability-from-plain.html + * rgerhards, 2008-06-09 + */ +static void +CheckConnection(nsd_t *pNsd) +{ + int rc; + char msgbuf[1]; /* dummy */ + nsd_ptcp_t *pThis = (nsd_ptcp_t*) pNsd; + ISOBJ_TYPE_assert(pThis, nsd_ptcp); + + rc = recv(pThis->sock, msgbuf, 1, MSG_DONTWAIT | MSG_PEEK); + if(rc == 0) { + dbgprintf("CheckConnection detected broken connection - closing it\n"); + /* in this case, the remote peer had shut down the connection and we + * need to close our side, too. + */ + sockClose(&pThis->sock); + } +} + + /* get the remote host's IP address. The returned string must be freed by the * caller. * rgerhards, 2008-04-24 @@ -684,6 +712,7 @@ CODESTARTobjQueryInterface(nsd_ptcp) pIf->Connect = Connect; pIf->GetRemoteHName = GetRemoteHName; pIf->GetRemoteIP = GetRemoteIP; + pIf->CheckConnection = CheckConnection; finalize_it: ENDobjQueryInterface(nsd_ptcp) |