Add iomux_from_timers() function to recover an IOMux from
the associated UCTimers
This commit is contained in:
@@ -132,6 +132,11 @@ int iomux_update_events(struct IOMux *mux, struct IOMuxFD *fd, unsigned int what
|
|||||||
*/
|
*/
|
||||||
struct UCTimers *iomux_get_timers(struct IOMux *mux);
|
struct UCTimers *iomux_get_timers(struct IOMux *mux);
|
||||||
|
|
||||||
|
/** Given an UCTimers associated with an IOMux, return the associated IOMux.
|
||||||
|
* (the UCTimers must previously been obtained from iomux_get_timers directly,
|
||||||
|
* or indirectly by the UCTimers provieded in a timer callback handler.
|
||||||
|
*/
|
||||||
|
struct IOMux *iomux_from_timers(struct UCTimers *timers);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -168,3 +168,8 @@ struct UCTimers *iomux_get_timers(struct IOMux *mux)
|
|||||||
return &mux->timers;
|
return &mux->timers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct IOMux *iomux_from_timers(struct UCTimers *timers)
|
||||||
|
{
|
||||||
|
return (struct IOMux*)timers; //timers is the 1. member of IOMux
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -29,7 +29,7 @@ struct IOMuxOps {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct IOMux {
|
struct IOMux {
|
||||||
/* TImer instance */
|
/* TImer instance - must be the 1. member*/
|
||||||
struct UCTimers timers;
|
struct UCTimers timers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#define DEBUG
|
#define DEBUG
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
#include <assert.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
@@ -76,6 +77,7 @@ void peer_timer_cb(struct UCTimers *timers, struct UCTimer *timer)
|
|||||||
struct HBPeer *peer = UC_CONTAINER_OF(timer, struct HBPeer, timer);
|
struct HBPeer *peer = UC_CONTAINER_OF(timer, struct HBPeer, timer);
|
||||||
struct HBContext *ctx = timer->cookie_ptr;
|
struct HBContext *ctx = timer->cookie_ptr;
|
||||||
time_t now;
|
time_t now;
|
||||||
|
struct IOMux *mux;
|
||||||
|
|
||||||
uc_timers_add(timers, timer, PEER_HB_MISS , 0);
|
uc_timers_add(timers, timer, PEER_HB_MISS , 0);
|
||||||
now = time(NULL);
|
now = time(NULL);
|
||||||
@@ -85,6 +87,9 @@ void peer_timer_cb(struct UCTimers *timers, struct UCTimer *timer)
|
|||||||
}
|
}
|
||||||
|
|
||||||
peer_send(ctx, peer);
|
peer_send(ctx, peer);
|
||||||
|
//jsut a small test of iomux_from_timers
|
||||||
|
mux = iomux_from_timers(timers);
|
||||||
|
assert(mux == ctx->mux);
|
||||||
}
|
}
|
||||||
|
|
||||||
void peer_add_addr(struct HBContext *ctx, const struct sockaddr_in *addr)
|
void peer_add_addr(struct HBContext *ctx, const struct sockaddr_in *addr)
|
||||||
|
|||||||
Reference in New Issue
Block a user