diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2009-11-23 15:33:52 +0100 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2009-11-23 15:33:52 +0100 |
commit | e0d77fa90cad334f308da9cbd4369d61f1c97511 (patch) | |
tree | 2cf61bc271b7a50f3b56f3da3d3e90c9ca40cb3d /runtime | |
parent | 02e4a98bac7329f6ab4bb3503839aba7e87881e5 (diff) | |
download | rsyslog-e0d77fa90cad334f308da9cbd4369d61f1c97511.tar.gz rsyslog-e0d77fa90cad334f308da9cbd4369d61f1c97511.tar.xz rsyslog-e0d77fa90cad334f308da9cbd4369d61f1c97511.zip |
milestone commit: first working version with epoll/tcp
... but not well-tested, so there may be many hidden bugs.
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/nsd.h | 2 | ||||
-rw-r--r-- | runtime/nsdpoll_ptcp.c | 60 | ||||
-rw-r--r-- | runtime/nspoll.c | 4 | ||||
-rw-r--r-- | runtime/nspoll.h | 2 |
4 files changed, 54 insertions, 14 deletions
diff --git a/runtime/nsd.h b/runtime/nsd.h index fc34ad6e..e5b9320b 100644 --- a/runtime/nsd.h +++ b/runtime/nsd.h @@ -91,7 +91,7 @@ ENDinterface(nsdsel) BEGINinterface(nsdpoll) /* name must also be changed in ENDinterface macro! */ rsRetVal (*Construct)(nsdpoll_t **ppThis); rsRetVal (*Destruct)(nsdpoll_t **ppThis); - rsRetVal (*Ctl)(nsdpoll_t *pNsdpoll, nsd_t *pNsd, int id, void *pUsr, int op); + rsRetVal (*Ctl)(nsdpoll_t *pNsdpoll, nsd_t *pNsd, int id, void *pUsr, int mode, int op); rsRetVal (*Wait)(nsdpoll_t *pNsdpoll, int timeout, int *idRdy, void **ppUsr); ENDinterface(nsdpoll) #define nsdpollCURR_IF_VERSION 1 /* increment whenever you change the interface structure! */ diff --git a/runtime/nsdpoll_ptcp.c b/runtime/nsdpoll_ptcp.c index ed683acc..95fd8aa3 100644 --- a/runtime/nsdpoll_ptcp.c +++ b/runtime/nsdpoll_ptcp.c @@ -78,14 +78,44 @@ finalize_it: } -/* remove the entry identified by id/pUsr from the list. - * rgerhards, 2009-11-18 +/* find and unlink the entry identified by id/pUsr from the list. + * rgerhards, 2009-11-23 + */ +static inline rsRetVal +unlinkEvent(nsdpoll_ptcp_t *pThis, int id, void *pUsr, nsdpoll_epollevt_lst_t **ppEvtLst) { + nsdpoll_epollevt_lst_t *pEvtLst; + nsdpoll_epollevt_lst_t *pPrev = NULL; + DEFiRet; + + pEvtLst = pThis->pRoot; + while(pEvtLst != NULL && pEvtLst->id != id && pEvtLst->pUsr != pUsr) { + pPrev = pEvtLst; + pEvtLst = pEvtLst->pNext; + } + if(pEvtLst == NULL) + ABORT_FINALIZE(RS_RET_NOT_FOUND); + + *ppEvtLst = pEvtLst; + + /* unlink */ + if(pPrev == NULL) + pThis->pRoot = pEvtLst->pNext; + else + pPrev->pNext = pEvtLst->pNext; + +finalize_it: + RETiRet; +} + + +/* destruct the provided element. It must already be unlinked from the list. + * rgerhards, 2009-11-23 */ static inline rsRetVal -delEvent(nsdpoll_ptcp_t *pThis, int id, void *pUsr) { +delEvent(nsdpoll_epollevt_lst_t **ppEvtLst) { DEFiRet; - // TODO: XXX add code! -#warning delEvent implementation is missing! + free(*ppEvtLst); + *ppEvtLst = NULL; RETiRet; } @@ -119,7 +149,7 @@ ENDobjDestruct(nsdpoll_ptcp) /* Modify socket set */ static rsRetVal -Ctl(nsdpoll_t *pNsdpoll, nsd_t *pNsd, int id, void *pUsr, int mode) { +Ctl(nsdpoll_t *pNsdpoll, nsd_t *pNsd, int id, void *pUsr, int mode, int op) { nsdpoll_ptcp_t *pThis = (nsdpoll_ptcp_t*) pNsdpoll; nsd_ptcp_t *pSock = (nsd_ptcp_t*) pNsd; nsdpoll_epollevt_lst_t *pEventLst; @@ -127,7 +157,7 @@ Ctl(nsdpoll_t *pNsdpoll, nsd_t *pNsd, int id, void *pUsr, int mode) { char errStr[512]; DEFiRet; - if(mode == NSDPOLL_ADD) { + if(op == NSDPOLL_ADD) { dbgprintf("adding nsdpoll entry %d/%p\n", id, pUsr); CHKiRet(addEvent(pThis, id, pUsr, mode, pSock, &pEventLst)); if(epoll_ctl(pThis->efd, EPOLL_CTL_ADD, pSock->sock, &pEventLst->event) < 0) { @@ -137,11 +167,21 @@ Ctl(nsdpoll_t *pNsdpoll, nsd_t *pNsd, int id, void *pUsr, int mode) { "epoll_ctl failed on fd %d, id %d/%p, op %d with %s\n", pSock->sock, id, pUsr, mode, errStr); } - } else if(mode == NSDPOLL_DEL) { - // TODO: XXX : code missing! + } else if(op == NSDPOLL_DEL) { + // TODO: XXX : code missing! del Event dbgprintf("removing nsdpoll entry %d/%p\n", id, pUsr); + CHKiRet(unlinkEvent(pThis, id, pUsr, &pEventLst)); + if(epoll_ctl(pThis->efd, EPOLL_CTL_DEL, pSock->sock, &pEventLst->event) < 0) { + errSave = errno; + rs_strerror_r(errSave, errStr, sizeof(errStr)); + errmsg.LogError(errSave, RS_RET_ERR_EPOLL_CTL, + "epoll_ctl failed on fd %d, id %d/%p, op %d with %s\n", + pSock->sock, id, pUsr, mode, errStr); + ABORT_FINALIZE(RS_RET_ERR_EPOLL_CTL); + } + CHKiRet(delEvent(&pEventLst)); } else { - dbgprintf("program error: invalid NSDPOLL_mode %d - ignoring request\n", mode); + dbgprintf("program error: invalid NSDPOLL_mode %d - ignoring request\n", op); ABORT_FINALIZE(RS_RET_ERR); } diff --git a/runtime/nspoll.c b/runtime/nspoll.c index b9a189cb..f287cd4e 100644 --- a/runtime/nspoll.c +++ b/runtime/nspoll.c @@ -145,10 +145,10 @@ Wait(nspoll_t *pThis, int timeout, int *idRdy, void **ppUsr) { * rgerhards, 2009-11-18 */ static rsRetVal -Ctl(nspoll_t *pThis, netstrm_t *pStrm, int id, void *pUsr, int op) { +Ctl(nspoll_t *pThis, netstrm_t *pStrm, int id, void *pUsr, int mode, int op) { DEFiRet; ISOBJ_TYPE_assert(pThis, nspoll); - iRet = pThis->Drvr.Ctl(pThis->pDrvrData, pStrm->pDrvrData, id, pUsr, op); + iRet = pThis->Drvr.Ctl(pThis->pDrvrData, pStrm->pDrvrData, id, pUsr, mode, op); RETiRet; } diff --git a/runtime/nspoll.h b/runtime/nspoll.h index 281b8103..a77759c0 100644 --- a/runtime/nspoll.h +++ b/runtime/nspoll.h @@ -51,7 +51,7 @@ BEGINinterface(nspoll) /* name must also be changed in ENDinterface macro! */ rsRetVal (*ConstructFinalize)(nspoll_t *pThis); rsRetVal (*Destruct)(nspoll_t **ppThis); rsRetVal (*Wait)(nspoll_t *pNsdpoll, int timeout, int *idRdy, void **ppUsr); - rsRetVal (*Ctl)(nspoll_t *pNsdpoll, netstrm_t *pStrm, int id, void *pUsr, int op); + rsRetVal (*Ctl)(nspoll_t *pNsdpoll, netstrm_t *pStrm, int id, void *pUsr, int mode, int op); rsRetVal (*IsEPollSupported)(void); /* static method */ ENDinterface(nspoll) #define nspollCURR_IF_VERSION 1 /* increment whenever you change the interface structure! */ |