On Mon, Apr 08, 2013 at 01:36:04PM +0800, Liu Ping Fan wrote: > Bind each NetClientState with a GSource(ie,NetClientSource). Currently, > these GSource attached with default context, but in future, after > resolving the race between handlers and the interface exposed by > NetClientInfo and other re-entrant issue, we can run NetClientState > on different threads > > Signed-off-by: Liu Ping Fan <pingf...@linux.vnet.ibm.com> > --- > include/net/net.h | 15 +++++++++++++ > net/net.c | 61 > +++++++++++++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 76 insertions(+), 0 deletions(-) > > diff --git a/include/net/net.h b/include/net/net.h > index cb049a1..cb2451d 100644 > --- a/include/net/net.h > +++ b/include/net/net.h > @@ -44,6 +44,7 @@ typedef ssize_t (NetReceiveIOV)(NetClientState *, const > struct iovec *, int); > typedef void (NetCleanup) (NetClientState *); > typedef void (LinkStatusChanged)(NetClientState *); > typedef void (NetClientDestructor)(NetClientState *); > +typedef void (NetClientBindCtx)(NetClientState *, GMainContext *); > > typedef struct NetClientInfo { > NetClientOptionsKind type; > @@ -55,8 +56,20 @@ typedef struct NetClientInfo { > NetCleanup *cleanup; > LinkStatusChanged *link_status_changed; > NetPoll *poll; > + NetClientBindCtx *bind_ctx; > } NetClientInfo; > > +typedef bool (*Pollable)(void *opaque); > + > +typedef struct NetClientSource { > + GSource source; > + /* fix me, to expand as array in future */ > + GPollFD gfd; > + Pollable readable; > + Pollable writable; > + void *opaque; > +} NetClientSource;
This struct has nothing to do with the net subsystem. It is a generic utility for file descriptor read/write monitoring. It should be in a separate file (maybe util/fdsource.c?). NetClient should not know about the GSource at all. It's an implementation detail of the NetClient, just like the actual fd is also an implementation detail that net.h/net.c doesn't know about. Stefan