51
51
#include "relp.h"
52
52
#include "relpsess.h"
53
53
#include "relpframe.h"
54
+ #include "relpclt.h"
54
55
#include "sendq.h"
55
56
#include "offers.h"
56
57
#include "dbllinklist.h"
@@ -67,25 +68,24 @@ callOnErr(const relpSess_t *__restrict__ const pThis,
67
68
const relpRetVal ecode )
68
69
{
69
70
char objinfo [1024 ];
71
+ relpTcp_t * const pTcp = pThis -> pTcp ;
70
72
//pThis->pEngine->dbgprint("librelp: generic error: ecode %d, "
71
73
//"emsg '%s'\n", ecode, emsg);
72
74
if (pThis -> pEngine -> onErr != NULL ) {
73
- #if 0 // TODO: FIXME
74
- if (pThis -> pSrv == NULL ) { /* client */
75
+ if (pTcp -> pSrv == NULL ) { /* client */
75
76
snprintf (objinfo , sizeof (objinfo ), "conn to srvr %s:%s" ,
76
- pThis -> pClt -> pSess -> srvAddr ,
77
- pThis -> pClt -> pSess -> srvPort );
78
- } else if (pThis -> pRemHostIP == NULL ) { /* server listener */
77
+ pTcp -> pClt -> pSess -> srvAddr ,
78
+ pTcp -> pClt -> pSess -> srvPort );
79
+ } else if (pTcp -> pRemHostIP == NULL ) { /* server listener */
79
80
snprintf (objinfo , sizeof (objinfo ), "lstn %s" ,
80
- pThis -> pSrv -> pLstnPort );
81
+ pTcp -> pSrv -> pLstnPort );
81
82
} else { /* server connection to client */
82
83
snprintf (objinfo , sizeof (objinfo ), "lstn %s: conn to clt %s/%s" ,
83
- pThis -> pSrv -> pLstnPort , pThis -> pRemHostIP ,
84
- pThis -> pRemHostName );
84
+ pTcp -> pSrv -> pLstnPort , pTcp -> pRemHostIP ,
85
+ pTcp -> pRemHostName );
85
86
}
86
87
objinfo [sizeof (objinfo )- 1 ] = '\0' ;
87
- #endif
88
- pThis -> pEngine -> onErr (pThis -> pUsr , "session" , emsg , ecode );
88
+ pThis -> pEngine -> onErr (pThis -> pUsr , objinfo , emsg , ecode );
89
89
}
90
90
}
91
91
@@ -276,8 +276,9 @@ relpSessRcvData(relpSess_t *pThis)
276
276
*/
277
277
pThis -> sessState = eRelpSessState_BROKEN ;
278
278
ABORT_FINALIZE (RELP_RET_SESSION_BROKEN );
279
- } else if ((int ) lenBuf == -1 ) { /* I don't know why we need to cast to int, but we must... */
279
+ } else if ((int ) lenBuf == -1 ) {
280
280
if (errno != EAGAIN ) {
281
+ callOnErr (pThis , "error when receiving data, session broken" , RELP_RET_SESSION_BROKEN );
281
282
pThis -> pEngine -> dbgprint ("errno %d during relp session %p, session broken\n" ,
282
283
errno , (void * )pThis );
283
284
pThis -> sessState = eRelpSessState_BROKEN ;
@@ -318,6 +319,7 @@ relpSessSendResponse(relpSess_t *pThis, relpTxnr_t txnr, unsigned char *pData, s
318
319
finalize_it :
319
320
if (iRet != RELP_RET_OK ) {
320
321
if (iRet == RELP_RET_IO_ERR ) {
322
+ callOnErr (pThis , "io error, session broken" , RELP_RET_SESSION_BROKEN );
321
323
pThis -> pEngine -> dbgprint ("relp session %p is broken, io error\n" , (void * )pThis );
322
324
pThis -> sessState = eRelpSessState_BROKEN ;
323
325
}
@@ -565,7 +567,7 @@ relpSessWaitState(relpSess_t *const pThis, const relpSessState_t stateExpected,
565
567
pfd .fd = sock ;
566
568
pfd .events = POLLIN ;
567
569
pThis -> pEngine -> dbgprint ("relpSessWaitRsp waiting for data on "
568
- "fd %d, timeout %d\n" , sock , timeout );
570
+ "fd %d, timeout %d, state expected %d \n" , sock , timeout , stateExpected );
569
571
nfds = poll (& pfd , 1 , timeout * 1000 );
570
572
if (nfds == -1 ) {
571
573
if (errno == EINTR ) {
@@ -597,6 +599,8 @@ relpSessWaitState(relpSess_t *const pThis, const relpSessState_t stateExpected,
597
599
iRet == RELP_RET_SESSION_BROKEN ||
598
600
relpEngineShouldStop (pThis -> pEngine )) {
599
601
/* the session is broken! */
602
+ callOnErr (pThis , "error waiting on required session state, session broken" ,
603
+ RELP_RET_SESSION_BROKEN );
600
604
pThis -> sessState = eRelpSessState_BROKEN ;
601
605
}
602
606
@@ -628,6 +632,7 @@ relpSessRawSendCommand(relpSess_t *pThis, unsigned char *pCmd, size_t lenCmd,
628
632
629
633
if (iRet == RELP_RET_IO_ERR ) {
630
634
pThis -> pEngine -> dbgprint ("relp session %p flagged as broken, IO error\n" , (void * )pThis );
635
+ callOnErr (pThis , "io error in RawSendCommand, session broken" , RELP_RET_SESSION_BROKEN );
631
636
pThis -> sessState = eRelpSessState_BROKEN ;
632
637
ABORT_FINALIZE (RELP_RET_SESSION_BROKEN );
633
638
}
@@ -791,6 +796,7 @@ relpSessCBrspOpen(relpSess_t *pThis, relpFrame_t *pFrame)
791
796
pEngine -> dbgprint ("ignoring unknown server offer '%s'\n" , pOffer -> szName );
792
797
}
793
798
}
799
+
794
800
relpSessSetSessState (pThis , eRelpSessState_INIT_RSP_RCVD );
795
801
796
802
finalize_it :
@@ -816,8 +822,10 @@ relpSessCltConnChkOffers(relpSess_t *pThis)
816
822
ABORT_FINALIZE (RELP_RET_RQD_FEAT_MISSING );
817
823
818
824
finalize_it :
819
- if (iRet != RELP_RET_OK )
825
+ if (iRet != RELP_RET_OK ) {
826
+ callOnErr (pThis , "error in CltConnChkOffers, session broken" , RELP_RET_SESSION_BROKEN );
820
827
pThis -> sessState = eRelpSessState_BROKEN ;
828
+ }
821
829
822
830
LEAVE_RELPFUNC ;
823
831
}
@@ -876,7 +884,6 @@ relpSessConnect(relpSess_t *pThis, int protFamily, unsigned char *port, unsigned
876
884
CHKRet (relpOffersToString (pOffers , NULL , 0 , & pszOffers , & lenOffers ));
877
885
CHKRet (relpOffersDestruct (& pOffers ));
878
886
879
- pThis -> pEngine -> dbgprint ("sending open command\n" );
880
887
CHKRet (relpSessRawSendCommand (pThis , (unsigned char * )"open" , 4 , pszOffers , lenOffers ,
881
888
relpSessCBrspOpen ));
882
889
relpSessSetSessState (pThis , eRelpSessState_INIT_CMD_SENT );
0 commit comments